NewNetworkProtocol

From TTWiki
Revision as of 17:39, 30 June 2007 by eis_os (talk)
Jump to navigationJump to search

Specification of the new asynchronous Network Protocol

New Async Network protocol

Instead having a DirectX based network system, we use a dedicated Server.

The Server component is only responsible to broadcast messages between the Clients so all TTDPatch Clients work in sync. Unlike traditional TTD, network joining will work while the first player is already in a game, the other players will get synced.

Both Server and Client have a framecounter, every action will take place at a certain framenumber.

A client sends actions to the server, which then decides at what frame the action on a client should take place. (The client doesn't cache the data, so the server has to send the data back.) The server is aswell responsible to initate a client sync and aswell check the random gen number of the clients from time to time, if they are in sync, if not the server initiate a sync.

A client will only advance to the next frame if the server sends a hearbeat packet.

The heartbeat packet is created every 27ms, at a configurable duration the heartbeat packet with randomgen request is send, a client then has to answer with a random gen number package and the server checks each active client if the random number matches with the other client.

Note: The action data for a frame has to arrive directly before the heartbeat package for that frame number.

-=Packets=-

A network packet has a variable lenght and is always in little endian format.

Each package start with:

<u32 framenumber> <u8 type>

Gamestate Packets:

||Type|Name|Description|Following Data

0x01|Action Data|The raw action data of ttd follows| <u8 len> <u8 data*len>

0x02|Action Data End Marker|Send after all actions of this frame got send|-||

Service Packets:

||Type|Name|Description|Following Data

0x30|Heartbeat|Send by the server to a client| -

0x31|Heartbeat with rnd request|with additional requesting a random number|-

Syncing

0x40|Random gen value|Answer to packet 0x31|<u32 random>

0x44|Get sync package|Request by the server to get the Gameplay data|-

0x45|Sync Package|Gameplay (Savegame) data|<u32 len><u8*len of gamedata>

0x46|Sync heartbeat|Only send when a client gets resyced|-

Server Management

0x80|Quit Server|Quits the server application|<u8*16 server password>

0x81|KickBan|Kicks the player x from the server and deny reconnection|<u8 playerslot> <u8*16 server password>

0x82|Kick|Kicks the player x from the server|<u8 playerslot> <u8*16 server password>

Client connect

0xF0|Server Password|Sends the server password to join|<u8*16 server password for joining>

0xF1|Free Slot Messages|Server shows current slots|<u32 len of following data><u8 free slot mask><u8 password mask><zero terminated strings follow for all player slots>

0xF2|Set Player Slot|Client requests a player|<u8 player slot to use><16x u8 password>

Password is filled with zero to match 16 Bytes, all zero means no password.

0xF3|Player Accepted|If the slot is free and the password is right

0xF4|Player Not Accepted|If there is an error, slot not free|<u16 error id>

0xF5|Newgrfmap|A map of used grfs|<u32 len of following data> Pairs of <u8*16 md5sum><string: newgrf filename><0x00><string: grf name> <0x00>

0xFF|Connect Error|Sends an error to the client|<u16 error id>||