issy123 / agario-protocol

Protocol for agar.io version 2.1.5
8 stars 2 forks source link

New protocol 7 for Ogar server (since 05/05/2016) #15

Open Barbosik opened 8 years ago

Barbosik commented 8 years ago

Basically the protocol is almost the same as previous.

The new client sends the following 2 messages to private server at connection begin:

FE 07 00 00 00  // protocol version 
FF 00 00 00 00  // just ignore it

Protocol 6, 7 change list:

1) Cell Update message 0x10

A little change in the structure of cell update message:

Offset Value Type Description
0 0x10 byte Cell Update message code
1 xx uint16 Eat Record Count
3 xx record list Eat Records
xx xx record list Cell Update Records. Ends with 4-zero bytes
xx xx uint16 Remove Record Count
xx xx record list Remove Records

Structure of Eat Record:

Offset Type Description
0 uint32 Hunter Cell Id
4 uint32 Prey Cell Id

Structure of Cell Update Record:

Offset Value Type Description
0 xx uint32 Cell ID (0x00000000 is used as terminator)
4 xx int32 Coordinate X
8 xx int32 Coordinate Y
12 xx int16 Cell size
14 xx byte Flags
15 xx 3 byte (optional) Color (r,g,b components)
xx xx string (optional) Skin name (zero-terminated string)
xx xx string (optional) Cell name (zero-terminated string, UTF8 encoding)

Structure of Remove Record:

Offset Type Description
0 uint32 Cell ID (which should be removed)

The flags:

Bit Hex Mask Description
0 0x01 isVirus
1 0x02 isColorPresent (3 bytes with R,G,B components included into update)
2 0x04 isSkinPresent (zero terminated string with skin name included into update)
3 0x08 isNamePresent (zero terminated string with skin name included into update, UTF8 encoding)
4 0x10 isAgitated (if 1 then increases the amplitude of the waves on a blob outline)
5 0x20 isEject (if 1 then this is not a player cell, just W ejected blob)

Message example:

10                                                 // Cell Update message code
02 00                                              // 2 eat records
B5 FF 55 AA E7 FF 55 AA                            // eat record #1
51 FF 55 AA 44 FF 55 AA                            // eat record #2
38 FF 55 AA 59 0B 00 00 7B 00 00 00 CF 00 00       // cell update record #1
51 FF 55 AA 1D 0E 00 00 F0 00 00 00 C5 00 00       // cell update record #2
CC FF 55 AA D3 12 00 00 C8 FE FF FF E4 00 00       // cell update record #3
B5 FF 55 AA D8 0C 00 00 94 FE FF FF 9E 01 00       // cell update record #4
00 00 00 00                                        // cell update record terminator
02 00                                              // 2 remove records
44 FF 55 AA                                        // remove record #1
E7 FF 55 AA                                        // remove record #2

The main difference here is that color and name fields of the cell now is optional and may not be included into message. The second difference is position of the Flags field. Now it placed before the cell size field. And third difference is that there is no other fields. What optional field is included into message is controlled with flags.

This change in update cell message structure leads to problem with private servers with old protocol. But difference is not significant and can be easily fixed.

2) String encoding

All string encoding were changed to UTF8. It still uses zero-terminated strings, but now strings encoded in UTF8 format. It affects Cell Update message, Leaderboard FFA message and Join command.

3) Clear Message 0x12.

Actually this message was used since protocol 5. But I found that ogar server still uses 0x14 (partial clear message). They both 1-byte length. But the new client uses 0x12. And it's important to send this message just when connection established and also on each join command.

EnTerr commented 8 years ago

Not sure it's worth it for Ogar servers to try implementing this 0xFF compression. It is a trade-off: decreasing network traffic but increasing server CPU (trying to find repeat sequences).

Network utilization by uncompressed Agar protocol seems pretty low, see https://www.reddit.com/r/Agario/comments/3l78nk/anyone_know_how_much_data_agario_uses/ so i presume lagging of the servers is due to CPU overload mostly.

Oh, and this so-called "compression" is rather week. Don't see why they don't just rely on transparent websocket compression between browser and server instead.

terjanq commented 8 years ago

Good Job! Have you noticed what type of data is getting compressed? I have made this tool http://agarpp.comli.com/analyse/ for decoding it, and I don't see such difference in cells data with compression flag 241,242,243

Barbosik commented 8 years ago

added a little more details

EnTerr commented 8 years ago

Given https://github.com/JaraLowell/OgarServ/issues/144 , methinks there is more and protocol > 5 uses UTF8 for all strings in all packages. In particular relevant to not crashing, be prepared strings to have odd length and end with a single \0 (instead of having even number of bytes and end with \0 \0)

Barbosik commented 8 years ago

I'm surprised that there is still no fix for the new protocol. I'm not JS developer, but in order to help, I made quick fix for ogar server: https://github.com/OgarProject/Ogar/issues/588

It works well with the new client and also supports old protocol automatically (include automatic utf-8/unicode string switch). I will be glad if it could help you.

EnTerr commented 8 years ago

Ogar project proper seems not actively maintained. There are living forks though. I poked the maintainers of OgarServ and Ogar Unlimited but they are not interested in adding support for newer protocol. I think i understand them - there is no benefit really to speaking 6/7...

Barbosik commented 8 years ago

Added new details about Clear Message 0x12. Actually it was used since protocol 5, but I found that ogar server still uses old Clear Message 0x14.

Barbosik commented 8 years ago

EnTerr>> I think i understand them - there is no benefit really to speaking 6/7...

I don't think so, the benefit is that it allows to use the new agario client. It is more easy for most of the users to use agario client instead of alternative one.

EnTerr commented 8 years ago

Re 0x12 vs 0x14 server messages - i get the impression from http://agar.gcommer.com/Protocol that 0x14 was used to clear only the owned blobs, while 0x12 clears everything.

EnTerr commented 8 years ago

What benefits does the "new Agar.io client" have that others don't? Does it have map, chat, plugins.... no. It has ads... and does not speak protocol 5 no more. The good thing about Agar.io were the servers - not the client.

issy123 commented 8 years ago

It patches bots but also destroys extensions like agarplus and bot providers but they have their own dreams that they will release some new game some moved to slither or diep to make bots/extensions for.

But the benefit is that there are no bots which make it smooth as butter but on the other side everyone is greedy and kills for the smallest mass

EnTerr commented 8 years ago

I think "to stop the bots" is just a convenient excuse for killing 3rd party clients. There are other ways to tackle the bots - for example the different world coordinates per player - how would a bot overcome that?

issy123 commented 8 years ago

There are many ways

And much more and more..

But a captcha wouldn't hurt like this:

captcha

An extension could just use that captcha too to verify it

EnTerr commented 8 years ago

@issy123 - but spectators also don't get real coordinates - every client or observer was (and still is?) getting their own different coordinate system from Agar.io server even when inhabiting the same world. Offset cannot be reverse-engineered since random.

You have a point about cross-referencing the things "you see" though. Just to be clear what that entails - it's either to walk diagonally till reaching world corner (in one of the 4 directions, NW, NE, SW, SE - does not matter which and hard to take a guess which corner is closer). At that point bot can guess the local vs real world coord offsets.

Or, you need to carpet-bomb the world with bots, so being spread (or through "Brownian motion") they have a good chance of noticing (by name) each other and their master. It's theoretically doable... but doesn't that just make them easy food for other players?

Barbosik commented 8 years ago

added new finding about cell flag bits. Bit 5 indicates if the cell is ejected with W (not a player, just a food)