From c7606db5168a8765c17f4da90cb9df44c8c9d0bb Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Thu, 17 Nov 2022 16:10:10 +0700 Subject: [PATCH] remove proxy + still don't know the cause --- bot.js | 1 - config.js | 1 - plugins/core.js | 9 ++- plugins/proxy.js | 96 ------------------------- plugins/proxy/chat.js | 15 ---- plugins/proxy/custom_chat_formatting.js | 32 --------- plugins/proxy/self_care.js | 49 ------------- 7 files changed, 6 insertions(+), 197 deletions(-) delete mode 100644 plugins/proxy.js delete mode 100644 plugins/proxy/chat.js delete mode 100644 plugins/proxy/custom_chat_formatting.js delete mode 100644 plugins/proxy/self_care.js diff --git a/bot.js b/bot.js index 8cea615..6a62517 100644 --- a/bot.js +++ b/bot.js @@ -49,7 +49,6 @@ async function createBot(server, config, getBots, dcclient) { bot.removeAllListeners(); bot._client.end(); bot._client.removeAllListeners(); - process.removeAllListeners(); }; bot.visibility = false; bot.getBots = getBots; diff --git a/config.js b/config.js index afd5c13..84e99e5 100644 --- a/config.js +++ b/config.js @@ -11,7 +11,6 @@ module.exports = { 'normalKey': '�iB_D���k��j8H�{?[/ڭ�f�}Ѣ�^-=�Ț��v]��g>��=c', 'ownerHashKey': 'b)R��nF�CW���#�\\[�S*8"t^eia�Z��k����K1�8zȢ�', }, - 'proxy': true, 'console': true, 'useChat': false, 'core': { diff --git a/plugins/core.js b/plugins/core.js index fc4a446..8eca738 100644 --- a/plugins/core.js +++ b/plugins/core.js @@ -1,14 +1,14 @@ /* eslint-disable max-len */ /* eslint-disable require-jsdoc */ const nbt = require('prismarine-nbt'); -const mcData = require('minecraft-data')('1.18.2'); const sleep = require('sleep-promise'); -const chatMessage = require('prismarine-chat')('1.18.2'); const Vec3 = require('vec3'); const relativePosition = new Vec3(0, 0, 0); function inject(bot, dcclient, config) { + const mcData = require('minecraft-data')(bot.version); + const chatMessage = require('prismarine-chat')(bot.version); const core = { isCore(position) { return position.x >= core.start.x && position.x <= core.end.x && position.y >= core.start.y && position.y <= core.end.y && position.z >= core.start.z && position.z <= core.end.z; @@ -40,13 +40,16 @@ function inject(bot, dcclient, config) { relativePosition.z = 0; } + const impulseMode = !bot.options.kaboom; + const location = { x: core.start.x + relativePosition.x, y: core.start.y + relativePosition.y, z: core.start.z + relativePosition.z, }; - bot.write('update_command_block', {location, command: command.substring(0, 32767), mode: 2, flags: 0b101}); + if (impulseMode) bot.write('update_command_block', {location, command: command.substring(0, 32767), mode: 0, flags: 0}); + bot.write('update_command_block', {location, command: command.substring(0, 32767), mode: impulseMode ? 2 : 1, flags: 0b100}); } catch (e) { bot.console.error(e); } diff --git a/plugins/proxy.js b/plugins/proxy.js deleted file mode 100644 index 091597f..0000000 --- a/plugins/proxy.js +++ /dev/null @@ -1,96 +0,0 @@ -/* eslint-disable require-jsdoc */ -const mc = require('minecraft-protocol'); -const {loadPlugins} = require('../util/loadPlugins'); - -function inject(bot, dcclient, config) { - if (!config.proxy) return; - - let index; - config.servers.forEach((server, _index) => { - if (bot.options.host !== server.host) return; - index = _index; - }); - - const version = bot.version; - const srv = mc.createServer({ - 'online-mode': false, - 'port': 25566 + index, - 'keepAlive': false, - version, - }); - - srv.on('login', function(client) { - bot.console.info(`[Proxy] ${client.username} connected to proxy`); - let endedClient = false; - let endedTarget = false; - - const targetClient = mc.createClient({ - username: client.username, - host: bot.options.host, - version, - }); - - targetClient.chat = function(message) { - targetClient.write('chat', {message}); - }; - - targetClient.on('login', (packet) => { - targetClient.entityId = packet.entityId; - loadPlugins(bot, null, config, null, targetClient, client, true); - }); - - targetClient.on('packet', (data, meta) => { - if (!endedClient && - meta.state === mc.states.PLAY && - client.state === mc.states.PLAY - ) client.write(meta.name, data); - }); - - targetClient.on('error', () => {}); - - targetClient.on('end', () => { - targetClient.end(); - endedTarget = true; - }); - - client.on('end', function() { - endedClient = true; - targetClient.end(); - targetClient.removeAllListeners(); - client.removeAllListeners(); - bot.console.info(`[Proxy] ${client.username} ended`); - }); - - client.on('error', function() { - endedClient = true; - targetClient.removeAllListeners(); - client.removeAllListeners(); - bot.console.info(`[Proxy] ${client.username} got error`); - }); - - client.on('packet', (data, meta) => { - if (meta.name === 'chat' && !data.message?.startsWith('/')) { - if (data.message.startsWith('.')) { - return bot.command_handler.run( - client.username, - client.username, - '*' + data.message.substring(1), - client.uuid, - null, - 'h', - 'o', - client.username, - ); - } - return; - } - targetClient.write(meta.name, data); - }); - }); - bot.once('end', () => { - srv.close(); - srv.removeAllListeners(); - }); -}; - -module.exports = {inject}; diff --git a/plugins/proxy/chat.js b/plugins/proxy/chat.js deleted file mode 100644 index 2fcfd8e..0000000 --- a/plugins/proxy/chat.js +++ /dev/null @@ -1,15 +0,0 @@ -/* eslint-disable require-jsdoc */ -const {chatPacketListener, parsePlayerMessages} = require('../../util/chat'); -function inject(bot, client, targetClient) { - const ChatMessage = require('prismarine-chat')(bot.version); - - targetClient.on('chat', (packet) => { - chatPacketListener(packet, ChatMessage, '', targetClient); - }); - - targetClient.on('parsed_chat', (message, packet) => { - parsePlayerMessages(message, packet, targetClient); - }); -}; - -module.exports = {inject}; diff --git a/plugins/proxy/custom_chat_formatting.js b/plugins/proxy/custom_chat_formatting.js deleted file mode 100644 index 8dea2cc..0000000 --- a/plugins/proxy/custom_chat_formatting.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-disable require-jsdoc */ -function inject(bot, client, targetClient) { - const {MessageBuilder} = require('prismarine-chat')(bot.version); - client.on('packet', (data, meta) => { - if (meta.name === 'chat' && - !data.message?.startsWith('/') && - !data.message?.startsWith('.') - ) { - bot.tellraw('@a', { - color: 'dark_gray', - translate: '[%s] [%s] %s \u203a %s', - with: [ - { - text: 'Chat', - color: 'gray', - }, - { - text: 'Proxy', - color: 'gray', - }, - { - text: client.username, - color: 'green', - }, - MessageBuilder.fromString('&7' + data.message), - ], - }); - } - }); -}; - -module.exports = {inject}; diff --git a/plugins/proxy/self_care.js b/plugins/proxy/self_care.js deleted file mode 100644 index fe4ae41..0000000 --- a/plugins/proxy/self_care.js +++ /dev/null @@ -1,49 +0,0 @@ -/* eslint-disable max-len */ -/* eslint-disable require-jsdoc */ -function inject(bot, client, targetClient, config) { - let cspy = false; - let op = true; - let gameMode = 1; - - targetClient.on('parsed_chat', (data) => { - if (data.toString() === 'Successfully enabled CommandSpy' || data.toString() === ' Enabled your command spy.' || data.toString() === ' Your command spy is already enabled.') cspy = true; - if (data.toString() === 'Successfully disabled CommandSpy' || data.toString() === ' Disabled your command spy.') cspy = false; - }); - - targetClient.on('entity_status', (data) => { - if (data.entityId !== targetClient.entityId) return; - - switch (data.entityStatus) { - case 24: - op = false; - break; - case 28: - op = true; - break; - } - }); - - targetClient.on('game_state_change', (data) => { - if (data.reason !== 3) return; - - gameMode = data.gameMode; - }); - - targetClient.once('login', (data) => { - gameMode = data.gameMode; - }); - - const interval = setInterval(() => { - if (bot.options.kaboom) { - if (!op && config.self_care.op) targetClient.chat('/minecraft:op @s[type=player]'); - if (!cspy && config.self_care.cspy) targetClient.chat('/commandspy:commandspy on'); - } - if (gameMode !== 1 && config.self_care.gamemode) targetClient.chat('/minecraft:gamemode creative @s[type=player]'); - }, config.self_care_check_interval); - - bot.once('end', () => { - clearInterval(interval); - }); -}; - -module.exports = {inject};