Client API for Agar.io v2
Sorry, no NPM package support, you can install it directly through Github:
npm install https://github.com/SNSA/agario-client2.git --save
const AgarClient = require('agario-client2');
const Client = AgarClient.Client;
const server = AgarClient.server;
const client = new Client('clientName');
client.on('connected', () => {
console.log('Connected to server and ready to spawn');
client.spawn('SNSA');
});
client.on('newBall', (data) => {
console.log('New ball appears');
});
server.getFFAServer({}, (resp) => {
if (resp.error) {
return console.log('Error while getting FFA server:', resp.error);
}
console.log('Connecting to:', resp.server);
client.connect('ws://' + resp.server);
});
let client = new AgarClient.Client(clientName)
client.connect(server)
: connect to Agar server, connect to the samews://ip:port
to join the same roomclient.disconnect()
: disconnect from Agar serverclient.spawn(nickName)
: spawn a ball
In this list on.eventName(param1, param2)
means you need to do
client.on('eventName', function(param1, param2) { ... })
on.connected()
: connected to server and ready to spawnon.newBall(data: Buffer)
: new ball appears, sent when respawned or split (manually or by hitting a virus)on.reset()
: reset all balls, sent when start a new gameon.leaderBoard(data: Array)
: Leader board information, each item of the array is an array like[highlight, nickname]
,highlight
is a number with value 0 or 1 where 1 meansnickname
should be highlighted in leader board (for example your nickname)on.worldUpdate(data: Buffer)
: world update, contains all information needed to draw the visible cells
let server = AgarClient.server
See this.
MIT