readd proxy :))

This commit is contained in:
ChomeNS 2022-11-30 18:01:46 +07:00
parent 658cf1297d
commit e0ff3c6504
8 changed files with 213 additions and 13 deletions

View file

@ -5,9 +5,9 @@ module.exports = {
usage: '',
trusted: 0,
execute (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.loopPlace()
bot.core.fillCore()
},
discordExecute (bot) {
bot.core.loopPlace()
bot.core.fillCore()
}
}

View file

@ -11,6 +11,7 @@ module.exports = {
normalKey: '<27>iB_D<5F><44><EFBFBD>k<EFBFBD><6B>j8H<38>{?[/ڭ<>f<EFBFBD><>^-=<3D>Ț<EFBFBD><C89A>v]<5D><>g><3E><>=c',
ownerHashKey: 'b)R<><52>nF<6E>CW<43><57><EFBFBD>#<23>\\[<5B>S*8"t^eia<69>Z<EFBFBD><5A>k<EFBFBD><6B><EFBFBD><EFBFBD>K1<4B>8zȢ<7A>'
},
proxy: true,
console: true,
useChat: false,
core: {
@ -74,11 +75,11 @@ module.exports = {
host: 'real.chipmunk.land',
port: 25565,
kaboom: true
},
{
host: 'mc.chomens41793.ga',
port: 25565,
kaboom: true
}
}// ,
// {
// host: 'mc.chomens41793.ga',
// port: 25565,
// kaboom: true
// }
]
}

View file

@ -32,5 +32,5 @@ dcclient.on('ready', () => {
dcclient.login(config.discord.token)
process.on('uncaughtException', (e) => {
console.log('uncaught ' + e)
console.log('uncaught ' + e.stack)
})

100
plugins/proxy.js Normal file
View file

@ -0,0 +1,100 @@
/* eslint-disable require-jsdoc */
const util = require('util')
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 clientEnded = false
let targetEnded = false
const target = mc.createClient({
username: client.username,
host: bot.options.host,
version
})
target.chat = function (message) {
target.write('chat', { message })
}
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)
})
target.on('packet', (data, meta) => {
if (!clientEnded &&
meta.state === mc.states.PLAY &&
client.state === mc.states.PLAY
) client.write(meta.name, data)
})
target.on('error', () => {})
target.on('end', () => {
target.end()
targetEnded = true
})
client.on('end', function () {
clientEnded = true
target.end()
target.removeAllListeners()
client.removeAllListeners()
bot.console.info(`[Proxy] ${client.username} ended`)
})
client.on('error', function () {
clientEnded = true
target.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
}
target.write(meta.name, data)
})
function endListener (reason) {
client.end(`Bot disconnected with reason: ${util.inspect(reason)}`)
bot.off('end', endListener)
srv.removeAllListeners()
}
bot.on('end', endListener)
})
};
module.exports = { inject }

15
plugins/proxy/chat.js Normal file
View file

@ -0,0 +1,15 @@
/* eslint-disable require-jsdoc */
const { chatPacketListener, parsePlayerMessages } = require('../../util/chat')
function inject (bot, client, target) {
const ChatMessage = require('prismarine-chat')(bot.version)
target.on('chat', (packet) => {
chatPacketListener(packet, ChatMessage, target)
})
target.on('parsed_chat', (message, packet) => {
parsePlayerMessages(message, packet, target)
})
};
module.exports = { inject }

View file

@ -0,0 +1,32 @@
/* eslint-disable require-jsdoc */
function inject (bot, client, target) {
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 }

View file

@ -0,0 +1,48 @@
/* eslint-disable require-jsdoc */
function inject (bot, client, target, config) {
let cspy = false
let op = true
let gameMode = 1
target.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
})
target.on('entity_status', (data) => {
if (data.entityId !== target.entityId) return
switch (data.entityStatus) {
case 24:
op = false
break
case 28:
op = true
break
}
})
target.on('game_state_change', (data) => {
if (data.reason !== 3) return
gameMode = data.gameMode
})
target.on('login', (data) => {
gameMode = data.gameMode
})
const interval = setInterval(() => {
if (bot.options.kaboom) {
if (!op && config.self_care.op) target.chat('/minecraft:op @s[type=player]')
if (!cspy && config.self_care.cspy) target.chat('/commandspy:commandspy on')
}
if (gameMode !== 1 && config.self_care.gamemode) target.chat('/minecraft:gamemode creative @s[type=player]')
}, config.self_care_check_interval)
bot.on('end', () => {
clearInterval(interval)
})
};
module.exports = { inject }

View file

@ -8,16 +8,20 @@ const path = require('path')
* @param {object} bot the bot object
* @param {object} dcclient discord client
* @param {object} config the config
* @param {object} rl readline.
* @param {object} rl readline
* @param {object} target proxy target
* @param {object} client proxy client
* @param {boolean} proxy is proxy
*/
async function loadPlugins (bot, dcclient, config, rl) {
const dir = path.join(__dirname, '..', 'plugins')
async function loadPlugins (bot, dcclient, config, rl, target, client, proxy) {
const dir = path.join(__dirname, '..', 'plugins', proxy ? 'proxy' : '')
const plugins = await fs.readdir(dir)
plugins.forEach((plugin) => {
if (!plugin.endsWith('.js')) return
try {
const plug = require(path.join(dir, plugin))
plug.inject(bot, dcclient, config, rl)
if (!proxy) plug.inject(bot, dcclient, config, rl)
else plug.inject(bot, client, target, config)
} catch (e) {
console.log(`Plugin ${plugin} is having exception loading the plugin:`)
console.log(util.inspect(e))