This repository was archived by the owner on Jan 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathlvlgen.js
256 lines (224 loc) · 9.35 KB
/
lvlgen.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// Made by Cr4xy - Helped by MastaCoder :)
// https://www.youtube.com/channel/UC1CJCNc6rrtjJzxiqYN97aQ - Support Cr4xy's YouTube!
var agarClient = require("agario-client");
config = require("./config.js"),
token = null,
account = new agarClient.Account(),
STATIC_NAME = config.name,
debugObj = {},
regions = config.regions,
DefaultAi = new(require("./ai/default_ai.js")),
AposAi = new(require("./ai/apos_ai.js"));
var fs = require('fs');
var VERSION = 0.971;
var currentSeconds = 0; // Starts at 0
var accountIndex = 0; // Gives number to each token and account.
var accountCount = 0; // Gives number of attempted accounts.
var regionCounter = 0; // Give number to each region.
var requestTries = 0; // Requests to get the server tokens.
var realHighest = []; // Real highest score caught.
Array.prototype.contains = function(element) {
return this.indexOf(element) >= 0;
}
Array.prototype.add = Array.prototype.push;
Array.prototype.remove = function(element) {
if (this.contains(element)) this.splice(this.indexOf(element), 1);
}
function getCurrentDate() {
var dr = new Date();
return dr.getFullYear() + "-" + dr.getMonth() + "-" + dr.getDate() + " | " + dr.getHours() + ":" + dr.getMinutes() + ":" + dr.getSeconds();
}
// Check if no region is enabled
!function() {
if (config.regions.length > 0) return;
console.log("[warning] No region enabled or found!");
process.exit();
}();
// Check for updates
! function() {
require("https").get('https://raw.githubusercontent.com/Cr4xy/agar-lvlgen/master/version', function(res) {
res.on('data', function(bytes) {
var fetched_version = bytes.toString();
if (config.logging) {
fs.appendFileSync('log.txt', "[" + getCurrentDate() + "] *** AGAR-LVLGEN STARTED *** \r\n", encoding = 'utf8');
}
console.log("\u001B[31m\n########################");
console.log("\u001B[32m _ _ _ ____");
console.log(" / \\ __ _ __ _ _ __ | | __ _| |/ ___| ___ _ __");
console.log(" / _ \\ / _` |/ _` | '__|____| | \\ \\ / / | | _ / _ \\ '_ \\ ");
console.log(" / ___ \\ (_| | (_| | | |_____| |__\\ V /| | |_| | __/ | | |");
console.log("/_/ \\_\\__, |\\__,_|_| |_____\\_/ |_|\\____|\\___|_| |_|");
console.log(" |___/ \u001B[33m- Open Source Agar.io Level Farming! \u001B[0m\n");
if (!isNaN(fetched_version) && isFinite(fetched_version)) {
if (VERSION < fetched_version) {
console.log("Running version: " + VERSION + " (New version " + fetched_version + " found, download off agar-lvlgen Github repo)");
console.log("https://github.com/Cr4xy/agar-lvlgen");
} else {
console.log("Running version: " + VERSION + " (Latest)");
console.log("\u001B[37mPlease DO NOT use \u001B[33magar-lvlgen\u001B[0m at the moment due the risk of getting \u001B[31mbanned\u001B[0m. :(");
setTimeout(process.exit, 60000);
}
} else {
console.log("Running version: " + VERSION + " (Failed to fetch)");
}
//console.log("Will reset in: " + config.reset + " minutes")
console.log("\n\u001B[31m########################\u001B[0m\n");
});
});
}();
return;
function getRegion() {
regionCounter++;
if (regionCounter >= regions.length) regionCounter = 0;
return regions[regionCounter];
}
function getServerOptions() {
return {
region: getRegion()
};
}
function requestToken(c_user, datr, xs) {
account.c_user = c_user || config.accounts[accountIndex].c_user;
account.datr = datr || config.accounts[accountIndex].datr;
account.xs = xs || config.accounts[accountIndex].xs;
account.requestFBToken(function(token, info) {
if (!token) {
if (requestTries++ >= 5) {
accountCount++;
console.log("[ac" + accountCount + "] Token Failed: Token failed after multiple tries.");
process.exit();
}
console.log("[ac" + accountCount + "] Token Failed: Token failed after " + requestTries + " tries, will try again.");
requestToken();
} else {
accountCount++;
if (config.showtoken) {
console.log("[ac" + accountCount + "] Token Success: ", token);
} else {
console.log("[ac" + accountCount + "] Token Success: Token Hidden!");
}
agarClient.servers.getFFAServer(getServerOptions(), function(e) {
var server = e.server;
var key = e.key;
start(server, key, token, account);
});
requestTries = 0;
}
});
}
// Get token & server, then start
! function getTokenAndServer() {
setTimeout(function() {
requestToken();
}, 500);
accountIndex++;
if (accountIndex >= config.accounts.length) {
accountIndex = 0;
return;
}
getTokenAndServer();
}();
var clientIdCounter = 0;
var bots = [];
function start(server, key, token, acc) {
var myClient = new agarClient("Client_" + clientIdCounter++);
myClient.debug = 0;
myClient.auth_token = token;
var myBotObj = {
spawned: false,
client: myClient,
account: acc
};
myClient.on('disconnect', function() {
bots.remove(myBotObj);
clearInterval(myClient.sendInterval);
myClient = null;
});
myClient.on('packetError', function(packet, error, preventCrash) {
preventCrash();
});
myClient.on('connected', function() {
bots.add(myBotObj);
myClient.spawn(STATIC_NAME);
myClient.sendInterval = setInterval(function() {
if (config.ai == "default") {
DefaultAi.update(myClient);
} else {
if (myClient.my_balls.length == 0) return;
var myBalls = [];
for (var i in myClient.my_balls) myClient.balls[myClient.my_balls[i]] && (myBalls.push(myClient.balls[myClient.my_balls[i]]));
AposAi.setPlayer(myBalls);
AposAi.setMemoryCells(myClient.balls);
var destination = AposAi.mainLoop(myClient.balls);
//console.log(destination);
myClient.moveTo(destination[0], destination[1]);
}
}, 40);
});
myClient.on('myNewBall', function() {
myBotObj.spawned = true;
});
myClient.on('lostMyBalls', function() {
myBotObj.spawned = false;
myClient.spawn(STATIC_NAME);
});
myClient.connect("ws://" + server, key);
}
setInterval(function() {
for (var i = 0; i < bots.length; i++) {
var acc = bots[i].account;
if (Date.now() > acc.token_expire) {
requestToken(acc.c_user, acc.datr, acc.xs)
bots.remove(bots[i]);
}
}
}, 10000);
setInterval(function() {
currentSeconds++;
var totalScore = 0;
var spawnedCount = 0;
for (var i = 0; i < bots.length; i++) {
bots[i].spawned && (spawnedCount++, totalScore += bots[i].client.score);
if (bots[i].client.score >= realHighest[i]) {
realHighest[i] = bots[i].client.score;
} else {
if (realHighest[i]) fs.appendFileSync('log.txt', "[" + getCurrentDate() + "] Bot " + i + " has died with " + realHighest[i] + " mass!\r\n", encoding = 'utf8');
realHighest[i] = 0;
}
}
var avgScore = parseInt((totalScore / Math.max(1, spawnedCount)).toFixed(0));
if (config.reset > 0) {
var inSeconds = config.reset * 60;
if (currentSeconds >= inSeconds && avgScore < 100) {
if (config.logging) fs.appendFileSync('log.txt', "[" + getCurrentDate() + "] *** SERVER RESTARTING ***", encoding = 'utf8');
process.exit();
}
}
}, 1000);
setTimeout(function() {
console.log(" ");
// Live console developed by MastaCoder!
if (config.liveConsole) {
console.log("\u001B[33mLive Console: \u001B[0m");
console.log("---------------------------------------------------------------------")
}
}, config.statusDelay - 0.001);
setInterval(function() {
var totalScore = 0;
var spawnedCount = 0;
var highestScore = 0;
for (var i = 0; i < bots.length; i++) bots[i].spawned && (spawnedCount++, totalScore += bots[i].client.score, highestScore = Math.max(highestScore, bots[i].client.score));
var avgScore = parseInt((totalScore / Math.max(1, spawnedCount)).toFixed(0));
debugObj.connected = bots.length;
debugObj.spawned = spawnedCount;
debugObj.totalScore = totalScore;
debugObj.avgScore = avgScore;
debugObj.highest = highestScore;
debugObj.time = currentSeconds;
// Live console developed by MastaCoder! (simplified by SALVATION)
if (config.liveConsole) {
process.stdout.write("\033[K\rSpawned: " + spawnedCount + " | Total: " + totalScore + " | Average: " + avgScore + " | Highest: " + highestScore + " | Time: " + currentSeconds);
} else {
console.log(debugObj);
}
}, config.statusDelay);