Please also see proposed ServerProtocolExtensions
page is also relevant.
Most of server related information can be obtained from sources of the game (server_protocol.* and server_transport.* files)
In general, client connects to the server by creating a socket in stream mode. Logically, the stream of data consists from packets each having a header with first 4 bytes being the size of a packet in bytes, next 4 bytes - packet id and the rest - packet data. Packet size and ID are 32-bit values in network byte order.
The packets can have one of the following ID values:
// server replies
#define SRV_FAIL 0
#define SRV_OK 1
#define SRV_LOGIN 2
#define SRV_MESSAGE 3
#define SRV_CHALLENGE 4
#define SRV_GAME_START_HOST 5
#define SRV_GAME_START_JOIN 6
// user status update notifications
#define SRV_USER_ONLINE 7
#define SRV_USER_OFFLINE 8
#define SRV_USER_CHALLENGE_IN 9
#define SRV_USER_CHALLENGE_OUT 10
#define SRV_USER_BUSY 11
#define SRV_GAME_PACKET 12
#define SRV_ENDGAME 13
#define SRV_DEBUG_MESSAGE 14
By the way, all the packets that are received by server are logged, so you can start standard ufo2000 server, connect to it with your test client and view log to see if the server interprets what you send to it as expected.
I rewrote the server in Python. This required understanding the protocol, so here's how I understood it:
First packet is always from client to server, and is always SRV_LOGIN, payload being username and password separated by colon (':').
Second packet is always from server to client, and is the result of authentication - SRV_OK or SRV_FAIL. The latter may contain error message as payload.
In my implementation, after having sent SRV_FAIL, server does not drop the connection, so that client can retry authenticating.
After successful SRV_LOGIN, client is in 'online' state. It is considered being in the chatroom.
Client can send packets of type (PACKET_TYPE [payload] description):
- SRV_MESSAGE [arbitrary text] chat message
- SRV_CHALLENGE [opponent username] to either challenge a player, or accept other player's challenge.
- SRV_DEBUG_MESSAGE [id:data] some statistics information for server
- 'system:[client operating system name]' information about client operating system name ('Windows 98', 'Linux' or other)
- 'version:[client version string]' information about the version of ufo2000 client
Server currently does send SRV_FAIL messages if some action has failed. Hovewer, in the absence of explicit protocol synchronization, client can not determine exactly which packet caused what error. "User-visible" errors are sent as SRV_MESSAGEs , with 'Server: ' prefix.
Client must be prepared to receive packets of type:
- SRV_FAIL [error message] Some error.
- SRV_USER_ONLINE [username] Some user has become online (free for chat)
- SRV_USER_OFFLINE [username] Some user disconnected from server
- SRV_USER_BUSY [username] Some user started playing with some other user
- SRV_USER_CHALLENGE_IN [username] Some user sent a challenge to you
- SRV_USER_CHALLENGE_OUT [username] Your challenge to this user has been sent.
- SRV_GAME_START_HOST  server went into gameplay mode, you're supposed to be a host
- SRV_GAME_START_JOIN  server went into gameplay mode, you're supposed to join
In gameplay mode server only accepts three types of packets:
Information on this page is not complete and corrections are welcome.
- SRV_GAME_PACKET  Some game data (is simply relayed to the other player)
- SRV_ENDGAME  Opponent has ended playing (exit, disconnect, etc)
- SRV_DEBUG_MESSAGE [id:data] Some statistics information for server
- 'crash:[message with stack backtrace information and cpu registers]' Client crashed but managed to send some debugging information about the bug before dying
- 'assert:[assertion message]' Client has encountered assertion error and terminated
- 'crc error' Network synchronization bugs detected
- 'terrain:[terrain name]' Information about terrain type used in the game
- 'scenario:[scenario name]' Information about scenario type used in the game
- 'result:[match result]' Information about the winner of the game, match result can be 'victory', 'defeat' or 'draw' (everyone has died)
Edit Page -
Page Revisions -
Page last modified on August 29, 2004, at 12:13 PM