TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to clone Agar.io

76 pointsby huydotnetabout 10 years ago

6 comments

daanavitchabout 10 years ago
That&#x27;s a coincidence, yesterday I have been trying to make an Agar.io clone in Node.js. There are some problems I&#x27;ve stumbled upon which aren&#x27;t mentioned in this article:<p>- The original Agar.io server client doesn&#x27;t send raw text data through the WebSocket, it sends compressed binary data. Agar.io sends packets of max 187 bytes on my computer. The Agar.io clone sends packets of a staggering 4253 bytes of raw JSON data on my computer, with only me playing! On a real-time game like this, where the user should receive immediate feedback on their actions, this is way too large. Unfortunately I wasn&#x27;t able to decode the data Agar.io is sending, so I don&#x27;t really know how they do it. Maybe they only send data for each player&#x27;s region of interest? Or maybe they send the data for each player individually? I think that should be a decent enough solution because we can send as many small packets of data as we want over the WebSocket. We don&#x27;t have to receive all player&#x27;s locations at once.<p>I took a look at sending binary data over the WebSocket with Javascript, but it&#x27;s not as easy as enabling compression, because you really have to think about the data types you&#x27;re going to use, you can&#x27;t just send a variable length JSON as binary data (please correct me if I&#x27;m wrong).<p>- The original Agar.io game processes no game logic on the client side, which makes the game freeze completely once the server lags. Most online games solve this by letting the client run game logic, but letting the server correct the client&#x27;s position when he is cheating.<p>This method creates a whole different problem when the client receives data from the server from a position from some time ago. The client can&#x27;t just correct the player&#x27;s position just like that, or on slow networks the player would constantly be sent back to an earlier position. So to solve that the client needs to go back in time and replay the data received from the server. If the player is not cheating, correction should not be necessary. If the player is cheating, the client must accept the data from the server. This is a pretty rudimentary explanation, it&#x27;s explained better here: <a href="http:&#x2F;&#x2F;gafferongames.com&#x2F;networking-for-game-programmers&#x2F;what-every-programmer-needs-to-know-about-game-networking&#x2F;" rel="nofollow">http:&#x2F;&#x2F;gafferongames.com&#x2F;networking-for-game-programmers&#x2F;wha...</a><p>Of course implementing something like this is pretty complicated, even the original Agar.io doesn&#x27;t have a system like this.
评论 #9634626 未加载
评论 #9634338 未加载
评论 #9634633 未加载
评论 #9646136 未加载
评论 #9634032 未加载
jakozaurabout 10 years ago
I&#x27;m already writing Agar.io clone in Meteor and was about to publish article how to implement it.<p>Damn it :-), you got it first.
评论 #9633557 未加载
评论 #9633611 未加载
评论 #9634562 未加载
ibashabout 10 years ago
If you&#x27;re into this I&#x27;ve been pulling apart the agar.io client in this repo: <a href="https:&#x2F;&#x2F;github.com&#x2F;ibash&#x2F;agar" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ibash&#x2F;agar</a><p>Within &#x27;sandbox&#x27; in the repo you can start up a proxy server to the real agar.io backend. When you visit the web server it will connect to the real agar.io backend and let you play the game. The proxy also can parse some of the agar.io messages being sent to&#x2F;from the backend.
azeirahabout 10 years ago
I would mostly like to see a mobile version of agar.io
评论 #9633682 未加载
pdkl95about 10 years ago
<a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=w41J4x2ybAA" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=w41J4x2ybAA</a><p>Agar.io in Minecraft<p>(no mods! this was done in vanilla minecraft (command blocks))
ultrafezabout 10 years ago
Documents like this are fantastic as a potential collaborator.