Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using stocks. #40

Closed
ghost opened this issue Dec 21, 2015 · 11 comments
Closed

Using stocks. #40

ghost opened this issue Dec 21, 2015 · 11 comments

Comments

@ghost
Copy link

ghost commented Dec 21, 2015

I'm trying to include your stock5/proxy example into my project but I'm getting errors.

Bot : client created
using agent [object Object]
Connecting to ws://151.80.96.51:1507 with key X2TBE
Bot : connecting...
Bot : connection error: Error: connect ECONNREFUSED 151.80.96.51:1507

In other words the bot isn't connecting to the stock proxy.

code:

    bots[bot_id] = new ExampleBot(bot_id);
    bots[bot_id].agent = createAgent();
    console.log('using agent ' + bots[bot_id].agent)
    bots[bot_id].connect('ws://' + srv.server, srv.key);
@pulviscriptor
Copy link
Owner

That can be for different reasons.
You say you use proxy, do you use some custom lib/agent? Lib socks in example can use only SOCKS4/SOCKS5 servers. It does not working with proxy.
Is that the case?
If not, then you need some sniffer to debug whats happening. I can recommend Microsoft Network Monitor or wireshark to see what is going there.

@pulviscriptor
Copy link
Owner

Check packets from/to SOCKS server with Microsoft Network Monitor or wireshark.
Or show packets here so i can see what is wrong.

@ghost
Copy link
Author

ghost commented Dec 21, 2015

Here you go

@pulviscriptor
Copy link
Owner

It says "This file is not available, because the upload was interrupted.".
*If you want to upload .pcap file, be sure that you closed all applications that can send your passwords or some important data before capturing.
Also if it is .pcap file, tell me IP of your SOCKS server that was used while capturing packets.

@ghost
Copy link
Author

ghost commented Dec 22, 2015

Okay let me try again, http://ge.tt/1Cwgi8U2/v/0 and the proxy ips are 121.40.34.139:3128 and 31.184.242.173:3130

@pulviscriptor
Copy link
Owner

I do not see there SOCKS IP at all. Are you sure your code is correct?
Show your createAgent() function or test it replacing with this:

function createAgent() {
    return new Socks.Agent({
            proxy: {
                ipaddress: '121.40.34.139',
                port: 3128,
                type: 5
            }}
    );
}

Replace SOCKS IP with working one, if this SOCKS is dead already.

@pulviscriptor
Copy link
Owner

I do see communications with 104.20.38.148:80 (http://m.agar.io/) and 151.80.98.51:1511 (ws://151.80.98.51:1511) without any SOCKS.
There is something wrong with code i think.
Can you show me your code?

@ghost
Copy link
Author

ghost commented Dec 22, 2015

var stock = ["121.40.34.139:3128", "31.184.242.173:3130"];
var http=require('http');
var Socks = require('socks');
var AgarioClient = require('./agario-client/agario-client.js');

var botnames = ["DrGoat"];

//pick a random array
function randomarray(array) {
return array[Math.floor(Math.random() * array.length)];
}

//Basic info for bot
function ExampleBot(bot_id) {
    this.bot_id      = bot_id;         //ID of bot for logging
    this.nickname    = randomarray(botnames);//default nickname
    this.verbose     = true;           //default logging enabled
    this.interval_id = 0;              //here we will store setInterval's ID
    this.server     = '';   //server address will be stored here
    this.server_key = '';   //server key will be stored here
    this.client       = new AgarioClient('Bot ' + this.bot_id); //create new client
    this.client.debug = 1; //lets set debug to 1
    this.agent = ''
}

//Uses stock5 proxy
function createAgent() {
    var dataaa = randomarray(stock).split(":")
    return new Socks.Agent({
            proxy: {
                ipaddress: (dataaa[0]),
                port: (dataaa[1]),
                type: ('5')
            }}
    );
}

var agent = createAgent();

//Options for getFFAServer
var get_server_opt = {
    region: 'EU-London', //server region
    agent:  agent        //our agent
};

//Bot AI
ExampleBot.prototype = {
    log: function(text) {
        if(this.verbose) {
            console.log(this.bot_id + ' says: ' + text);
        }
    },

    connect: function(server, key) {
        this.log('Connecting to ' + server + ' with key ' + 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, spawning');
            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.once('leaderBoardUpdate', function(old, leaders) {
            var name_array = leaders.map(function(ball_id) {
                return bot.client.balls[ball_id].name || 'unnamed'
            });

            bot.log('Joined server');
        });

        bot.client.on('lostMyBalls', function() {
            bot.client.spawn(bot.nickname);
        });

        bot.client.on('reset', function() { //when client clears everything (connection lost?)
            clearInterval(bot.interval_id);
        });
    },

    recalculateTarget: function() {
        var bot = this;
        bot.client.moveTo(0, 0);
    }
};



//launching bots below

//object of bots
var bots = {
    'Alpha'  : null,
    'Bravo'  : null,
    'Charlie': null,
    'Delta'  : null,
    '1'  : null,
    '2'  : null,
    '3': null,
    '4'  : null,
    '5'   : null
};

//searching party for bots in EU-London
function start() {
    console.log('Requesting party server');
AgarioClient.servers.createParty({region: 'EU-London'}, function(srv) {
    if(!srv.server) return console.log('Failed to request server (error=' + srv.error + ', error_source=' + srv.error_source + ')');
    console.log('Engaging bots to party http://agar.io/#' + srv.key + ' on IP ' + srv.server);

    for(var bot_id in bots) {
        bots[bot_id] = new ExampleBot(bot_id);
        bots[bot_id].agent = createAgent();
        console.log('using agent ' + bots[bot_id].agent)
        bots[bot_id].connect('ws://' + srv.server, srv.key);
    }
});
}

startServer()

@pulviscriptor
Copy link
Owner

I see there few problems.

  • For every new connection you use createAgent() which uses randomarray() which returns random SOCKS server.
    So you can request server/key from one IP but connect from another and server will disconnect you immediately for that. You need to request server/key and connect from same IP, through same SOCKS.
  • For requesting server/key you do have options var get_server_opt but you do not use them at all.
  • Line 121 have AgarioClient.servers.createParty({region: 'EU-London'}, function(srv) { you did not specified agent in options here. Server/Key will be requested directly from your IP.
  • startServer() is not defined, it should be start() i think.
  • While fixing, i have crash Error: Please specify a proxy type in options.proxy.type which because of type: ('5') it should be integer type - type: 5

So after "fixes" here is "working" code

var stock = ["1.2.3.4:5678"];
var http=require('http');
var Socks = require('socks');
var AgarioClient = require('./agario-client/agario-client.js');

var botnames = ["DrGoat"];

//pick a random array
function randomarray(array) {
    return array[Math.floor(Math.random() * array.length)];
}

//Basic info for bot
function ExampleBot(bot_id) {
    this.bot_id      = bot_id;         //ID of bot for logging
    this.nickname    = randomarray(botnames);//default nickname
    this.verbose     = true;           //default logging enabled
    this.interval_id = 0;              //here we will store setInterval's ID
    this.server     = '';   //server address will be stored here
    this.server_key = '';   //server key will be stored here
    this.client       = new AgarioClient('Bot ' + this.bot_id); //create new client
    this.client.debug = 1; //lets set debug to 1
    this.agent = ''
}

//Uses stock5 proxy
function createAgent() {
    var dataaa = randomarray(stock).split(":");
    return new Socks.Agent({
            proxy: {
                ipaddress: (dataaa[0]),
                port: (dataaa[1]),
                type: 5
            }}
    );
}

var agent = createAgent();

//Options for getFFAServer
var get_server_opt = {
    region: 'EU-London', //server region
    agent:  agent        //our agent
};

//Bot AI
ExampleBot.prototype = {
    log: function(text) {
        if(this.verbose) {
            console.log(this.bot_id + ' says: ' + text);
        }
    },

    connect: function(server, key) {
        this.log('Connecting to ' + server + ' with key ' + 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, spawning');
            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.once('leaderBoardUpdate', function(old, leaders) {
            var name_array = leaders.map(function(ball_id) {
                return bot.client.balls[ball_id].name || 'unnamed'
            });

            bot.log('Joined server');
            bot.log('Leaders on server:' + name_array);
        });

        bot.client.on('lostMyBalls', function() {
            bot.client.spawn(bot.nickname);
        });

        bot.client.on('reset', function() { //when client clears everything (connection lost?)
            clearInterval(bot.interval_id);
        });
    },

    recalculateTarget: function() {
        var bot = this;
        bot.client.moveTo(0, 0);
    }
};



//launching bots below

//object of bots
var bots = {
    'Alpha'  : null
};

//searching party for bots in EU-London
function start() {
    console.log('Requesting party server');
    AgarioClient.servers.createParty({region: 'EU-London', agent: createAgent()}, function(srv) {
        if(!srv.server) return console.log('Failed to request server (error=' + srv.error + ', error_source=' + srv.error_source + ')');
        console.log('Engaging bots to party http://agar.io/#' + srv.key + ' on IP ' + srv.server);

        for(var bot_id in bots) {
            bots[bot_id] = new ExampleBot(bot_id);
            bots[bot_id].agent = createAgent();
            console.log('using agent ' + bots[bot_id].agent)
            bots[bot_id].connect('ws://' + srv.server, srv.key);
        }
    });
}

start();

If you add more than one SOCKS, it will stop work. You need use same SOCKS for requesting server/key and connection. You need to fix that.
Also setup somewhere your own SOCKS server for testing because public SOCKS usually are very very unstable.
I used ssspl for that. Please be careful to not allow somebody from internet use your SOCKS

@ghost
Copy link
Author

ghost commented Dec 22, 2015

Thanks for the help! How would I get different ips to join the same party?

@pulviscriptor
Copy link
Owner

How would I get different ips to join the same party?

What i can think of is modifying createAgent() like

function createAgent(socks) {
    return new Socks.Agent({
            proxy: socks
        }
    );
}

Then rewrite start to something like

function start() {
    console.log('Requesting party server');
    var socks = getNewSocksServer();
    AgarioClient.servers.createParty({region: 'EU-London', agent: createAgent(socks)}, function(srv) {
        if(!srv.server) return console.log('Failed to request server (error=' + srv.error + ', error_source=' + srv.error_source + ')');
        console.log('Engaging bots to party http://agar.io/#' + srv.key + ' on IP ' + srv.server);

        for(var bot_id in bots) {
            bots[bot_id] = new ExampleBot(bot_id);
            bots[bot_id].agent = createAgent(socks);
            console.log('using agent ' + bots[bot_id].agent)
            bots[bot_id].connect('ws://' + srv.server, srv.key);
        }
    });
}

And making getNewSocksServer() is up to you. It should return object like

            {
                ipaddress: '1.2.3.4',
                port: 567,
                type: 5
            }

Didn't tested, but i think you got the idea. You can even write socks to bots[bot_id].socks for future use if you will need it.
Oh, it may not work as it should. But you still got the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant