Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var AgarioClient = require('agario-client');
- function getToken() {
- var AgarioClient = require('agario-client');
- var account = new AgarioClient.Account();
- account.c_user = '100006612392533'; //100011132700068
- account.datr = 'LyWcVvCYbzfx0ze9kLUiFFmu'; //hBl-VqyJ2IO37dYyOHQDs4n9
- account.xs = '234%3AN4FUWGaXUgKTHw%3A2%3A1453420833%3A18215'; //127:I9OXiLse-vKMDg:2:1452461086:-1
- //Request token
- account.requestFBToken(function(token, info) {
- if(token) {
- var miliseconds = ( account.token_expire-(+new Date) )
- function mToMAS(millis) {
- var minutes = Math.floor(millis / 60000);
- var seconds = ((millis % 60000) / 1000).toFixed(0);
- return minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
- }
- token1 = token
- }else{
- console.log('Failed to request Facebook Token!!');
- if(info.error) console.log('The request for facebook.com returned: ' + info.error);
- if(info.res && info.res.statusCode) console.log('The HTTP Error code is: ' + info.res.statusCode);
- if(info.res && info.res.headers && info.res.headers.location) console.log('We got redirected to: ' + info.res.headers.location);
- if(info.data) console.log('HTML: ' + info.data);
- }
- });
- }
- getToken();
- var region = ['US-Atlanta', 'TK-Turkey', 'SG-Singapore', 'RU-Russia', 'JP-Tokyo', 'EU-London', 'CN-China', 'BR-Brazil']
- function ExampleBot(bot_id) {
- this.bot_id = bot_id;
- this.nickname = 'Trump';
- this.verbose = true;
- this.interval_id = 0;
- this.server = '';
- this.server_key = '';
- this.client = new AgarioClient('XPBot ' + this.bot_id);
- this.client.debug = 1;
- this.client.auth_token = token1;
- this.retryatempts = 0;
- }
- ExampleBot.prototype = {
- log: function(text) {
- if(this.verbose) {
- console.log(this.bot_id + ' says: ' + text);
- }
- },
- connect: function(server, key) {
- this.server = server;
- this.server_key = key;
- this.client.connect(server, key);
- this.attachEvents();
- },
- attachEvents: function() {
- var bot = this;
- bot.client.on('connected', function() {
- bot.log('Connected!');
- bot.client.spawn(bot.nickname);
- bot.interval_id = setInterval (function(){
- bot.recalculateTarget()
- }, 100);
- });
- bot.client.on('connectionError', function(e) {
- bot.log('Connection failed with reason: ' + e);
- bot.log('Server address set to: ' + bot.server + ' key ' + bot.server_key);
- });
- bot.client.on('packetError', function(packet, err, preventCrash) {
- bot.log('Packet error detected for packet: ' + packet.toString());
- bot.log('Crash will be prevented, bot will be disconnected');
- preventCrash();
- bot.disconnect();
- });
- bot.client.on('myNewBall', function(ball_id) {
- bot.log('My new ball ' + ball_id);
- });
- bot.client.once('leaderBoardUpdate', function(old, leaders) {
- var name_array = leaders.map(function(ball_id) {
- return bot.client.balls[ball_id].name || 'unnamed'
- });
- bot.log('Leaders on server: ' + name_array.join(', '));
- });
- bot.client.on('somebodyAteSomething', function(eater_ball, eaten_ball) {
- var ball = bot.client.balls[eater_ball];
- if(!ball) return; //if we don't know that ball, we don't care
- if(!ball.mine) return; //if it's not our ball, we don't care
- bot.client.log('I ate ' + eaten_ball + ', my new size is ' + ball.size);
- });
- bot.client.on('mineBallDestroy', function(ball_id, reason) { //when my ball destroyed
- if(reason.by) {
- bot.log(bot.client.balls[reason.by] + ' ate my ball');
- }
- if(reason.reason == 'merge') {
- bot.log('My ball ' + ball_id + ' merged with my other ball, now i have ' + bot.client.my_balls.length + ' balls');
- }else{
- bot.log('I lost my ball ' + ball_id + ', ' + bot.client.my_balls.length + ' balls left');
- }
- });
- bot.client.on('lostMyBalls', function() {
- bot.log('Lost all my balls, respawning');
- bot.client.spawn(bot.nickname);
- });
- bot.client.on('disconnect', function() {
- bot.log('Disconnected from server, bye!');
- });
- bot.client.on('reset', function() { //when client clears everything (connection lost?)
- clearInterval(bot.interval_id);
- });
- },
- getDistanceBetweenBalls: function(ball_1, ball_2) {
- return Math.sqrt( Math.pow( ball_1.x - ball_2.x, 2) + Math.pow( ball_2.y - ball_1.y, 2) );
- },
- recalculateTarget: function() {
- var bot = this;
- var candidate_ball = null;
- var candidate_distance = 0;
- var my_ball = bot.client.balls[ bot.client.my_balls[0] ];
- if(!my_ball) return;
- for(var ball_id in bot.client.balls) {
- var ball = bot.client.balls[ball_id];
- if(ball.virus) continue;
- if(!ball.visible) continue;
- if(ball.mine) continue;
- if(ball.size/my_ball.size > 0.5) continue;
- var distance = bot.getDistanceBetweenBalls(ball, my_ball);
- if(candidate_ball && distance > candidate_distance) continue;
- candidate_ball = ball;
- candidate_distance = bot.getDistanceBetweenBalls(ball, my_ball);
- }
- if(!candidate_ball) return;
- bot.client.moveTo(candidate_ball.x, candidate_ball.y);
- }
- };
- var http = require('http');
- var serverarr = [];
- var req = http.get({
- host: 'm.agar.io',
- path: '/fullInfo'
- }, function(res) {
- var restext = '';
- res.on('data', function(d) {
- restext += d;
- });
- res.on('end', function() {
- var parsed = JSON.parse(restext);
- var server = {};
- for (var i = 0, len = parsed.servers.length; i < len; i++) {
- server = parsed.servers[i];
- if(server.isEnabled) serverarr.push(server);
- }
- startBots();
- });
- });
- var bots = [];
- var bot_id = 0;
- function startBots() {
- for (i = 0; i < serverarr.length; i++) {
- bots[i] = new ExampleBot(i);
- bots[i].connect('ws://' + serverarr[i].ip, '');
- bots[i].client.inactiveDestroy = 30^1000;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement