2024-07-06 11:02:11 -04:00
|
|
|
const m = require("minecraft-protocol")
|
|
|
|
const settings = require("./settings.json")
|
2024-07-19 15:52:38 -04:00
|
|
|
const generateUser = require("./util/usergen.js")
|
2024-07-06 11:02:11 -04:00
|
|
|
const secret = require(settings.secret)
|
|
|
|
const EventEmitter = require("node:events")
|
|
|
|
const crypto = require("crypto")
|
|
|
|
const fs=require("fs")
|
|
|
|
|
|
|
|
module.exports.bot=[];
|
|
|
|
|
|
|
|
const loadplug = (botno) => {
|
|
|
|
const botplug = []
|
|
|
|
const bpl = fs.readdirSync('plugins')
|
|
|
|
for (const i in bpl) {
|
|
|
|
if (!bpl[i].endsWith('.js')) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
botplug.push(require(`./plugins/${bpl[i]}`))
|
|
|
|
} catch (e) { console.log(e) }
|
|
|
|
}
|
|
|
|
botplug.forEach((plug) => {
|
|
|
|
try {
|
|
|
|
if (botno !== undefined) {
|
|
|
|
if (plug.loadBot) {
|
|
|
|
plug.loadBot(module.exports.bot[botno])
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
plug.load()
|
|
|
|
}
|
|
|
|
} catch (e) { console.log(e) }
|
|
|
|
})
|
|
|
|
}
|
|
|
|
loadplug()
|
|
|
|
|
|
|
|
const createBot = function createBot(host,oldId){
|
|
|
|
const bot = new EventEmitter();
|
|
|
|
bot._client = m.createClient({
|
|
|
|
host: host.host,
|
|
|
|
port: host.port ? host.port : 25565,
|
2024-07-21 07:40:31 -04:00
|
|
|
username: generateUser(host.options.legalName),
|
2024-07-06 11:02:11 -04:00
|
|
|
version: settings.version_mc
|
|
|
|
})
|
|
|
|
bot._client.on("success",()=>{
|
|
|
|
//console.log(bot);
|
|
|
|
})
|
|
|
|
if(typeof oldId !== "undefined"){
|
2024-07-17 08:23:06 -04:00
|
|
|
for(const i in module.exports.bot[oldId].interval){
|
|
|
|
clearInterval(module.exports.bot[oldId].interval[i]);
|
|
|
|
}
|
|
|
|
delete module.exports.bot[oldId];
|
2024-07-06 11:02:11 -04:00
|
|
|
bot.id=oldId;
|
|
|
|
module.exports.bot[oldId]=bot;
|
|
|
|
console.log("Re-creating bot "+bot.id)
|
|
|
|
} else {
|
|
|
|
bot.id=module.exports.bot.length;
|
|
|
|
module.exports.bot.push(bot);
|
|
|
|
console.log("Creating bot "+bot.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
bot.host=host;
|
|
|
|
bot.interval={};
|
|
|
|
|
|
|
|
bot.info=(msg)=>{
|
|
|
|
console.log(`[${bot.id}] [info] ${msg}`)
|
|
|
|
}
|
|
|
|
/*bot.error=(msg){
|
|
|
|
console.log(`[${bot.id}] [error] ${msg}`)
|
|
|
|
}*/
|
|
|
|
loadplug(bot.id);
|
|
|
|
bot._client.on("error",(err)=>{
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(const i in settings.servers){
|
|
|
|
createBot(settings.servers[i]);
|
|
|
|
}
|
|
|
|
module.exports.createBot = createBot;
|