From 93f911aaa8a0e94de99346d83d7b55977d7d3a41 Mon Sep 17 00:00:00 2001 From: Chipmunk <65827213+ChipmunkMC@users.noreply.github.com> Date: Wed, 11 Sep 2024 08:53:27 -0400 Subject: [PATCH] Make echo send the message normally, and don't use non-initialized memory for the acknowledged buffer --- commands/echo.js | 16 +++++++++++++++- plugins/chat.js | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/commands/echo.js b/commands/echo.js index 3e78ac4..455bcae 100644 --- a/commands/echo.js +++ b/commands/echo.js @@ -16,6 +16,20 @@ module.exports = { echoCommand (context) { const bot = context.source.bot - bot.core.run(`essentials:sudo ${bot.uuid} c:${context.getArgument('message')}`) + bot.chat.queue.push(this.sanitize(context.getArgument('message'))) + }, + + sanitize (message) { + let clean = '' + + for (let i = 0; i < message.length && clean.length < 256; i++) { + const c = message[i] + const cc = c.charCodeAt(0) + + if (cc < 0x20 || cc === 0x7f || cc === 0xa7) continue + clean += c + } + + return clean } } diff --git a/plugins/chat.js b/plugins/chat.js index f0f1baf..126565d 100644 --- a/plugins/chat.js +++ b/plugins/chat.js @@ -26,7 +26,7 @@ function inject (bot) { timestamp: BigInt(Date.now()), salt: 0n, offset: 0, - acknowledged: Buffer.allocUnsafe(3) + acknowledged: Buffer.alloc(3) }) },