-
Notifications
You must be signed in to change notification settings - Fork 88
Compression
length | description |
---|---|
1 | packet type |
4 | retransmit mask |
2 | encapsulation seq |
2 | encapsulation ack |
2 | command stream seq |
2 | command stream ack |
2 | command stream len |
command stream length field is completely redundant with length field in the udp header.
encapsulation seq/ack and command stream seq/ack can be 8 bit fields since it takes 30 seconds for them to wrap around even then. In case of 10 seconds of no communication between 2 peers, a special value of 0xff in them can signal that a 16bit seq/ack field follows.
retransmit mask can be replaced by 1 bit in most cases, since it is zero basically all the time. bit=0 signals mask==0, bit=1 signals mask follows.
packet type can be replaced by 2 bits, since after the initial game setup stage, only command 4 and 5 are seen on the wire. 0==command4, 1==command5, 2==8bit command follows, 3==reserved
encapsulation header savings: 6 + 31 + 4*8 + 16 bits == 85 bits of 120 bits (70%) assuming 8 * (20 + 8) bits for IP4+UDP, total savings: 85 bits of 344 (25%)
the command stream (for when encapsulation.type == 4) consist of a sequence of command packets with this structure:
length | description |
---|---|
1 | command code |
2 | length |
N | contents |
Known command codes
code | length | argument | description |
---|---|---|---|
0 | 4 | simtick increment | sender target simtick += argument |
0x32 | 5 | playerid,simtick | sender acknowledges simtick for playerid |
0x33 | 4 | simtick | ? (simtick that was executed?) |
0x34 | 4 | simtick | ? (simtick that is is closed and ready to be executed?) |
0xc | var | ? | ? (sim command?) |
0x16 | var | ? | ? (lua command? e.g.: give resources, chat) |
0x3 | 20 | hash,simtick | desync detection hash |
many more command codes that are still unknown.
The deflate compression appears to achieve a ca. 50% compression ratio, albeit for a case where not many commands were given to the simulation.
example packet dump (3 player game): https://github.com/faf5678/stuff/blob/master/packet_dump