-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
137 lines (105 loc) · 5.1 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
██████╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗ ██████╗ ██████╗ ██╗ █████╗ ██╗ ██╗
╚════██╗██╔══██╗██╔═══██╗██╔══██╗██╔════╝██╔══██╗╚════██╗██╔══██╗██║ ██╔══██╗╚██╗ ██╔╝
█████╔╝██████╔╝██║ ██║██████╔╝█████╗ ██║ ██║ █████╔╝██████╔╝██║ ███████║ ╚████╔╝
██╔═══╝ ██╔══██╗██║ ██║██╔══██╗██╔══╝ ██║ ██║██╔═══╝ ██╔═══╝ ██║ ██╔══██║ ╚██╔╝
███████╗██████╔╝╚██████╔╝██║ ██║███████╗██████╔╝███████╗██║ ███████╗██║ ██║ ██║
╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝
A utility created for hosting a proxy to create a stable connection between a server and client
as well as botting and mapping features by
██████ ▓█████ ▄▄▄▄ ▄▄▄ ██████ ▄▄▄█████▓ ██▓ ▄▄▄ ███▄ █
▒██ ▒ ▓█ ▀ ▓█████▄ ▒████▄ ▒██ ▒ ▓ ██▒ ▓▒▓██▒▒████▄ ██ ▀█ █
░ ▓██▄ ▒███ ▒██▒ ▄██▒██ ▀█▄ ░ ▓██▄ ▒ ▓██░ ▒░▒██▒▒██ ▀█▄ ▓██ ▀█ ██▒
▒ ██▒▒▓█ ▄ ▒██░█▀ ░██▄▄▄▄██ ▒ ██▒░ ▓██▓ ░ ░██░░██▄▄▄▄██ ▓██▒ ▐▌██▒
▒██████▒▒░▒████▒░▓█ ▀█▓ ▓█ ▓██▒▒██████▒▒ ▒██▒ ░ ░██░ ▓█ ▓██▒▒██░ ▓██░
▒ ▒▓▒ ▒ ░░░ ▒░ ░░▒▓███▀▒ ▒▒ ▓▒█░▒ ▒▓▒ ▒ ░ ▒ ░░ ░▓ ▒▒ ▓▒█░░ ▒░ ▒ ▒
░ ░▒ ░ ░ ░ ░ ░▒░▒ ░ ▒ ▒▒ ░░ ░▒ ░ ░ ░ ▒ ░ ▒ ▒▒ ░░ ░░ ░ ▒░
░ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ▒ ░ ░ ▒ ░ ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
*/
//Don't stop on error
process.on('uncaughtException', function (err) {
console.log('Caught exception: ', err);
});
//Main Requires
const fs = require('fs');
const path = require('path');
const ini = require('ini');
//These are global because they may need to be accessed often by other modules
global.config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'))
//This is somewhat handy, but bad practice. It allows other modules to run code and return results at this level.
global.rootEval = function(cmd){
var result = eval(cmd);
if(typeof result == 'object') console.log(result); else return(result);
};
//Requires
const colors = require('colors');
const cmd = require('./cmd/cmd.js');
const { fork } = require('child_process');
//Get account information
fs.accessSync("./"+config.proxy.details+".json", fs.constants.R_OK);
var secrets = require('./'+config.proxy.details+'.json');
//Definitions
//Contains reference to the proxy process
var proxy = null;
//Bot process
var bot = null;
function startProxy(){
proxy = fork('./proxy/proxy.js');
proxy.send({name : 'start',config : config,secrets : secrets,});
proxy.on('message',(msg) => {
switch(msg[0]){
case "bot_restart":
if(bot==null){
startBot();
}
if(bot.killed != null && bot.killed!=true){
bot.send({name : 'end'});
}
startBot();
break;
case "bot_end":
if(bot!=null){
bot.send({name : 'end'});
bot.kill();
}
break;
}
});
return('Proxy started!'.lightGreen);
}
function pause_client(id){
proxy.send({
name : "pause",
pause : id,
});
}
function bot_change(aiType){
config.ai.start=aiType;
startBot();
}
function startBot(){
if(bot!=null){
bot.kill();
}
bot = fork('./bot/bot.js');
bot.send({name : 'start',config : config,secrets : secrets,});
bot.on('message',(msg) => {
switch(msg[0]){
case "bot_restart":
startBot();
break;
case "proxy_restart":
proxy.kill();
proxy=null;
bot.kill();
bot=null;
console.log("GLITCH DETECTED, RESTARTING".red);
setTimeout(function(){
startProxy();
},10000);
break;
}
});
return('Bot started!'.lightGreen);
}