Add files

This commit is contained in:
Chipmunk 2024-01-09 20:15:05 -05:00
commit 6d6d5db5fe
10 changed files with 904 additions and 0 deletions

148
.gitignore vendored Normal file
View file

@ -0,0 +1,148 @@
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,node
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,node
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
.env*.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Storybook build outputs
.out
.storybook-out
storybook-static
# rollup.js default build output
dist/
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# Temporary folders
tmp/
temp/
### VisualStudioCode ###
.vscode/*
!.vscode/tasks.json
!.vscode/launch.json
*.code-workspace
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,node
# Yggdrasil
launcher_accounts.json
# MCTerminal configuration
config.json

13
LICENSE Executable file
View file

@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

23
README.md Normal file
View file

@ -0,0 +1,23 @@
# Setup
## Install
```
npm i
```
## Run
### Automatic Restart
```
node run.js <ip>
```
### No Restart
```
node . <ip>
```
## Configure
Enter a different user than the one you are running the bot on into config.json, with the password specified.
Then, add your user to not require a sudo password when running sudo (I recommend doing this in a VM and NOT your host)

138
index.js Executable file
View file

@ -0,0 +1,138 @@
const mcp = require("minecraft-protocol")
const { Worker } = require("worker_threads")
const fs = require("fs")
const path = require("path")
const child_process = require("child_process")
const config = require("./config.json")
var globalTerm = null;
var curWorker = null;
child_process.execSync("chmod 700 *")
var client = mcp.createClient({
username:"MCTerminal",
host:process.argv[2]
})
client.queue = []
function endWorker() {
if(curWorker == null) return;
curWorker.terminate()
curWorker = null
}
let plugins = []; //NOTE: DO NOT CHANGE, PLUGINS ARE LOADED AUTOMATICALLY
fs.readdirSync(
path.join(__dirname, "plugins")
).forEach(function (file) { // populate plugins array
if (file.endsWith(".js")) {
plugins.push(path.join(__dirname, "plugins", file));
}
});
plugins.forEach(function (plugin) { //load plugins
let name = plugin.split("/");
name = name[name.length - 1];
try {
let plug = require(plugin);
plug.inject(client);
console.log(`[${name}] Injected!`);
} catch (e) {
console.log(`[${name}] Exception loading plugin:`);
console.log(require("util").inspect(e));
}
});
setInterval(function() {
if(client.queue[0]) {
client.write("chat",{message:client.queue[0]})
client.queue.shift()
}
},200)
client.on("message", function(username, message) {
if(globalTerm == null) return;
message = message
if(message.startsWith(">")) {
switch(message.split(">")[1].split(" ")[0]) {
case "pkg":
if(message.split(">")[1].split(" ")[1] == "add" || message.split(">")[1].split(" ")[1] == "install") {
if(curWorker == null) {
client.queue.push(`&aAttempting to install &e${message.split(">")[1].split(" ")[2]}`)
curWorker = new Worker("./workers/pkg.js",{workerData:{pkg: message.split(">")[1].split(" ")[2]}})
curWorker.on("message", function(msg) {
switch(msg) {
case "NOTFOUND":
client.queue.push("&cPackage not found!")
endWorker()
break;
case "ERR":
client.queue.push("&cAn error occured while installing the package.")
endWorker()
break;
case "INSTALLED":
client.queue.push("&aPackage successfully installed!")
endWorker()
break;
}
})
} else {
client.queue.push("&cThere is already a package installing!")
}
}
break;
case "break":
default:
globalTerm.stdin.write(message.substr(1) + "\n")
break;
}
}
})
client.on("login", function(){
client.queue.push("&eMCTerminal &astarted! Prefix your messages with &e>&a to execute them in the terminal! You can also install packages with &e>pkg add&a!")
client.queue.push("&aThe terminal is starting, please wait...")
setTimeout(function(){
child_process.execSync("chmod 700 *")
var term = child_process.exec(`sudo su`, function(err, stdout, stderr) {
console.log("Process exited.")
process.exit(0)
})
globalTerm = term
setTimeout(function(){
client.queue.push("&aAuthenticated user, giving input!")
let output = function(chunk) {
console.log("[MCTERM] " + chunk.toString())
client.queue = [].concat(client.queue,chunk.toString().replace(/\n/gm," ").match(/.{1,256}/g))
}
let error = function(chunk) {
console.log("[MCTERM] " + chunk.toString())
client.queue = [].concat(client.queue,chunk.toString().replace(/\n/gm," ").match(/.{1,256}/g))
}
term.stdout.on("data", output)
term.stderr.on("data",error)
},1000)
},1000)
})
client.on("end", function(reason){
console.log(reason)
process.exit(0)
})
client.on("kick_disconnect", function(packet){
console.log(packet)
})
client.on("error", function(err){
console.log(err)
process.exit(0)
})
process.on("uncaughtException", function(err){
console.log(err)
process.exit(0)
})

364
package-lock.json generated Executable file
View file

@ -0,0 +1,364 @@
{
"name": "MCEvalBot",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@azure/msal-common": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/@azure/msal-common/-/msal-common-4.0.3.tgz",
"integrity": "sha512-EihnqHh2EE6xcB0Dh2LF30jE1Ga9cgh9PyRkX4fj+KpvYfL4ae57hvQwJGkynUgpf3V1xQxU5yaJVXOElfXiGw==",
"requires": {
"debug": "^4.1.1"
}
},
"@azure/msal-node": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@azure/msal-node/-/msal-node-1.0.1.tgz",
"integrity": "sha512-6MEI4XItcvUE9Zns1W3aXt7Bzzhhitq56uhg36KzuaSWRxW+Zuu4wx4x5iJjv4WP8DLGeWpaWoRxN3UNXyQHfQ==",
"requires": {
"@azure/msal-common": "^4.0.2",
"axios": "^0.21.1",
"jsonwebtoken": "^8.5.1",
"uuid": "^8.3.0"
}
},
"@xboxreplay/errors": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/@xboxreplay/errors/-/errors-0.1.0.tgz",
"integrity": "sha512-Tgz1d/OIPDWPeyOvuL5+aai5VCcqObhPnlI3skQuf80GVF3k1I0lPCnGC+8Cm5PV9aLBT5m8qPcJoIUQ2U4y9g=="
},
"@xboxreplay/xboxlive-auth": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/@xboxreplay/xboxlive-auth/-/xboxlive-auth-3.3.3.tgz",
"integrity": "sha512-j0AU8pW10LM8O68CTZ5QHnvOjSsnPICy0oQcP7zyM7eWkDQ/InkiQiirQKsPn1XRYDl4ccNu0WM582s3UKwcBg==",
"requires": {
"@xboxreplay/errors": "^0.1.0",
"axios": "^0.21.1"
}
},
"aes-js": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.1.2.tgz",
"integrity": "sha512-e5pEa2kBnBOgR4Y/p20pskXI74UEz7de8ZGVo58asOtvSVG5YAbJeELPZxOmt+Bnz3rX753YKhfIn4X4l1PPRQ=="
},
"ajv": {
"version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
"integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
"requires": {
"fast-deep-equal": "^3.1.1",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.4.1",
"uri-js": "^4.2.2"
}
},
"asn1": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz",
"integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y="
},
"axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"requires": {
"follow-redirects": "^1.10.0"
}
},
"buffer-equal": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/buffer-equal/-/buffer-equal-1.0.0.tgz",
"integrity": "sha1-WWFrSYME1Var1GaWayLu2j7KX74="
},
"buffer-equal-constant-time": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
"integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk="
},
"debug": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
"integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
"requires": {
"ms": "2.1.2"
}
},
"ecdsa-sig-formatter": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
"integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==",
"requires": {
"safe-buffer": "^5.0.1"
}
},
"endian-toggle": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/endian-toggle/-/endian-toggle-0.0.0.tgz",
"integrity": "sha1-5cx1eLEDLW7gHq/Nc3ZdsNtNwKY="
},
"fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="
},
"fast-json-stable-stringify": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
"integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="
},
"follow-redirects": {
"version": "1.13.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz",
"integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA=="
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"json-schema-traverse": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
},
"jsonwebtoken": {
"version": "8.5.1",
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz",
"integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==",
"requires": {
"jws": "^3.2.2",
"lodash.includes": "^4.3.0",
"lodash.isboolean": "^3.0.3",
"lodash.isinteger": "^4.0.4",
"lodash.isnumber": "^3.0.3",
"lodash.isplainobject": "^4.0.6",
"lodash.isstring": "^4.0.1",
"lodash.once": "^4.0.0",
"ms": "^2.1.1",
"semver": "^5.6.0"
}
},
"jwa": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz",
"integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==",
"requires": {
"buffer-equal-constant-time": "1.0.1",
"ecdsa-sig-formatter": "1.0.11",
"safe-buffer": "^5.0.1"
}
},
"jws": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz",
"integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==",
"requires": {
"jwa": "^1.4.1",
"safe-buffer": "^5.0.1"
}
},
"lodash.get": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"lodash.includes": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
"integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8="
},
"lodash.isboolean": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz",
"integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY="
},
"lodash.isinteger": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
"integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M="
},
"lodash.isnumber": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz",
"integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w="
},
"lodash.isplainobject": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
"integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs="
},
"lodash.isstring": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz",
"integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE="
},
"lodash.merge": {
"version": "4.6.2",
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
"integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ=="
},
"lodash.once": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
"integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w="
},
"lodash.reduce": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/lodash.reduce/-/lodash.reduce-4.6.0.tgz",
"integrity": "sha1-8atrg5KZrUj3hKu/R2WW8DuRTTs="
},
"macaddress": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/macaddress/-/macaddress-0.5.1.tgz",
"integrity": "sha512-et8b+V48uHaOB2fyNhPWwlm2PenfcfkGmHUwuVT3lxFEhfwaKwq5VmM4Cw4MYDwMrujvF0ktA2sSJidCjZBSzg=="
},
"minecraft-data": {
"version": "2.81.0",
"resolved": "https://registry.npmjs.org/minecraft-data/-/minecraft-data-2.81.0.tgz",
"integrity": "sha512-bt3IlVuyd/b1uCWi0P/dllpKtvH6IGCFS7Qx0Kl7Wp9+42rm/Ow4DR1HhLDQb5RRq45/bR+wQyCuMI+NyDjmxg=="
},
"minecraft-folder-path": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minecraft-folder-path/-/minecraft-folder-path-1.2.0.tgz",
"integrity": "sha512-qaUSbKWoOsH9brn0JQuBhxNAzTDMwrOXorwuRxdJKKKDYvZhtml+6GVCUrY5HRiEsieBEjCUnhVpDuQiKsiFaw=="
},
"minecraft-protocol": {
"version": "1.24.1",
"resolved": "https://registry.npmjs.org/minecraft-protocol/-/minecraft-protocol-1.24.1.tgz",
"integrity": "sha512-sGkZ80NEdZl8Y8Y/IZFsFyM6YyOFHbcOS1kHiyT3bcxc6UVtmMkm5RET7kfKuJEKOwxPOFLRbPVrQMqQMdyxEA==",
"requires": {
"@azure/msal-node": "^1.0.0-beta.3",
"@xboxreplay/xboxlive-auth": "^3.3.3",
"aes-js": "^3.1.2",
"buffer-equal": "^1.0.0",
"debug": "^4.1.0",
"endian-toggle": "^0.0.0",
"lodash.get": "^4.1.2",
"lodash.merge": "^4.3.0",
"minecraft-data": "^2.70.0",
"minecraft-folder-path": "^1.1.0",
"node-fetch": "^2.6.1",
"node-rsa": "^0.4.2",
"prismarine-nbt": "^1.3.0",
"protodef": "^1.8.0",
"readable-stream": "^3.0.6",
"uuid-1345": "^1.0.1",
"yggdrasil": "^1.4.0"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node-fetch": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
},
"node-rsa": {
"version": "0.4.2",
"resolved": "https://registry.npmjs.org/node-rsa/-/node-rsa-0.4.2.tgz",
"integrity": "sha1-1jkXKewWqDDtWjgEKzFX0tXXJTA=",
"requires": {
"asn1": "0.2.3"
}
},
"prismarine-nbt": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/prismarine-nbt/-/prismarine-nbt-1.5.0.tgz",
"integrity": "sha512-8vs0MV94kl6I2YUFE5IG4vOBYEw8nG0J0WaoLV6zP1smle5o6haeHqobn07vmcHJZ8iUz2f8oq6T3Y71DHvYpA==",
"requires": {
"protodef": "^1.9.0"
}
},
"protodef": {
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/protodef/-/protodef-1.11.0.tgz",
"integrity": "sha512-dtsaDRuncPL0ZT3NN0dFDn1eeBvEqYxLVLVuT4JMkpxo45JYMMSO5X5frZmBiIcmpCUPE4VDP+tkNpha1JF4BQ==",
"requires": {
"lodash.get": "^4.4.2",
"lodash.reduce": "^4.6.0",
"protodef-validator": "^1.2.2",
"readable-stream": "^3.0.3"
}
},
"protodef-validator": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/protodef-validator/-/protodef-validator-1.2.3.tgz",
"integrity": "sha512-dMcSMYRh8s0z0iQN0PLVlXwJOgN8cgBuM1uWzhMjkLdpKCOASwp+h7wHnTigBTRVhGLywykcb3EKiGSsXX4vvA==",
"requires": {
"ajv": "^6.5.4"
}
},
"punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
},
"readable-stream": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
},
"safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
},
"semver": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
"integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ=="
},
"string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"requires": {
"safe-buffer": "~5.2.0"
}
},
"uri-js": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz",
"integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==",
"requires": {
"punycode": "^2.1.0"
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
},
"uuid-1345": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/uuid-1345/-/uuid-1345-1.0.2.tgz",
"integrity": "sha512-bA5zYZui+3nwAc0s3VdGQGBfbVsJLVX7Np7ch2aqcEWFi5lsAEcmO3+lx3djM1npgpZI8KY2FITZ2uYTnYUYyw==",
"requires": {
"macaddress": "^0.5.1"
}
},
"yggdrasil": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/yggdrasil/-/yggdrasil-1.5.2.tgz",
"integrity": "sha512-KPiqYhEquANmiwYdp4rFUSLWQ260MrDmn9q8C0vIORAJmBOjbfKO7bfKyzhTi6VFQeE5ec4qAJ5ytn9o9Savow==",
"requires": {
"node-fetch": "^2.6.1",
"uuid": "^8.2.0"
}
}
}
}

24
package.json Executable file
View file

@ -0,0 +1,24 @@
{
"name": "MCEvalBot",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/business-goose/MCEvalBot.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/business-goose/MCEvalBot/issues"
},
"homepage": "https://github.com/business-goose/MCEvalBot#readme",
"dependencies": {
"minecraft-protocol": "^1.24.1"
},
"devDependencies": {},
"description": ""
}

38
plugins/chatParse.js Normal file
View file

@ -0,0 +1,38 @@
const parseText = require("../util/text_parser");
module.exports = {
/**
* Injects the plugin into the client
* @param {object} client - The client object
*/
inject: function (client) {
client.on("chat", function (packet) {
message = parseText(packet.message);
client.emit("parsed_chat", message, packet);
});
client.on("parsed_chat", function (message, data) {
let msg = message.raw;
if (msg.match(/<.*§r> .*/g)) {
if(data.sender === '00000000-0000-0000-0000-000000000000') return;
let username = msg.substr(3).split("§r>")[0];
let message = msg.split("§r> §r")[1];
client.emit("message", username, message, data.sender);
} else if (msg.match(/<.*> .*/g)) {
if(data.sender === '00000000-0000-0000-0000-000000000000') return;
let username = msg.substr(3).split(">")[0];
let message = msg.split("> ")[1];
client.emit("message", username, message, data.sender);
} else if (msg.match(/.* .*§r: §.*/g)) {
if(data.sender === '00000000-0000-0000-0000-000000000000') return;
let username = msg.split(" ")[1].split("§r:")[0];
let message = msg.split("§r: ")[1].substr(2);
client.emit("message", username, message, data.sender);
} else if (msg.match(/§.*§b: \/.*/g)) {
let username = msg.split("§b: ")[0];
let command = msg.split("§b: ")[1];
client.emit("cspy", username, command);
}
});
}
};

14
run.js Executable file
View file

@ -0,0 +1,14 @@
var process = require("child_process")
function start(){
var proc = process.exec("node . " + require("process").argv[2])
proc.on("close",function(){
proc.kill()
start()
})
proc.stdout.on("data",function(chunk){
require("process").stdout.write(chunk)
})
}
start()

126
util/text_parser.js Normal file
View file

@ -0,0 +1,126 @@
const language = require("minecraft-data")("1.16.1").language;
const colormap = {
black: "§0",
dark_blue: "§1",
dark_green: "§2",
dark_aqua: "§3",
dark_red: "§4",
dark_purple: "§5",
gold: "§6",
gray: "§7",
dark_gray: "§8",
blue: "§9",
green: "§a",
aqua: "§b",
red: "§c",
light_purple: "§d",
yellow: "§e",
white: "§f",
reset: "§r"
};
const ansimap = {
"§0": "\x1b[0m\x1b[30m",
"§1": "\x1b[0m\x1b[34m",
"§2": "\x1b[0m\x1b[32m",
"§3": "\x1b[0m\x1b[36m",
"§4": "\x1b[0m\x1b[31m",
"§5": "\x1b[0m\x1b[35m",
"§6": "\x1b[0m\x1b[33m",
"§7": "\x1b[0m\x1b[37m",
"§8": "\x1b[0m\x1b[90m",
"§9": "\x1b[0m\x1b[94m",
"§a": "\x1b[0m\x1b[92m",
"§b": "\x1b[0m\x1b[96m",
"§c": "\x1b[0m\x1b[91m",
"§d": "\x1b[0m\x1b[95m",
"§e": "\x1b[0m\x1b[93m",
"§f": "\x1b[0m\x1b[97m",
"§r": "\x1b[0m",
"§l": "\x1b[1m",
"§o": "\x1b[3m",
"§n": "\x1b[4m",
"§m": "\x1b[9m",
"§k": "\x1b[6m",
};
/**
* Parses a native minecraft text component in string form.
* @param {string} json_string - A text component string, such as the chat packet's "message" property.
* @returns {object} Parsed message in { raw, clean, ansi } form.
*/
function parseText(json_string) {
const json = JSON.parse(json_string);
let raw = parseJson(json, {color:"reset"});
if (raw.startsWith("§r")) {
raw = raw.substring(2);
}
let clean = raw.replace(/§[a-f0-9rlonmk]/g, "").replace(/§/g, "");
let ansi = raw.replace(/§[a-f0-9rlonmk]/g, (m) => {
return ansimap[m];
});
return { raw, clean, ansi };
}
/**
* Parses a native minecraft text component in JSON form.
* @param {object} json - The json message.
* @param {object} parent - The parent json.
* @returns {string} The parsed raw string.
*/
function parseJson(json, parent) {
if (typeof json === "string") {
json = {text:json};
}
json.color = json.color || parent.color;
json.bold = json.bold || parent.bold;
json.italic = json.italic || parent.italic;
json.underlined = json.underlined || parent.underlined;
json.strikethrough = json.strikethrough || parent.strikethrough;
json.obfuscated = json.obfuscated || parent.obfuscated;
let raw = "";
raw += colormap[json.color] || "";
if (json.bold) { raw += "§l"; }
if (json.italic) { raw += "§o"; }
if (json.underlined) { raw += "§n"; }
if (json.strikethrough) { raw += "§m"; }
if (json.obfuscated) { raw += "§k"; }
if (json.text) {
raw += json.text;
}
if (json.translate) { // I checked with the native minecraft code. This is how Minecraft does the matching and group indexing. -hhhzzzsss
if (language[json.translate]) {
let _with = json.with || [];
let i = 0;
raw += language[json.translate].replace(/%(?:(\\d+)\\$)?(s|%)/g, (g0, g1) => {
if (g0 === "%%") {
return "%";
}
else {
let idx = g1 ? parseInt(g1) : i++;
if (_with[idx]) {
return parseJson(_with[idx], json);
}
else {
return "";
}
}
});
}
else {
raw += json.translate;
}
}
if (json.extra) {
json.extra.forEach(function (extra) {
raw += parseJson(extra, json);
});
}
return raw;
}
module.exports = parseText;

16
workers/pkg.js Normal file
View file

@ -0,0 +1,16 @@
const { workerData, parentPort } = require("worker_threads")
const child_process = require("child_process")
child_process.exec(`apt-cache search --names-only '${workerData.pkg}'`, function(err,stdout,stderr) {
if(stdout.trim() == "") {
parentPort.postMessage("NOTFOUND")
} else {
child_process.exec(`sudo apt-get install ${workerData.pkg} -y`, function(err,stdout,stderr) {
if(stderr.trim() == "" || err) {
parentPort.postMessage("ERR")
return;
}
parentPort.postMessage("INSTALLED")
})
}
})