21/6/2015, 18:58

Agar with friends

This post describes how to set up a game with your friends in the online game agar.io. Note that this post is very likely to get outdated soon after the time of writing as the game is still under development.





Background


Agar.io is an addictive JavaScript based game in which you control a ball which eats balls that are smaller than itself. And which gets eaten by balls that are bigger than itself if you are not careful. Everybody is playing it. It's fun.

Now, as most online games, the game is a lot more fun if you play it with people you know. Until yesterday, people would accomplish this by simply manipulating the JavaScript to connect to the same game. In some cases, though, this could ruin games as people without teams would become overrun, and the feature was disabled.

As often happens, people quickly found a way to circumvent the newly introduced protection. Moreover, the fix is currently monetised on Chrome's Webshop. Monetising something that's not your own work like that is generally rather poor taste, so here is one way to obtain the same result as the monetised plugin.



The fix


Please be aware that everything here can be deduced directly from the slightly obfuscated client source code. I have no idea what the servers do.

In principle, here's how the initial connection works in the game: the client asks m.agar.io for a server in a given part of the world. The site replies with an IP for a server and a one-time code to connect to it.

Now, there's only so many servers out there so by simply repeating the request, one will eventually get more one-time codes for the same server, which can then be shared among one's friends. The procedure below explains how to do this in a way that is feasible for perhaps 2–3 people. It would be straight-forward to implement in a plugin to allow for an arbitrary number of people to join the same server, but I am not going to do that.



How to use this in practice


Step 1. Go to http://agar.io – the HTTPS version of the site also works but appears to be a bit buggy.

Step 2. Open the browser's developer console (right click → 'inspect element' → 'console' in Firefox/Chrome). Paste the following piece of JavaScript:


function getServer() {
jQuery.ajax("http://m.agar.io/", {
success: function(a) {
a = a.split("\n");
console.log("connect(\"ws://" + a[0] + "\", \"" + a[1] + "\")")
},
dataType: "text",
method: "POST",
data: "EU-London"
})
}

for (i=0;i<20;i++) {
getServer();
}

In this, replace "EU-London" with a location close to you. To see the currently active server locations, search for "EU-London" in the client source code.

Step 3. This produces a list of servers that you can connect to. To connect to a given one, simply copy one of the lines and enter it into the browser console. Now find some lines with duplicate IP:ports and share those with your friends. Remember that each line can only be used once.

Step 4. Repeat! For whatever reason (my hypothesis being that servers tend to be full), this does not necessarily work the first time around and people end up on different servers. In my experience though, a few attempts will typically suffice.


Tags: agar gaming javascriptThis post is available in Danish.

Comments


Erik 22/6/2015, 23:36
It doesn't seem to work when I try it.

It gives 20 times a version of this: connect("ws://151.80.98.52:1502", "x5dcrbuy/8cz\r2/n\2y3xtvvsokn2g8")

But when I try one of them it opens and closes the websocket 20 times.


Søren Fuglede Jørgensen 30/7/2015, 22:50
Yeah, it seems like they changed their connection code numerous times since I posted the above. I honestly don't know if anything works at the moment.



Add a comment

To avoid too much spam, you'll have to log in to add a comment. You can do so below, or you can create a user, if you don't already have one. You can use your photo login here as well.


E-mail address:
Password:  Forgot your password?
Captcha:

[ Different Image ]
CAPTCHA Image