2022-08-14 05:51:45 -04:00
|
|
|
/* eslint-disable max-len */
|
|
|
|
/* eslint-disable no-var */
|
|
|
|
const readline = require('node:readline');
|
|
|
|
const {stdin: input, stdout: output} = require('node:process');
|
|
|
|
const rl = readline.createInterface({input, output});
|
|
|
|
const process = require('child_process');
|
2022-08-18 22:36:34 -04:00
|
|
|
const config = require('./config');
|
2022-08-14 05:51:45 -04:00
|
|
|
require('./uptime');
|
|
|
|
|
2022-08-18 07:02:14 -04:00
|
|
|
rl.setMaxListeners(Infinity);
|
|
|
|
|
2022-08-14 05:51:45 -04:00
|
|
|
const bots = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the start function
|
|
|
|
* @param {String} host
|
|
|
|
* @param {Number} port
|
|
|
|
*/
|
|
|
|
function start(host, port) {
|
|
|
|
const server = host;
|
|
|
|
let theServer;
|
|
|
|
bots[server] = process.exec('node index.js ' + host);
|
|
|
|
if (host=='sus.shhnowisnottheti.me') {
|
|
|
|
theServer = 'ayunboom';
|
|
|
|
}
|
|
|
|
if (host=='129.159.58.114') {
|
|
|
|
theServer = 'dinboom';
|
|
|
|
}
|
|
|
|
if (host=='play.kaboom.pw') {
|
|
|
|
theServer = 'kaboom';
|
|
|
|
}
|
|
|
|
if (host=='192.168.1.103') {
|
|
|
|
theServer = 'local';
|
|
|
|
}
|
|
|
|
if (host=='kitsune.icu') {
|
|
|
|
theServer = 'kitsune';
|
|
|
|
}
|
2022-08-20 04:20:04 -04:00
|
|
|
if (host=='mc.chomens41793.ga') {
|
|
|
|
theServer = 'chomens';
|
|
|
|
}
|
2022-08-14 05:51:45 -04:00
|
|
|
eval(`${theServer} = []`);
|
|
|
|
eval(`${theServer}loop = setInterval(() => {
|
|
|
|
if (${theServer}[0]) {
|
|
|
|
bots[server].stdin.write(${theServer}.at(0) + '\\n');
|
|
|
|
${theServer} = [];
|
|
|
|
}
|
|
|
|
}, 0)`);
|
|
|
|
bots[server].on('close', function() {
|
|
|
|
bots[server].kill();
|
|
|
|
eval(`clearInterval(${theServer}loop)`);
|
|
|
|
start(server);
|
|
|
|
});
|
|
|
|
bots[server].stdout.on('data', function(chunk) {
|
|
|
|
rl.output.write('\x1b[2K\r');
|
|
|
|
require('process').stdout.write(`${chunk}`);
|
|
|
|
rl._refreshLine();
|
|
|
|
});
|
|
|
|
rl.on('line', (line) => {
|
|
|
|
if (line.startsWith('/send ')) {
|
|
|
|
try {
|
|
|
|
const args = line.substring(1).trim().split(' ');
|
|
|
|
eval(`${args.at(1)}.push(args.slice(2).join(' ').toString())`);
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Invalid.');
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bots[server].stdin.write(line + '\n');
|
|
|
|
require('process').on('SIGINT', () => {
|
|
|
|
bots[server].kill();
|
|
|
|
require('process').exit();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const server of config.servers) {
|
|
|
|
start(server.host, server.port);
|
|
|
|
}
|