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
This commit is contained in:
ChomeNS 2023-02-26 16:50:15 +07:00
parent 90cdfe6cd0
commit 5d2a06b424
5 changed files with 71 additions and 73 deletions

View file

@ -1,9 +1,9 @@
module.exports = { module.exports = {
version: '1.19', version: '1.19.2',
prefixes: [ prefixes: [
'*', 'd*',
'cbot ', 'devcbot ',
'/cbot ' '/devcbot '
], ],
commandsDir: '../commands', // this will be used by the commands.js in the plugins folder so it needs ../ commandsDir: '../commands', // this will be used by the commands.js in the plugins folder so it needs ../
keys: { keys: {
@ -12,7 +12,7 @@ module.exports = {
}, },
proxy: { proxy: {
enabled: true, enabled: true,
version: '1.19' version: '1.19.2'
}, },
console: true, console: true,
chat: { chat: {
@ -61,7 +61,7 @@ module.exports = {
'192.168.1.103': '1002806756885413978', '192.168.1.103': '1002806756885413978',
'kitsune.icu': '1004006678460637315', 'kitsune.icu': '1004006678460637315',
'fallback.kitsune.icu': '1050764247518412850', 'fallback.kitsune.icu': '1050764247518412850',
'chayapak.chipmunk.land': '1010734897796763758', 'chayapak.chipmunk.land': '1079331774783574116',
'play.chipmunk.land': '1042590315464364032', 'play.chipmunk.land': '1042590315464364032',
'mcslot.eu': '1057090538404323338' 'mcslot.eu': '1057090538404323338'
}, },
@ -73,30 +73,30 @@ module.exports = {
}, },
servers: [ servers: [
// logging means log to console // logging means log to console
{ // {
host: 'play.kaboom.pw', // host: 'play.kaboom.pw',
port: 25565, // port: 25565,
kaboom: true, // kaboom: true,
logging: true // logging: true
}, // },
{ // {
host: 'sus.shhnowisnottheti.me', // host: 'sus.shhnowisnottheti.me',
port: 25565, // port: 25565,
kaboom: true, // kaboom: true,
logging: true // logging: true
}, // },
{ // {
host: 'kitsune.icu', // host: 'kitsune.icu',
port: 25565, // port: 25565,
kaboom: true, // kaboom: true,
logging: false // logging: false
}, // },
{ // {
host: 'play.chipmunk.land', // host: 'play.chipmunk.land',
port: 25565, // port: 25565,
kaboom: true, // kaboom: true,
logging: true // logging: true
}, // },
{ {
host: 'chayapak.chipmunk.land', host: 'chayapak.chipmunk.land',
port: 25565, port: 25565,

View file

@ -27,27 +27,25 @@ function inject (bot, dcclient, config) {
const chatQueueInterval = setInterval(function () { const chatQueueInterval = setInterval(function () {
if (bot._chatQueue.length !== 0) { if (bot._chatQueue.length !== 0) {
if (minecraftVersionToNumber(bot.version) >= 1.19) { if (bot._chatQueue[0].startsWith('/') && minecraftVersionToNumber(bot.version) >= 1.19) {
// totallynotskidded™ from mineflayer/lib/plugins/chat.js // totallynotskidded™ from mineflayer
if (bot._chatQueue[0].startsWith('/')) { const command = bot._chatQueue[0].slice(1)
bot.write('chat_command', { const timestamp = BigInt(Date.now())
command: bot._chatQueue[0].substring(1), // removes / from the command bot._client.write('chat_command', {
timestamp: BigInt(Date.now()), command,
timestamp,
salt: 0n, salt: 0n,
argumentSignatures: [], argumentSignatures: [],
signedPreview: false signedPreview: false,
messageCount: 0,
acknowledged: Buffer.alloc(3),
// 1.19.2 Chat Command packet also includes an array of last seen messages
previousMessages: []
}) })
} else { } else {
bot.write('chat_message', { bot._client.chat(bot._chatQueue[0])
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
})
}
} else {
bot.write('chat', { message: bot._chatQueue[0] })
} }
bot._chatQueue.shift() bot._chatQueue.shift()
} }
}, 450) }, 450)
@ -68,7 +66,9 @@ function inject (bot, dcclient, config) {
minecraftVersionToNumber(bot.version) >= 1.19 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._client.on('chat', listener)
bot.on('message', (message, packet) => parsePlayerMessages(message, packet, bot)) bot.on('message', (message, packet) => parsePlayerMessages(message, packet, bot))

View file

@ -39,27 +39,25 @@ function inject (bot, dcclient, config) {
const clientPacketBlacklist = [] const clientPacketBlacklist = []
const targetPacketBlacklist = [] const targetPacketBlacklist = []
// target.chat exist so yeah.. // should this be here or in the chat plugin?
target.sendMessage = function (message) { target.sendMessage = function (message) {
if (minecraftVersionToNumber(target.version) >= 1.19) { if (message.startsWith('/') && minecraftVersionToNumber(target.version) >= 1.19) {
if (message.startsWith('/')) { // totallynotskidded™ from mineflayer
const command = message.slice(1)
const timestamp = BigInt(Date.now())
target.write('chat_command', { target.write('chat_command', {
command: message.substring(1), // removes / from the command command,
timestamp: BigInt(Date.now()), timestamp,
salt: 0n, salt: 0n,
argumentSignatures: [], argumentSignatures: [],
signedPreview: false signedPreview: false,
messageCount: 0,
acknowledged: Buffer.alloc(3),
// 1.19.2 Chat Command packet also includes an array of last seen messages
previousMessages: []
}) })
} else { } else {
target.write('chat_message', { target.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
})
}
} else {
target.write('chat', { message })
} }
} }

View file

@ -5,8 +5,8 @@ function inject (bot, client, target) {
function listener (packet) { function listener (packet) {
chatPacketListener(packet, target, minecraftVersionToNumber(target.version) >= 1.19) chatPacketListener(packet, target, minecraftVersionToNumber(target.version) >= 1.19)
} }
target.on('systemChat', listener)
target.on('chat', listener) target.on('chat', listener)
target.on('system_chat', listener)
target.on('message', (message, packet) => { target.on('message', (message, packet) => {
parsePlayerMessages(message, packet, target) parsePlayerMessages(message, packet, target)

View file

@ -5,11 +5,11 @@
* @param {boolean} mc119 minecraft 1.19 or newer * @param {boolean} mc119 minecraft 1.19 or newer
*/ */
function chatPacketListener (packet, bot, mc119) { 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 { try {
const ChatMessage = require('prismarine-chat')(bot.version) 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 // down here it prevents command set message
// for ayunboom cuz its 1.17.1 // for ayunboom cuz its 1.17.1
@ -21,7 +21,7 @@ function chatPacketListener (packet, bot, mc119) {
// VVVVVVVVVVVVVVVVVVVVV // VVVVVVVVVVVVVVVVVVVVV
if (parsedMessage.translate === 'advMode.setCommand.success') return 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) bot.emit('message', message, packet)
} catch (e) { } catch (e) {