refactor: small cleanups #1
10 changed files with 108 additions and 80 deletions
4
index.js
4
index.js
|
@ -30,9 +30,9 @@ const createBot = function createBot (host, oldId) {
|
|||
|
||||
bot._client = createClient({
|
||||
host: host.host,
|
||||
port: host.port ? host.port : 25565,
|
||||
port: host.port ?? 25565,
|
||||
username: generateUser(host.options.legalName),
|
||||
version: host.version ? host.version : settings.version_mc
|
||||
version: host.version ?? settings.version_mc
|
||||
})
|
||||
|
||||
bot.info = (msg) => {
|
||||
|
|
19
launch.cmd
19
launch.cmd
|
@ -1,8 +1,15 @@
|
|||
@echo off
|
||||
|
||||
:botlaunch
|
||||
node index.js
|
||||
if %errorlevel%==1 (
|
||||
exit
|
||||
)
|
||||
timeout /nobreak /t 5 > nul
|
||||
goto botlaunch
|
||||
node index.js
|
||||
call :err_unwrap
|
||||
|
||||
timeout /nobreak /t 5 >NUL
|
||||
goto botlaunch
|
||||
|
||||
:err_unwrap
|
||||
set _err=%ERRORLEVEL%
|
||||
if %_err% neq 0 (
|
||||
exit %_err%
|
||||
)
|
||||
goto :eof
|
||||
|
|
11
launch.sh
11
launch.sh
|
@ -1,6 +1,7 @@
|
|||
#!/bin/bash
|
||||
while [ true ];
|
||||
do node index.js;
|
||||
if [ $? -eq 1 ]; then exit; fi
|
||||
sleep 6;
|
||||
#!/bin/sh
|
||||
set -xe
|
||||
|
||||
while :; do
|
||||
node index.js
|
||||
sleep 5
|
||||
done
|
65
package-lock.json
generated
65
package-lock.json
generated
|
@ -9,7 +9,8 @@
|
|||
"version": "12.0.0-alpha.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"minecraft-protocol": "^1.49.0"
|
||||
"minecraft-protocol": "^1.51.0",
|
||||
"prismarine-chat": "^1.10.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@azure/msal-common": {
|
||||
|
@ -36,12 +37,21 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "22.9.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.1.tgz",
|
||||
"integrity": "sha512-p8Yy/8sw1caA8CdRIQBG5tiLHmxtQKObCijiAa9Ez+d4+PRffM4054xbju0msf+cvhJpnFEeNjxmVT/0ipktrg==",
|
||||
"version": "22.10.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.2.tgz",
|
||||
"integrity": "sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.19.8"
|
||||
"undici-types": "~6.20.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node-rsa": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/node-rsa/-/node-rsa-1.1.4.tgz",
|
||||
"integrity": "sha512-dB0ECel6JpMnq5ULvpUTunx3yNm8e/dIkv8Zu9p2c8me70xIRUUG3q+qXRwcSf9rN3oqamv4116iHy90dJGRpA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/readable-stream": {
|
||||
|
@ -188,9 +198,9 @@
|
|||
"license": "MIT"
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.3.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
|
||||
"integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz",
|
||||
"integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
|
@ -420,9 +430,9 @@
|
|||
"license": "MIT"
|
||||
},
|
||||
"node_modules/minecraft-data": {
|
||||
"version": "3.78.0",
|
||||
"resolved": "https://registry.npmjs.org/minecraft-data/-/minecraft-data-3.78.0.tgz",
|
||||
"integrity": "sha512-Ssks8QD31lsoxqa7LySTqeP9romsfAbfsSGiUHiGMeqfxRi/PtOxGLyKD1BXB8V/tXLztFcbQYqzIhprDkPguw==",
|
||||
"version": "3.80.0",
|
||||
"resolved": "https://registry.npmjs.org/minecraft-data/-/minecraft-data-3.80.0.tgz",
|
||||
"integrity": "sha512-UYq+ADpS9K1+cqiJiz6tqkht4y4cRYF3qOYanG9eIiHY+VC+qIAC7/UcW6G3adayvj5YBOCurlqaw3E0TMAtHg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/minecraft-folder-path": {
|
||||
|
@ -432,11 +442,12 @@
|
|||
"license": "MIT"
|
||||
},
|
||||
"node_modules/minecraft-protocol": {
|
||||
"version": "1.50.0",
|
||||
"resolved": "https://registry.npmjs.org/minecraft-protocol/-/minecraft-protocol-1.50.0.tgz",
|
||||
"integrity": "sha512-GiZy8g4YG0iZEKifX6ulCyhVnTDGZ1gH0ouUdxjo6xkKwp4KOf+ptbBgZ8G5+WHCumrI91+v/JYU07uCvKdi0w==",
|
||||
"version": "1.51.0",
|
||||
"resolved": "https://registry.npmjs.org/minecraft-protocol/-/minecraft-protocol-1.51.0.tgz",
|
||||
"integrity": "sha512-ACvquP6fI8TdPXfPNNGTTi9v12WW6LS4k2KmmUBSmNncM0KnUwywqTT6YQIfCff6dUMd9DZB1oaNZfEDto+QQw==",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"@types/node-rsa": "^1.1.4",
|
||||
"@types/readable-stream": "^4.0.0",
|
||||
"aes-js": "^3.1.2",
|
||||
"buffer-equal": "^1.0.0",
|
||||
|
@ -560,12 +571,12 @@
|
|||
}
|
||||
},
|
||||
"node_modules/prismarine-nbt": {
|
||||
"version": "2.6.0",
|
||||
"resolved": "https://registry.npmjs.org/prismarine-nbt/-/prismarine-nbt-2.6.0.tgz",
|
||||
"integrity": "sha512-z65ijm6hVlYOmhg8IEzdYfUz1u3AOiQtzyTSAwD8NLBCr96ZUPtUH5o/6sGAoDaN+rkDe0DNBCiO7bvXXO1fkQ==",
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/prismarine-nbt/-/prismarine-nbt-2.7.0.tgz",
|
||||
"integrity": "sha512-Du9OLQAcCj3y29YtewOJbbV4ARaSUEJiTguw0PPQbPBy83f+eCyDRkyBpnXTi/KPyEpgYCzsjGzElevLpFoYGQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"protodef": "^1.9.0"
|
||||
"protodef": "^1.18.0"
|
||||
}
|
||||
},
|
||||
"node_modules/prismarine-realms": {
|
||||
|
@ -598,9 +609,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/protodef": {
|
||||
"version": "1.17.0",
|
||||
"resolved": "https://registry.npmjs.org/protodef/-/protodef-1.17.0.tgz",
|
||||
"integrity": "sha512-mnpNPV3xwu63u3NwZuXM1RCp979vjHxUGHzVrb6dxbvof5Fx+b8Rs0G0c3xtEuFDreGAMWS7VrlNkDUDBMsFWQ==",
|
||||
"version": "1.18.0",
|
||||
"resolved": "https://registry.npmjs.org/protodef/-/protodef-1.18.0.tgz",
|
||||
"integrity": "sha512-jO64lkzkh0dYc0AVWCU/GzCKwqhFFIz1kfEz0NBf0RUuRNcmvgKbopabJdfZ6W8NvALdySUXgEhvKDZPhdBwrg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"lodash.get": "^4.4.2",
|
||||
|
@ -613,9 +624,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/protodef-validator": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/protodef-validator/-/protodef-validator-1.3.1.tgz",
|
||||
"integrity": "sha512-lZ5FWKZYR9xOjpMw1+EfZRfCjzNRQWPq+Dk+jki47Sikl2EeWEPnTfnJERwnU/EwFq6us+0zqHHzSsmLeYX+Lg==",
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/protodef-validator/-/protodef-validator-1.4.0.tgz",
|
||||
"integrity": "sha512-2y2coBolqCEuk5Kc3QwO7ThR+/7TZiOit4FrpAgl+vFMvq8w76nDhh09z08e2NQOdrgPLsN2yzXsvRvtADgUZQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ajv": "^6.5.4"
|
||||
|
@ -741,9 +752,9 @@
|
|||
"license": "MIT"
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "6.19.8",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
|
||||
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
|
||||
"version": "6.20.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
|
||||
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/uri-js": {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"author": "7cc5c4f330d47060",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"minecraft-protocol": "^1.49.0"
|
||||
"minecraft-protocol": "^1.51.0",
|
||||
"prismarine-chat": "^1.10.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,32 +23,39 @@ const rl = createInterface({
|
|||
prompt: '\x1b[0m> '
|
||||
})
|
||||
rl.on('line', (l) => {
|
||||
const args = l.split(' ');
|
||||
const cmdName = args[0].toLowerCase();
|
||||
|
||||
try {
|
||||
if (cmds[l.split(' ')[0].toLowerCase()]) {
|
||||
if (cmds[l.split(' ')[0].toLowerCase()].consoleIndex) {
|
||||
const tmpcmd = l.split(' ')
|
||||
const index2 = tmpcmd.splice(1, 1)[0]
|
||||
if (index2 === '*') {
|
||||
for (let i = 0; i < bots.length; i++) {
|
||||
const cmd = new Command(uuid, user, nick, tmpcmd.join(' '), 'console', 'console', 'console', '', bots[i])
|
||||
cmd.verify = 2
|
||||
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
|
||||
}
|
||||
} else {
|
||||
const cmd = new Command(uuid, user, nick, tmpcmd.join(' '), 'console', 'console', 'console', '', bots[+index2])
|
||||
cmd.verify = 2
|
||||
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
|
||||
const cmd = cmds[cmdName];
|
||||
if (!cmd) {
|
||||
rl.prompt(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd.consoleIndex) {
|
||||
const index2 = args.splice(1, 1)[0];
|
||||
if (index2 === '*') {
|
||||
for (let i = 0; i < bots.length; i++) {
|
||||
const context = new Command(uuid, user, nick, args.join(' '), 'console', 'console', 'console', '', bots[i])
|
||||
context.verify = 2
|
||||
cmd.execute(context)
|
||||
}
|
||||
} else {
|
||||
const cmd = new Command(uuid, user, nick, l, 'console', 'console', 'console', '', consoleBotStub)
|
||||
cmd.verify = 2
|
||||
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
|
||||
const context = new Command(uuid, user, nick, args.join(' '), 'console', 'console', 'console', '', bots[+index2])
|
||||
context.verify = 2
|
||||
cmd.execute(context)
|
||||
}
|
||||
} else {
|
||||
const context = new Command(uuid, user, nick, l, 'console', 'console', 'console', '', consoleBotStub)
|
||||
context.verify = 2
|
||||
cmd.execute(context)
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
rl.prompt(false)
|
||||
|
||||
rl.prompt(false);
|
||||
})
|
||||
rl.prompt()
|
||||
|
||||
|
@ -58,6 +65,7 @@ function consoleWrite (text) {
|
|||
process.stdout.write(text + '\n')
|
||||
rl.prompt(true)
|
||||
}
|
||||
|
||||
export default function load (b) {
|
||||
b.info = (msg) => {
|
||||
consoleWrite(`[${b.id}] [info] ${msg}`)
|
||||
|
|
|
@ -15,8 +15,8 @@ export default class Command {
|
|||
this.colors = settings.colors
|
||||
this.lang = settings.defaultLang
|
||||
this.verify = 0
|
||||
this.host = bot.host.host
|
||||
this.port = bot.host.port
|
||||
this.host = bot?.host.host
|
||||
this.port = bot?.host.port
|
||||
this.bot = bot
|
||||
|
||||
this.rewriteCommand = newCmd => {
|
||||
|
|
|
@ -7,13 +7,12 @@ export default function (cmd, uuid) {
|
|||
const dateString = _dateString.slice(0, _dateString.length - 4)
|
||||
const hashTrusted = `babyboom:${settings.keyTrusted}:${uuid}:${cmdWithoutHash}:${dateString}`
|
||||
const hashOwner = `babyboom:${settings.keyOwner}:${uuid}:${cmdWithoutHash}:${dateString}`
|
||||
|
||||
const hashPart = cmd[cmd.length - 1];
|
||||
const validhashT = createHash('sha256').update(hashTrusted).digest('hex')
|
||||
const validhashO = createHash('sha256').update(hashOwner).digest('hex')
|
||||
if (cmd[cmd.length - 1] === validhashT) {
|
||||
return 1
|
||||
}
|
||||
if (cmd[cmd.length - 1] === validhashO) {
|
||||
return 2
|
||||
}
|
||||
if (hashPart === validhashT) return 1
|
||||
if (hashPart === validhashO) return 2
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import MinecraftData from 'minecraft-data'
|
||||
const _lang = MinecraftData('1.20.6').language
|
||||
const _lang = MinecraftData('1.21.1').language
|
||||
const lang = Object.create(null) // Without constructor function
|
||||
for (const i in _lang) {
|
||||
lang[i] = _lang[i]
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
||||
const THRESHOLD = 1000; // KiB = 1024; KB = 1000
|
||||
|
||||
export default function memoryconvert (bytes) {
|
||||
if (bytes >= 1125899906842624) { // Petabytes
|
||||
return `${Math.round(bytes / 1125899906842624 * 100) / 100} PB`
|
||||
} else if (bytes >= 1099511627776) { // Terabytes
|
||||
return `${Math.round(bytes / 1099511627776 * 100) / 100} TB`
|
||||
} else if (bytes >= 1073741824) { // Gigabytes
|
||||
return `${Math.round(bytes / 1073741824 * 100) / 100} GB`
|
||||
} else if (bytes >= 1048576) { // Megabytes
|
||||
return `${Math.round(bytes / 1048576 * 100) / 100} MB`
|
||||
} else if (bytes >= 1024) { // Kilobytes
|
||||
return `${Math.round(bytes / 1024 * 100) / 100} KB`
|
||||
} else { // Bytes
|
||||
return `${bytes} B`
|
||||
for (let i = 0; i < UNITS.length; i++) {
|
||||
const last = i === (UNITS.length - 1);
|
||||
const max = THRESHOLD ** (i + 1);
|
||||
if (!last && bytes >= max) continue;
|
||||
|
||||
const divisor = THRESHOLD ** i;
|
||||
const unit = UNITS[i];
|
||||
|
||||
const div = bytes / divisor;
|
||||
return `${+div.toFixed(2)} ${unit}`
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue