-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfeeder.js
169 lines (110 loc) · 3.34 KB
/
feeder.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
'use strict'
////////////////////////////////////////////////////////////
// //
// Feeder/server/userscript by l3mpik //
///////////////////////////////////////////////////////////
const Bot = require('./dist');
const express = require('express');
const app = express();
const fs = require('fs');
const path = require('path');
const socket = require('socket.io-client')('ws://127.0.0.1:4000');
process.on('uncaughtException', function(err) {})
let proxies = fs
.readFileSync(path.join(__dirname, 'proxies.txt'))
.toString()
.split(/\r?\n/)
.filter(function(line) {
return line.length > 0
});
let server = '';
let b_name = '';
let skin = '';
let alive = 0;
let gX = 0;
let gY = 0;
let perProxy = 2;
const bots = [];
function spawn() {
bots.forEach(function(bot) {
bot.close()
console.log('Bot disconnect!');
});
alive = 0;
socket.emit('bcount', alive);
setTimeout(function() {
proxies.forEach(function(proxy, pidx) {
for (let i = 0; i < perProxy; i++) {
const bot = new Bot({
name: b_name,
reconnect: true,
skin: skin,
server: server
})
bot.on('position', function(position, snake) {
snake.facePosition(gX, gY);
})
bot.on('spawn', function() {
alive++;
socket.emit('bcount', alive);
console.log('Available proxy: ' + proxies.length + '\n Chance to spawn max: ' + proxies.length * perProxy + ' bots' + ' Now: ' + alive + '\n\n\n\n\n\n\n\n\n\n\n');
})
bot.on('dead', function() {
alive--;
socket.emit('bcount', alive);
console.log('Available proxy: ' + proxies.length + '\n Chance to spawn max: ' + proxies.length * perProxy + ' bots' + ' Now: ' + alive + '\n\n\n\n\n\n\n\n\n\n\n');
})
bot.on('disconnect', function() {
alive--;
socket.emit('bcount', alive);
console.log('Available proxy: ' + proxies.length + '\n Chance to spawn max: ' + proxies.length * perProxy + ' bots' + ' Now: ' + alive + '\n\n\n\n\n\n\n\n\n\n\n');
})
bots.push(bot)
bot.connect(proxy);
}
})
}, 1000);
}
socket.on('pos', function(xx, yy) {
gX = xx;
gY = yy;
});
socket.on('cmd', function(c) {
bots.forEach(function(bot) {
const snake = bot.me()
if (bot.connected && snake) {
snake.toggleSpeeding(c === 'on')
}
})
});
function r_skin(){
setInterval(function(){
i++;
skin = i;
if(i == 39) {
i = 0;
}
},200);
}
socket.on('server', function(data) {
server = data[0];
b_name = data[1];
if (data[2] == -1) {
skin = r_skin();
} else {
skin = data[2];
}
spawn();
});
socket.on('cmd', function(ss) {
if (ss == 1) {
bots.forEach(function(bot) {
const snake = bot.me()
if (bot.connected && snake) {
snake.toggleSpeeding(c === 'on');
}
});
}
});
console.log('Waiting for client!');
app.listen(3000)