Client-Server Game Protocol
The client-server game protocol uses TCP to transmit data between the client and server, using port 9999. Since TCP handles transmission control, no checksumming of packets is performed.
All packets are binary data, and where multi-byte values are transmitted, they will be in network byte order, also known as big-endian. Where string data is needed, it is sent as a single byte which represents the length of the string, followed by the bytes in the string.
The first byte of a packet is the command code, and determines the layout of the rest of the packet.
Most commands are only valid in particular player modes. Sending a command that is not valid in the current mode is considered an error, and will cause the connection to close. The following command codes can be sent to the server:
0x00 QUIT
Close the connection. This command is valid at any time.
0x01 LOGON
Log on to the server. This command is only valid in "init" mode.
0x02 PASSWD
Finish logging on by providing a requested password. This command is only valid when the player is in "password-required" mode.
0x03 LISTSHIPS
Return the list of ships. This command is only valid when the player is in "lobby" mode.
0x04 JOIN
Select the ship to use, and enter the game. This command is only valid in "lobby" mode.
0x05 ACTION
Give the server the action bitmask for the player. This command is only valid in "playing" mode.
0x06 CONTINUE
Return from "dead" mode to "playing" mode. This command is only valid in "dead" mode.
Initial Connection
Immediately upon connecting, the server will send one of the following greeting packets:
0x80 READY
The server is ready for you to log on. The packet also includes the protocol version, which is a single byte.
0x81 FULL
The server is full. The packet is followed by an immediate disconnect.
0x82 DENIED
The server has denied you access. The packet is followed by an immediate disconnect.
QUIT command
The QUIT command immediately closes the connection. The packet length is one byte, since there is no additional data required.
LOGON command
The LOGON command gives the username to the server. The packet length is variable. Following the command code is a string, which is the username. Valid responses are as follows:
0x82 DENIED
The server has denied you access. The packet is followed by an immediate disconnect.
0x83 LOGONOK
The user is logged in, and is now in "lobby" mode.
0x84 NEEDPW
The user must supply a password to complete the logon process.
PASSWD command
The PASSWD command gives the user's password to the server. The packet length is variable. Following the command code is a string, which is the password. Valid responses are as follows:
0x82 DENIED
The server has denied you access. The packet is followed by an immediate disconnect..
0x83 LOGONOK
The user is logged in, and is now in "lobby" mode.
LISTSHIPS command
The LISTSHIPS command sends the list of available ships to the client. The command packet is only one byte long. The response is a series of SHIPDATA packets, followed by an ENDSHIPDATA packet.
0x85 SHIPDATA
The SHIPDATA command code is followed by a byte which represents the ID of the ship. Next is the name, which is a string, and some statistics, which are each 16 bit unsigned integers. The statistics are: ship hit points, max speed, and max turn rate.
0x86 ENDSHIPDATA
The ENDSHIPDATA packet has no additional bytes.
JOIN command
The JOIN command puts the player into "playing" mode. The command code is followed by the ID of the ship the player would like to use. Valid responses are as follows:
0x87 PLAYING
The player is now playing. This response is only one byte in length.
0x88 BADSHIP
The ship ID requested was not valid. This response is only one byte in length.
ACTION command
The ACTION command puts tells the server what actions the player has requested. The command code is followed by a 16 bit integer which is a bitmask containing the requested actions. When in "playing" or "dead" mode, there is no respose for this packet. In any other mode the response is as follows:
0x89 INVALID
The command was invalid for this mode.
CONTINUE command
The CONTINUE command puts the player back into "playing" mode after the player has heen killed. Valid responses are as follows:
0x87 PLAYING
The player is now playing. This response is only one byte in length.
0x89 INVALID
The command was invalid for this mode.
"playing" Mode Transmissions
While the player is in "playing" mode, the server will continuously send data to the client. The expected packets are as follows:
0x90 UPDATE
The UPDATE command code is followed by an 8 bit sequence number. Next is the player orientation, which is one byte, then the player position, which is two 16 bit integers, X then Y. Following that is the number of objects within visible range, which is a byte. Following that is an update for each visible object. The updates are as follows: Object type (byte), object orientation (byte), object position relative to the player (two 16 bit integers, X then Y).
0x91 DEAD
The player has died, and is now in "dead" mode. Following this packet, player ACTION packets will be ignored, and UPDATE packets will still be transmitted.