diff --git a/plugins/proxy.js b/plugins/proxy.js index 5ac824b..25e5f01 100644 --- a/plugins/proxy.js +++ b/plugins/proxy.js @@ -31,6 +31,8 @@ function inject (bot, dcclient, config) { version }) + const targetPacketBlacklist = [] + target.chat = function (message) { target.write('chat', { message }) } @@ -38,13 +40,14 @@ function inject (bot, dcclient, config) { target.on('login', (packet) => { bot.console.info(`[Proxy] ${client.username} target logged in`) target.entityId = packet.entityId - loadPlugins(bot, null, config, null, target, client, true) + loadPlugins(bot, null, config, null, target, client, true, targetPacketBlacklist) }) target.on('packet', (data, meta) => { if (!clientEnded && meta.state === mc.states.PLAY && - client.state === mc.states.PLAY + client.state === mc.states.PLAY && + !targetPacketBlacklist.includes(meta.name) ) client.write(meta.name, data) }) @@ -88,6 +91,7 @@ function inject (bot, dcclient, config) { } target.write(meta.name, data) }) + function endListener (reason) { client.end(`Bot disconnected with reason: ${util.inspect(reason)}`) bot.off('end', endListener) diff --git a/util/loadPlugins.js b/util/loadPlugins.js index fe1340c..ccb0f91 100644 --- a/util/loadPlugins.js +++ b/util/loadPlugins.js @@ -11,8 +11,9 @@ const path = require('path') * @param {object} target proxy target * @param {object} client proxy client * @param {boolean} proxy is proxy + * @param {array} targetPacketBlacklist target packet blacklist */ -async function loadPlugins (bot, dcclient, config, rl, target, client, proxy) { +async function loadPlugins (bot, dcclient, config, rl, target, client, proxy, targetPacketBlacklist) { const dir = path.join(__dirname, '..', 'plugins', proxy ? 'proxy' : '') const plugins = await fs.readdir(dir) plugins.forEach((plugin) => { @@ -20,7 +21,7 @@ async function loadPlugins (bot, dcclient, config, rl, target, client, proxy) { try { const plug = require(path.join(dir, plugin)) if (!proxy) plug.inject(bot, dcclient, config, rl) - else plug.inject(bot, client, target, config) + else plug.inject(bot, client, target, config, targetPacketBlacklist) } catch (e) { console.log(`Plugin ${plugin} is having exception loading the plugin:`) console.log(util.inspect(e))