Semester Project (part 2)
Server->Client protocol
- Server sends periodic updates of all objects in simulation
- Server sends notification of ship destruction
Server->Client messages
- SIGNON_ACK
- PLAYER_ID
- KILLED
- STATUS
SIGNON_ACK
- Acknowledges SIGNON and returns player's unique identifier
- Only sent once (after player SIGNON)
- Format:
0 (single byte) | player ID (32-bit
int )
|
PLAYER_ID
- Gives name and ID for new player (opponent)
- Sent once for each player when they join
- (You might also see a similar message when a player dies, but with a
playerid with the high bit set to 1.)
- Format:
1 (single byte)
| player ID (32-bit int )
| len
| f
| o
| o
|
KILLED
- Sent when ship destroyed
- Client must sent RESTART message to get new ship
- Format:
STATUS
- Sent periodically to distribute location and status of all objects
in simulation
- One entry for each object
- Message header:
16 (single byte) | n (a single
byte specifying the number of objects to follow)
|
ID | (player ID of this object - 32-bit int )
|
X | (position - 32-bit int )
|
Y | (position - 32-bit int )
|
angle |
(object angle * 103 - 32-bit int )
|
score | (32-bit int )
|
- If bit 31 of score is 1, object is a torpedo
- If bit 31 of score is 0, object is a ship
- If bit 30 of ship's score is 1, ship is firing thrusters
Processing Server->Client protocol
- Client processes incoming mesages in a loop
- Reads message type (one byte) first, then reads remainder of message
(if necessary)
- Process contents of message
switch
statement useful:
while (true) {
read next message type
switch (message type) {
case SIGNON_ACK:
read player id
break
case PLAYER_ID
read player information
break
case KILLED:
restart new ship
break
case STATUS:
read n
for (i = 0; i < n; i++) {
read object status
}
}
}
Last revised 4 December 2007