Advertisement
optimusprimeagario

LOL

Mar 13th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.64 KB | None | 0 0
  1. /*
  2. O Código foi editado(melhorado) por Break Agar (Original agar-feeder)
  3.  
  4. var BreakBotCriado = ('Novo Bot Gerado!') //MSG QUE APARECE NO CMD AO GERAR BOT (VAR)
  5. function BreakBotStart(alert) {
  6. AlertBotStart = start_id; //Mensagem Quando Startar o bot!
  7. start_id = ('Bot Iniciado!');
  8. }
  9. function BreakBotStop(alert) {
  10. AlertBotStop = stop_id; //Mensagem Quando Parar Os Bots!
  11. stop_id = ('Bot Parado!');
  12.  
  13. }
  14. var DomineBot_config = require('./domine.config'); //Acess To Control
  15. var EditAcess = require('./acess.edit');
  16.  
  17. var BreakBot = bot.js;
  18.  
  19. if bot.js = true {
  20. console.log('Bot Configurado');
  21. new DomineBot_config botMass = botsMassBoost;
  22. }
  23. function botsMassBoost = (value = 132) {
  24. //Código em manuntenção , ao fazer login com facebook do código
  25. var facebook.login = username_login;
  26. var facebook.password = password_login;
  27. var completo = facebook.login + facebook.password (null)
  28.  
  29. if (completo = true (BreakBotStart (alert) );
  30.  
  31. }
  32.  
  33. */
  34. //A SEGUIR VEJA UM SCRIPT EDITADO DO FEEDER!
  35.  
  36. var fs = require('fs-extra');
  37. var path = require('path');
  38.  
  39. if (!fs.existsSync('proxy.txt')) {
  40. console.log("INFO: did not found proxy.txt - creating it.");
  41. fs.copySync(path.resolve(__dirname,'./proxy.sample.txt'), 'proxy.txt');
  42. }
  43.  
  44. if (!fs.existsSync('config.js')) {
  45. console.log("INFO: did not found config.js - creating it.");
  46. fs.copySync(path.resolve(__dirname,'./config.sample.js'), 'config.js');
  47. }
  48.  
  49. var config = require('./config');
  50. var names = require('./names');
  51.  
  52. var AgarioClient = require('agario-client'); //Use this in your scripts
  53. spawnCount = 0;
  54.  
  55. function FeederBot(bot_id, agent, bot_number, server) {
  56. this.bot_id = bot_id; //ID of bot for logging
  57.  
  58. if (config.useRandomSkinName) {
  59. this.nickname = names.getRandomName();
  60. } else {
  61. this.nickname = config.useStaticName;
  62. }
  63.  
  64. this.interval_id = 0; //here we will store setInterval's ID
  65. this.ball_id = null;
  66. this.server = ''; //server address will be stored here
  67. this.client = new AgarioClient('Bot_' + this.bot_id); //creates new client
  68. this.client.debug = 0;
  69. this.client.agent = agent;
  70. this.client.auth_token = auth_token;
  71. this.client.headers['user-agent'] = config.userAgent;
  72. this.isOnFeedMission = false;
  73. this.onboard_client(server, bot_number)
  74. }
  75.  
  76. FeederBot.prototype = {
  77. log: function(text) {
  78. if (config.verbosityLevel > 0) {
  79. console.log('Bot_' + this.bot_id + ': ' + text);
  80. }
  81. },
  82.  
  83. onboard_client: function(server, bot_number) {
  84. var bot = this;
  85. setTimeout(function() {
  86. bot.connect(server);
  87. }, config.onboardingTimer * bot_number);
  88. },
  89.  
  90. connect: function(server) {
  91. if (config.verbosityLevel > 0) {
  92. this.log('Connecting to: ' + server);
  93. }
  94.  
  95. if (spawnCount > config.maxBots) {
  96. this.log('ERROR: spawned to many bots - Increase config.maxBots for more bots.');
  97. return;
  98. }
  99.  
  100. this.server = server;
  101. this.client.connect(server);
  102. this.attachEvents();
  103. },
  104.  
  105. attachEvents: function() {
  106. var bot = this;
  107.  
  108. bot.client.on('connected', function() {
  109. if (config.verbosityLevel > 0) {
  110. bot.log('Connection Success, spawning');
  111. }
  112. bot.client.spawn(bot.nickname);
  113. spawnCount++;
  114. socket.emit("spawn-count", spawnCount + '/' + config.maxBots);
  115. //we will search for target to eat every 100ms
  116. bot.interval_id = setInterval(function() {
  117. bot.recalculateTarget()
  118. }, 100);
  119. });
  120.  
  121. bot.client.on('connectionError', function(e) {
  122. if (config.verbosityLevel > 0) {
  123. bot.log('Connection Failed: ' + e);
  124. }
  125. });
  126.  
  127. bot.client.on('myNewBall', function(ball_id) {
  128. // Should always be generated.
  129. if (config.verbosityLevel > -1) {
  130. bot.log('New Cell Generated (' + ball_id + ')');
  131. }
  132. });
  133.  
  134. bot.client.once('leaderBoardUpdate', function(old, leaders) {
  135. var name_array = leaders.map(function(ball_id) {
  136. return bot.client.balls[ball_id].name || 'unnamed'
  137. });
  138. if (config.verbosityLevel > 0) {
  139. bot.log('Server Leaderboard: ' + name_array.join(' - '));
  140. }
  141. });
  142.  
  143. bot.client.on('somebodyAteSomething', function(eater_ball, eaten_ball) {
  144. var ball = bot.client.balls[eater_ball];
  145. if (!ball) return; //if we don't know that ball, we don't care
  146. if (!ball.mine) return; //if it's not our ball, we don't care
  147. //bot.client.log('I ate ' + eaten_ball + ', my new size is ' + ball.size);
  148. });
  149.  
  150. bot.client.on('mineBallDestroy', function(ball_id, reason) { //when my ball destroyed
  151. if (reason.by) {
  152. if (config.verbosityLevel > 0) {
  153. bot.log(bot.client.balls[reason.by] + ' has killed a cell.');
  154. }
  155. }
  156.  
  157. if (reason.reason == 'merge') {
  158. if (config.verbosityLevel > 1) {
  159. bot.log('Merged with another cell. Bot_' + ball_id + ' now has ' + bot.client.my_balls.length + ' balls.')
  160. }
  161. } else {
  162. if (config.verbosityLevel > 1) {
  163. bot.log('Lost a cell! Bot_' + ball_id + ' has ' + bot.client.my_balls.length + ' cells left.');
  164. }
  165. }
  166. });
  167.  
  168. bot.client.on('lostMyBalls', function() {
  169. if (config.verbosityLevel > 0) {
  170. bot.log('Has been killed, respawning.');
  171. }
  172. bot.client.spawn(bot.nickname);
  173. bot.isOnFeedMission = false;
  174. });
  175.  
  176. bot.client.on('disconnect', function() {
  177. if (config.verbosityLevel > 0) {
  178. bot.log('Disconnected from the server.');
  179. }
  180. if (spawnCount > 0){ spawnCount--;}
  181. socket.emit("spawn-count", spawnCount + '/' + config.maxBots);
  182. });
  183.  
  184. bot.client.on('reset', function() { //when client clears everything (connection lost?)
  185. clearInterval(bot.interval_id);
  186. });
  187.  
  188. bot.client.on('packetError', function(packet, err, preventCrash) {
  189. bot.log('Packet error detected for packet: ' + packet.toString());
  190. bot.log('Crash will be prevented, bot will be disconnected');
  191. preventCrash();
  192. bot.client.disconnect();
  193. });
  194. },
  195.  
  196. getDistanceBetweenBalls: function(ball_1, ball_2) {
  197. return this.getDistanceBetweenBallAndPosition(ball_1, ball_2.x, ball_2.y);
  198. },
  199.  
  200. getDistanceBetweenBallAndPosition: function(ball_1, x, y) {
  201. return this.getDistanceBetweenPositions(ball_1.x, ball_1.y, x, y);
  202. },
  203.  
  204. getDistanceBetweenPositions: function(x1, y1, x2, y2) {
  205. return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y1 - y2, 2));
  206. },
  207.  
  208. getAvailableTransporter: function() {
  209. var bot = this;
  210. var my_ball = bot.client.balls[bot.client.my_balls[0]];
  211. if (!my_ball) return;
  212.  
  213. possible_transporter = null
  214.  
  215. for (var bot_id in bots) {
  216. ball_id = bots[bot_id].id
  217. bot_ball = bots[bot_id].client.balls[bots[bot_id].client.my_balls[0]];
  218. if (!bot_ball) continue;
  219. if (bot.getDistanceBetweenBallAndPosition(my_ball, bot_ball.x, bot_ball.y) > 2000) {
  220. continue;
  221. }
  222. if (bot.getDistanceBetweenBallAndPosition(my_ball, bot_ball) > bot.getDistanceBetweenBallAndPosition(my_ball, possible_transporter)) {
  223. continue;
  224. }
  225. if (my_ball.size / bot_ball.size > 0.8) continue;
  226.  
  227. possible_transporter = bot_ball;
  228. }
  229.  
  230. return possible_transporter;
  231. },
  232.  
  233. getMassPixelRadius: function(mass) {
  234. return Math.ceil(Math.sqrt(100 * mass));
  235. },
  236.  
  237. canSplitFeedPlayer: function(botMass, otherMass) {
  238. requiredMass = otherMass * 1.25;
  239. return requiredMass < botMass
  240. },
  241.  
  242. playerInRange: function(my_ball, playerX, playerY, playerSize, range) {
  243. var bot = this;
  244. bot_distance = bot.getDistanceBetweenBallAndPosition(my_ball, playerX, playerY) - bot.getMassPixelRadius(bot.client.balls[player_cell_id].size)
  245. ditance_needed = range //400 - bot.getMassPixelRadius(my_ball.size);
  246. return bot_distance < ditance_needed;
  247. },
  248.  
  249. in_circle: function(center_x, center_y, radius, x, y) {
  250. //square_dist = (center_x - x) ^ 2 + (center_y - y) ^ 2;
  251. //return square_dist <= (radius/2) ^ 2;
  252. dx = x - center_x
  253. dy = y - center_y
  254. return dx * dx + dy * dy <= radius * radius
  255. },
  256.  
  257. getCoordinatesOfCircleAngle: function(center_x, center_y, radius, angle) {
  258. x = Math.ceil(center_x + radius * Math.cos(angle));
  259. y = Math.ceil(center_y + radius * Math.sin(angle));
  260. return {
  261. "x": x,
  262. "y": y
  263. };
  264. },
  265.  
  266. checkIfPathCrossesBall: function(from_x, from_y, dest_x, dest_y, ball_id) {
  267. bot = this;
  268. ball = bot.client.balls[ball_id];
  269.  
  270. // Translate coordinates
  271. var x1 = Math.ceil(from_x);
  272. var y1 = Math.ceil(from_y);
  273. var x2 = Math.ceil(dest_x);
  274. var y2 = Math.ceil(dest_y);
  275. // Define differences and error check
  276. var dx = Math.abs(x2 - x1);
  277. var dy = Math.abs(y2 - y1);
  278. var sx = (x1 < x2) ? 1 : -1;
  279. var sy = (y1 < y2) ? 1 : -1;
  280. var err = dx - dy;
  281. // Main loop
  282. while (!((x1 == x2) && (y1 == y2))) {
  283. var e2 = err << 1;
  284. if (e2 > -dy) {
  285. err -= dy;
  286. x1 += sx;
  287. }
  288. if (e2 < dx) {
  289. err += dx;
  290. y1 += sy;
  291. }
  292.  
  293. if (bot.in_circle(ball.x, ball.y, bot.getMassPixelRadius(ball.mass), x1, y1)) {
  294. return true;
  295. }
  296. }
  297. // Return the result
  298. return false;
  299. },
  300.  
  301. getNearestBallOnPath: function(from_x, from_y, dest_x, dest_y) {
  302. bot = this;
  303. my_ball = bot.client.balls[bot.client.my_balls[0]];
  304.  
  305. for (ball_id in bot.client.balls) {
  306. ball = bot.client.balls[ball_id];
  307. if (!ball.virus) {
  308. continue;
  309. }
  310.  
  311. if (bot.checkIfPathCrossesBall(from_x, from_y, dest_x, dest_y, ball_id)) {
  312. console.log("Path not safe: bot would die!");
  313. return ball_id;
  314. }
  315. }
  316.  
  317. return null;
  318. },
  319.  
  320. safeMoveTo: function(x, y) {
  321. bot = this;
  322. my_ball = bot.client.balls[bot.client.my_balls[0]];
  323.  
  324. safeX = x;
  325. safeY = y;
  326.  
  327. nearest_obstacle = bot.getNearestBallOnPath(my_ball.x, my_ball.y, x, y);
  328.  
  329. if (nearest_obstacle != null) {
  330. ball = bot.client.balls[nearest_obstacle];
  331. bestXDistance = 99999999;
  332. bestX = 0;
  333. bestY = 0;
  334.  
  335. for (var i = 0; i < 360; i = i + 16) {
  336. pos = bot.getCoordinatesOfCircleAngle(ball.x, ball.y, bot.getMassPixelRadius(ball.mass) + bot.getMassPixelRadius(my_ball.mass), i)
  337. test_path = bot.getNearestBallOnPath(pos.x, pos.y, my_ball.x, my_ball.y);
  338. test_path2 = bot.getNearestBallOnPath(pos.x, pos.y, x, y);
  339.  
  340. if (test_path == null && test_path2 == null) {
  341. console.log("this path is safe.")
  342.  
  343. distance1 = bot.getDistanceBetweenPositions(pos.x, pos.y, my_ball.x, my_ball.y);
  344. distance2 = bot.getDistanceBetweenPositions(pos.x, pos.y, x, y);
  345. totalDistance = distance1 + distance2;
  346. if (totalDistance < bestXDistance) {
  347. bestXDistance = totalDistance;
  348. bestX = pos.x;
  349. bestY = pos.y;
  350. console.log("found safe spot!");
  351. }
  352. } else {
  353. console.log("pathfinding: this path is not safe.")
  354. }
  355. }
  356.  
  357. if (bestX == 0 && bestY == 0) {
  358. console.log("pathfinding: impossible.")
  359. return;
  360. } else {
  361. safeX = bestX;
  362. safeY = bestY;
  363. }
  364.  
  365. console.log("pathfinding done:")
  366. console.log(safeX)
  367. console.log(safeY)
  368. }
  369.  
  370. bot.client.moveTo(safeX, safeY);
  371. },
  372.  
  373. recalculateTarget: function() {
  374. var bot = this;
  375. var candidate_ball = null;
  376. var candidate_distance = 0;
  377. var my_ball = bot.client.balls[bot.client.my_balls[0]];
  378. var player_ball = bot.client.balls[player_cell_id];
  379. if (!my_ball) return;
  380. if (!player_ball)
  381. {
  382. bot.client.moveTo(9658, -1843);
  383. return;
  384. }
  385.  
  386. if (bot.isOnFeedMission) {
  387.  
  388. bot.client.moveTo(9658, -1843);
  389.  
  390. return;
  391. }
  392.  
  393. if (my_ball.mass > config.minimumMassBeforeFeed) {
  394. bot.isOnFeedMission = true;
  395. return;
  396. }
  397.  
  398. if (candidate_ball == null) {
  399. //console.log("normal move");
  400. bot.client.moveTo(9658, -1843);
  401. } else {
  402. //console.log("normal move");
  403. bot.client.moveTo(9658, -1843);
  404. }
  405.  
  406. }
  407. };
  408.  
  409. //you can do this in your code to use bot as lib
  410. //module.exports = ExampleBot;
  411.  
  412. //launching bots below
  413.  
  414. var contains = function(needle) {
  415. // Per spec, the way to identify NaN is that it is not equal to itself
  416. var findNaN = needle !== needle;
  417. var indexOf;
  418.  
  419. if (!findNaN && typeof Array.prototype.indexOf === 'function') {
  420. indexOf = Array.prototype.indexOf;
  421. } else {
  422. indexOf = function(needle) {
  423. var i = -1,
  424. index = -1;
  425.  
  426. for (i = 0; i < this.length; i++) {
  427. var item = this[i];
  428.  
  429. if ((findNaN && item !== item) || item === needle) {
  430. index = i;
  431. break;
  432. }
  433. }
  434. return index;
  435. };
  436. }
  437.  
  438. return indexOf.call(this, needle) > -1;
  439. };
  440.  
  441. var WebSocket = require('ws');
  442. var player_cell_id = null;
  443. var socket = require('socket.io-client')(config.feederServer);
  444.  
  445. socket.on('cellid', function(data) {
  446. player_cell_id = data;
  447. });
  448.  
  449. socket.on('cmd', function(data) {
  450. console.log(data);
  451. if (data.name == "split") {
  452. for (bot in bots) {
  453. bots[bot].client.split();
  454. }
  455. } else if (data.name == "eject") {
  456. for (bot in bots) {
  457. bots[bot].client.eject();
  458. }
  459. } else if (data.name == "connect_server") {
  460. if (data.ip == null) {
  461. return;
  462. }
  463. if (data.ip == "") {
  464. return;
  465. }
  466. for (bot in bots) {
  467. bots[bot].client.disconnect();
  468. }
  469. bots = {};
  470. game_server_ip = data.ip;
  471. console.log("client requested bots on: " + game_server_ip);
  472.  
  473. setTimeout(function() {
  474. startFeederBotOnProxies();
  475. }, 1000);
  476. }
  477. });
  478.  
  479. socket.on('force-login', function(data) {
  480. console.log(data);
  481. if (data == "server-booted-up") {
  482. return;
  483. }
  484. socket.emit("login", {
  485. "uuid": config.client_uuid,
  486. "type": "server"
  487. });
  488. });
  489.  
  490. fs = require('fs');
  491. var HttpsProxyAgent = require('https-proxy-agent');
  492. var Socks = require('socks');
  493.  
  494. function getRandomLine(filename) {
  495. var fs = require('fs');
  496. var lines = fs.readFileSync(filename).toString().split("\n");
  497. line = lines[Math.floor(Math.random() * lines.length)];
  498. return line
  499. }
  500.  
  501. //object of bots
  502. var bots = {};
  503.  
  504. bot_count = 0;
  505.  
  506. var fs = require('fs');
  507. var lines = fs.readFileSync(config.proxies).toString().split("\n");
  508. var url = require('url');
  509. var game_server_ip = null;
  510. var auth_token = null;
  511.  
  512. if (config.useFacebookAuth) {
  513. var account = new AgarioClient.Account();
  514.  
  515. account.c_user = config.account.c_user;
  516. account.datr = config.account.datr;
  517. account.xs = config.account.xs;
  518.  
  519. account.requestFBToken(function(token, info) {
  520. auth_token = token;
  521. });
  522.  
  523. }
  524.  
  525. if (config.account.token != "") {
  526. auth_token = config.account.token;
  527. }
  528.  
  529. function createAgent(ip,type) {
  530.  
  531. data = ip.split(":");
  532.  
  533. return new Socks.Agent({
  534. proxy: {
  535. ipaddress: data[0],
  536. port: parseInt(data[1]),
  537. type: parseInt(type)
  538. }}
  539. );
  540. }
  541.  
  542. var proxy_mode = "HTTP";
  543.  
  544. function startFeederBotOnProxies() {
  545. console.log("Auth_Token: " + auth_token);
  546. for (proxy_line in lines) {
  547.  
  548. if(lines[proxy_line].trim() == "#HTTP"){
  549. proxy_mode = "HTTP";
  550. }else if(lines[proxy_line].trim() == "#SOCKS4"){
  551. proxy_mode = "SOCKS4";
  552. }else if(lines[proxy_line].trim() == "#SOCKS5"){
  553. proxy_mode = "SOCKS5";
  554. }
  555.  
  556. if (lines[proxy_line][0] == "#" || lines[proxy_line].length < 3) {
  557. continue;
  558. }
  559.  
  560. //usefull for testing single proxies
  561. if (process.argv[3] != null && proxy_line != process.argv[3]) {
  562. continue;
  563. }
  564.  
  565. proxy = "http://" + lines[proxy_line];
  566. proxy_single = lines[proxy_line];
  567. console.log(proxy_mode + " ; " + proxy_single);
  568.  
  569. try {
  570.  
  571. var opts = url.parse(proxy);
  572.  
  573. if (proxy != null) {
  574. if(proxy_mode=="HTTP"){
  575. agent = HttpsProxyAgent(opts);
  576. }else if(proxy_mode=="SOCKS4"){
  577. agent = createAgent(lines[proxy_line],4);
  578. }else if(proxy_mode=="SOCKS5"){
  579. agent = createAgent(lines[proxy_line],5);
  580. }
  581.  
  582. } else {
  583. var agent = null;
  584. }
  585.  
  586. if (lines[proxy_line] == "NOPROXY") {
  587. agent = null;
  588. }
  589.  
  590. console.log("Attempting connection to " + game_server_ip);
  591. for (i = 0; i < config.botsPerIp; i++) {
  592. bot_count++;
  593. bots[bot_count] = new FeederBot(bot_count, agent, bot_count, game_server_ip);
  594. }
  595.  
  596. } catch (e) {
  597. console.log('Error occured on startup: ' + e);
  598. }
  599. }
  600. }
  601.  
  602. console.log("Break Bot Start!");
  603. console.log("CTRL + C To Stop Bot");
  604. console.log("By: Break");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement