-
Notifications
You must be signed in to change notification settings - Fork 6
/
bots.js
135 lines (132 loc) · 4.6 KB
/
bots.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
const WebSocket = require('ws');
const io = require('socket.io')(8080);
const socks = require('socks');
const fs = require('fs');
const Packets = require('./packets');
let bots = [];
const socksList = fs.readFileSync('./socks_checker/socks.txt', 'utf8').trim().split('\n');
const data = {
origin: '',
serverIP: '',
mouseX: 0,
mouseY: 0
};
io.on('connection', socket => {
console.log('[SERVER]: Connected!');
socket.on('start', (origin, ip) => {
data.origin = origin;
data.serverIP = ip;
if(data.origin === 'http://agar.red' || data.origin === 'http://agar.pro'){
let id = 0;
setInterval(() => {
if(id < socksList.length){
bots.push(new Bot(id));
id++;
}
}, 300);
}
else for(const id in socksList) bots.push(new Bot(id));
console.log('[SERVER]: Bots started!');
});
socket.on('stop', () => {
for(const i in bots) bots[i].ws.close();
bots = [];
console.log('[SERVER]: Bots stopped!');
});
socket.on('mouse', (x, y) => {
data.mouseX = x;
data.mouseY = y;
});
socket.on('split', () => {
for(const i in bots) bots[i].send(new Buffer([17]));
});
socket.on('eject', () => {
for(const i in bots) bots[i].send(new Buffer([21]));
});
socket.on('disconnect', () => {
console.log('[SERVER]: Disconnected!');
});
});
class Bot extends Packets {
constructor(id){
super();
this.id = id;
this.name = `NEL99#${this.id}`;
this.ws = null;
this.headers = {
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'ca-ES,ca;q=0.9,en;q=0.8,es;q=0.7,ig;q=0.6',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36'
};
if(data.origin === 'http://agar.red') this.headers['Cache-Control'] = 'no-cache';
this.sock = socksList[this.id].split(':');
this.agent = new socks.Agent({
proxy: {
ipaddress: this.sock[0],
port: Number(this.sock[1]),
type: 5
}
});
this.minX = 0;
this.minY = 0;
this.maxX = 0;
this.maxY = 0;
this.offsetX = 0;
this.offsetY = 0;
this.connectionAttempts = 0;
this.connect();
}
connect(){
this.ws = new WebSocket(data.serverIP, {
origin: data.origin,
headers: this.headers,
agent: this.agent
});
this.ws.binaryType = 'nodebuffer';
this.ws.onopen = this.onopen.bind(this);
this.ws.onmessage = this.onmessage.bind(this);
this.ws.onerror = this.onerror.bind(this);
this.ws.onclose = this.onclose.bind(this);
}
send(buffer){
if(this.ws.readyState === WebSocket.OPEN) this.ws.send(buffer);
}
onopen(){
this.send(this[data.origin]().handshakeProtocol);
this.send(this[data.origin]().handshakeKey);
if(this[data.origin]().ping && this[data.origin]().pingTime){
setInterval(function(){
this.send(this[data.origin]().ping);
}.bind(this), this[data.origin]().pingTime);
}
setInterval(function(){
this.send(this[data.origin]().spawn(this.name));
}.bind(this), 1000);
setInterval(function(){
this.send(this[data.origin]().move(data.mouseX + this.offsetX, data.mouseY + this.offsetY));
}.bind(this), 100);
if(process.argv[2] === '--verbose') console.log(`[Bot#${this.id}]: Connection opened`);
}
onmessage(message){
const msg = new Buffer(message.data);
if(data.origin === 'http://agar.pro'){
if(msg.readUInt8(0) === 64 && msg.byteLength === 33){
this.minX = msg.readDoubleLE(1);
this.minY = msg.readDoubleLE(9);
this.maxX = msg.readDoubleLE(17);
this.maxY = msg.readDoubleLE(25);
this.offsetX = (this.minX + this.maxX) / 2;
this.offsetY = (this.minY + this.maxY) / 2;
}
}
}
onerror(err){
this.connectionAttempts++;
if(this.connectionAttempts === 3) this.ws.close();
else this.connect();
if(process.argv[2] === '--verbose') console.log(`[Bot#${this.id}]: Connection error: ${err}`);
}
onclose(e){
if(process.argv[2] === '--verbose') console.log(`[Bot#${this.id}]: Connection closed: ${e.reason ? e.reason : e.code ? e.code : e}`);
}
}