From 5d2a06b424b0826050a157798ca7a1a9662b2c39 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Sun, 26 Feb 2023 16:50:15 +0700 Subject: [PATCH] 1.19.1/2 support (not 1.19.3) not 1.19.3 because formattedMessage doesn't exist on kaboom so prefixes like [OP] doesn't appear --- config.js | 60 +++++++++++++++++++++---------------------- plugins/chat.js | 40 ++++++++++++++--------------- plugins/proxy.js | 36 ++++++++++++-------------- plugins/proxy/chat.js | 2 +- util/chat.js | 6 ++--- 5 files changed, 71 insertions(+), 73 deletions(-) diff --git a/config.js b/config.js index 90fd424..5998ec5 100644 --- a/config.js +++ b/config.js @@ -1,9 +1,9 @@ module.exports = { - version: '1.19', + version: '1.19.2', prefixes: [ - '*', - 'cbot ', - '/cbot ' + 'd*', + 'devcbot ', + '/devcbot ' ], commandsDir: '../commands', // this will be used by the commands.js in the plugins folder so it needs ../ keys: { @@ -12,7 +12,7 @@ module.exports = { }, proxy: { enabled: true, - version: '1.19' + version: '1.19.2' }, console: true, chat: { @@ -61,7 +61,7 @@ module.exports = { '192.168.1.103': '1002806756885413978', 'kitsune.icu': '1004006678460637315', 'fallback.kitsune.icu': '1050764247518412850', - 'chayapak.chipmunk.land': '1010734897796763758', + 'chayapak.chipmunk.land': '1079331774783574116', 'play.chipmunk.land': '1042590315464364032', 'mcslot.eu': '1057090538404323338' }, @@ -73,30 +73,30 @@ module.exports = { }, servers: [ // logging means log to console - { - host: 'play.kaboom.pw', - port: 25565, - kaboom: true, - logging: true - }, - { - host: 'sus.shhnowisnottheti.me', - port: 25565, - kaboom: true, - logging: true - }, - { - host: 'kitsune.icu', - port: 25565, - kaboom: true, - logging: false - }, - { - host: 'play.chipmunk.land', - port: 25565, - kaboom: true, - logging: true - }, + // { + // host: 'play.kaboom.pw', + // port: 25565, + // kaboom: true, + // logging: true + // }, + // { + // host: 'sus.shhnowisnottheti.me', + // port: 25565, + // kaboom: true, + // logging: true + // }, + // { + // host: 'kitsune.icu', + // port: 25565, + // kaboom: true, + // logging: false + // }, + // { + // host: 'play.chipmunk.land', + // port: 25565, + // kaboom: true, + // logging: true + // }, { host: 'chayapak.chipmunk.land', port: 25565, diff --git a/plugins/chat.js b/plugins/chat.js index 615db30..f2f0066 100644 --- a/plugins/chat.js +++ b/plugins/chat.js @@ -27,27 +27,25 @@ function inject (bot, dcclient, config) { const chatQueueInterval = setInterval(function () { if (bot._chatQueue.length !== 0) { - if (minecraftVersionToNumber(bot.version) >= 1.19) { - // totallynotskidded™️ from mineflayer/lib/plugins/chat.js - if (bot._chatQueue[0].startsWith('/')) { - bot.write('chat_command', { - command: bot._chatQueue[0].substring(1), // removes / from the command - timestamp: BigInt(Date.now()), - salt: 0n, - argumentSignatures: [], - signedPreview: false - }) - } else { - bot.write('chat_message', { - message: bot._chatQueue[0], - timestamp: BigInt(Date.now()), - salt: 0, - signature: Buffer.alloc(0) // the bot will never go online mode i guess so i will just use this - }) - } + if (bot._chatQueue[0].startsWith('/') && minecraftVersionToNumber(bot.version) >= 1.19) { + // totallynotskidded™️ from mineflayer + const command = bot._chatQueue[0].slice(1) + const timestamp = BigInt(Date.now()) + bot._client.write('chat_command', { + command, + timestamp, + salt: 0n, + argumentSignatures: [], + signedPreview: false, + messageCount: 0, + acknowledged: Buffer.alloc(3), + // 1.19.2 Chat Command packet also includes an array of last seen messages + previousMessages: [] + }) } else { - bot.write('chat', { message: bot._chatQueue[0] }) + bot._client.chat(bot._chatQueue[0]) } + bot._chatQueue.shift() } }, 450) @@ -68,7 +66,9 @@ function inject (bot, dcclient, config) { minecraftVersionToNumber(bot.version) >= 1.19 ) } - bot._client.on('system_chat', listener) + // TODO: support playerChat (formattedMessage doesn't exist on kaboom so prefixes like [OP] doesn't appear) + // bot._client.on('playerChat', listener) + bot._client.on('systemChat', listener) bot._client.on('chat', listener) bot.on('message', (message, packet) => parsePlayerMessages(message, packet, bot)) diff --git a/plugins/proxy.js b/plugins/proxy.js index 10f446b..5d6f864 100644 --- a/plugins/proxy.js +++ b/plugins/proxy.js @@ -39,27 +39,25 @@ function inject (bot, dcclient, config) { const clientPacketBlacklist = [] const targetPacketBlacklist = [] - // target.chat exist so yeah.. + // should this be here or in the chat plugin? target.sendMessage = function (message) { - if (minecraftVersionToNumber(target.version) >= 1.19) { - if (message.startsWith('/')) { - target.write('chat_command', { - command: message.substring(1), // removes / from the command - timestamp: BigInt(Date.now()), - salt: 0n, - argumentSignatures: [], - signedPreview: false - }) - } else { - target.write('chat_message', { - message, - timestamp: BigInt(Date.now()), - salt: 0, - signature: Buffer.alloc(0) // the bot will never go online mode i guess so i will just use this - }) - } + if (message.startsWith('/') && minecraftVersionToNumber(target.version) >= 1.19) { + // totallynotskidded™️ from mineflayer + const command = message.slice(1) + const timestamp = BigInt(Date.now()) + target.write('chat_command', { + command, + timestamp, + salt: 0n, + argumentSignatures: [], + signedPreview: false, + messageCount: 0, + acknowledged: Buffer.alloc(3), + // 1.19.2 Chat Command packet also includes an array of last seen messages + previousMessages: [] + }) } else { - target.write('chat', { message }) + target.chat(message) } } diff --git a/plugins/proxy/chat.js b/plugins/proxy/chat.js index db41f38..ec3b7f8 100644 --- a/plugins/proxy/chat.js +++ b/plugins/proxy/chat.js @@ -5,8 +5,8 @@ function inject (bot, client, target) { function listener (packet) { chatPacketListener(packet, target, minecraftVersionToNumber(target.version) >= 1.19) } + target.on('systemChat', listener) target.on('chat', listener) - target.on('system_chat', listener) target.on('message', (message, packet) => { parsePlayerMessages(message, packet, target) diff --git a/util/chat.js b/util/chat.js index 6acbf99..7ec7a53 100644 --- a/util/chat.js +++ b/util/chat.js @@ -5,11 +5,11 @@ * @param {boolean} mc119 minecraft 1.19 or newer */ function chatPacketListener (packet, bot, mc119) { - // try catch prevents json parse error (which prob never happens but still..) + // try catch prevents json parse error (happens with a custom server that sends an invalid json component for example) try { const ChatMessage = require('prismarine-chat')(bot.version) - const parsedMessage = JSON.parse(mc119 ? packet.content : packet.message) + const parsedMessage = JSON.parse(mc119 ? packet.formattedMessage : packet.message) // down here it prevents command set message // for ayunboom cuz its 1.17.1 @@ -21,7 +21,7 @@ function chatPacketListener (packet, bot, mc119) { // VVVVVVVVVVVVVVVVVVVVV if (parsedMessage.translate === 'advMode.setCommand.success') return - const message = ChatMessage.fromNotch(mc119 ? packet.content : packet.message) + const message = ChatMessage.fromNotch(mc119 ? packet.formattedMessage : packet.message) bot.emit('message', message, packet) } catch (e) {