Advertisement
MasonBurdette

Untitled

Feb 21st, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 KB | None | 0 0
  1. var AgarioClient = require('agario-client');
  2.  
  3. function getToken() {
  4. var AgarioClient = require('agario-client');
  5.  
  6. var account = new AgarioClient.Account();
  7.  
  8. account.c_user = '100006612392533'; //100011132700068
  9. account.datr = 'LyWcVvCYbzfx0ze9kLUiFFmu'; //hBl-VqyJ2IO37dYyOHQDs4n9
  10. account.xs = '234%3AN4FUWGaXUgKTHw%3A2%3A1453420833%3A18215'; //127:I9OXiLse-vKMDg:2:1452461086:-1
  11.  
  12.  
  13.  
  14. //Request token
  15. account.requestFBToken(function(token, info) {
  16. if(token) {
  17. var miliseconds = ( account.token_expire-(+new Date) )
  18.  
  19. function mToMAS(millis) {
  20. var minutes = Math.floor(millis / 60000);
  21. var seconds = ((millis % 60000) / 1000).toFixed(0);
  22. return minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
  23. }
  24. token1 = token
  25. }else{
  26. console.log('Failed to request Facebook Token!!');
  27. if(info.error) console.log('The request for facebook.com returned: ' + info.error);
  28. if(info.res && info.res.statusCode) console.log('The HTTP Error code is: ' + info.res.statusCode);
  29. if(info.res && info.res.headers && info.res.headers.location) console.log('We got redirected to: ' + info.res.headers.location);
  30. if(info.data) console.log('HTML: ' + info.data);
  31. }
  32. });
  33.  
  34. }
  35. getToken();
  36.  
  37. var region = ['US-Atlanta', 'TK-Turkey', 'SG-Singapore', 'RU-Russia', 'JP-Tokyo', 'EU-London', 'CN-China', 'BR-Brazil']
  38. function ExampleBot(bot_id) {
  39. this.bot_id = bot_id;
  40. this.nickname = 'Trump';
  41. this.verbose = true;
  42. this.interval_id = 0;
  43. this.server = '';
  44. this.server_key = '';
  45. this.client = new AgarioClient('XPBot ' + this.bot_id);
  46. this.client.debug = 1;
  47. this.client.auth_token = token1;
  48. this.retryatempts = 0;
  49. }
  50. ExampleBot.prototype = {
  51. log: function(text) {
  52. if(this.verbose) {
  53. console.log(this.bot_id + ' says: ' + text);
  54. }
  55. },
  56. connect: function(server, key) {
  57. this.server = server;
  58. this.server_key = key;
  59. this.client.connect(server, key);
  60. this.attachEvents();
  61. },
  62. attachEvents: function() {
  63. var bot = this;
  64. bot.client.on('connected', function() {
  65. bot.log('Connected!');
  66. bot.client.spawn(bot.nickname);
  67. bot.interval_id = setInterval (function(){
  68. bot.recalculateTarget()
  69. }, 100);
  70. });
  71. bot.client.on('connectionError', function(e) {
  72. bot.log('Connection failed with reason: ' + e);
  73. bot.log('Server address set to: ' + bot.server + ' key ' + bot.server_key);
  74. });
  75. bot.client.on('packetError', function(packet, err, preventCrash) {
  76. bot.log('Packet error detected for packet: ' + packet.toString());
  77. bot.log('Crash will be prevented, bot will be disconnected');
  78. preventCrash();
  79. bot.disconnect();
  80. });
  81. bot.client.on('myNewBall', function(ball_id) {
  82. bot.log('My new ball ' + ball_id);
  83. });
  84. bot.client.once('leaderBoardUpdate', function(old, leaders) {
  85. var name_array = leaders.map(function(ball_id) {
  86. return bot.client.balls[ball_id].name || 'unnamed'
  87. });
  88. bot.log('Leaders on server: ' + name_array.join(', '));
  89. });
  90. bot.client.on('somebodyAteSomething', function(eater_ball, eaten_ball) {
  91. var ball = bot.client.balls[eater_ball];
  92. if(!ball) return; //if we don't know that ball, we don't care
  93. if(!ball.mine) return; //if it's not our ball, we don't care
  94. bot.client.log('I ate ' + eaten_ball + ', my new size is ' + ball.size);
  95. });
  96. bot.client.on('mineBallDestroy', function(ball_id, reason) { //when my ball destroyed
  97. if(reason.by) {
  98. bot.log(bot.client.balls[reason.by] + ' ate my ball');
  99. }
  100. if(reason.reason == 'merge') {
  101. bot.log('My ball ' + ball_id + ' merged with my other ball, now i have ' + bot.client.my_balls.length + ' balls');
  102. }else{
  103. bot.log('I lost my ball ' + ball_id + ', ' + bot.client.my_balls.length + ' balls left');
  104. }
  105. });
  106. bot.client.on('lostMyBalls', function() {
  107. bot.log('Lost all my balls, respawning');
  108. bot.client.spawn(bot.nickname);
  109. });
  110. bot.client.on('disconnect', function() {
  111. bot.log('Disconnected from server, bye!');
  112. });
  113. bot.client.on('reset', function() { //when client clears everything (connection lost?)
  114. clearInterval(bot.interval_id);
  115. });
  116. },
  117. getDistanceBetweenBalls: function(ball_1, ball_2) {
  118. return Math.sqrt( Math.pow( ball_1.x - ball_2.x, 2) + Math.pow( ball_2.y - ball_1.y, 2) );
  119. },
  120. recalculateTarget: function() {
  121. var bot = this;
  122. var candidate_ball = null;
  123. var candidate_distance = 0;
  124. var my_ball = bot.client.balls[ bot.client.my_balls[0] ];
  125. if(!my_ball) return;
  126. for(var ball_id in bot.client.balls) {
  127. var ball = bot.client.balls[ball_id];
  128. if(ball.virus) continue;
  129. if(!ball.visible) continue;
  130. if(ball.mine) continue;
  131. if(ball.size/my_ball.size > 0.5) continue;
  132. var distance = bot.getDistanceBetweenBalls(ball, my_ball);
  133. if(candidate_ball && distance > candidate_distance) continue;
  134.  
  135. candidate_ball = ball;
  136. candidate_distance = bot.getDistanceBetweenBalls(ball, my_ball);
  137. }
  138. if(!candidate_ball) return;
  139. bot.client.moveTo(candidate_ball.x, candidate_ball.y);
  140. }
  141. };
  142. var http = require('http');
  143. var serverarr = [];
  144. var req = http.get({
  145. host: 'm.agar.io',
  146. path: '/fullInfo'
  147. }, function(res) {
  148. var restext = '';
  149. res.on('data', function(d) {
  150. restext += d;
  151. });
  152. res.on('end', function() {
  153. var parsed = JSON.parse(restext);
  154. var server = {};
  155. for (var i = 0, len = parsed.servers.length; i < len; i++) {
  156. server = parsed.servers[i];
  157. if(server.isEnabled) serverarr.push(server);
  158. }
  159. startBots();
  160. });
  161. });
  162. var bots = [];
  163. var bot_id = 0;
  164. function startBots() {
  165. for (i = 0; i < serverarr.length; i++) {
  166. bots[i] = new ExampleBot(i);
  167. bots[i].connect('ws://' + serverarr[i].ip, '');
  168. bots[i].client.inactiveDestroy = 30^1000;
  169. }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement