You are on page 1of 5

LULEÅ

TEKNISKA
UNIVERSITET

Interface specification of

Game protocol
Network programming

2010-08-23
Short specification
Game start
A Client send Join message to server with id=0;
Server replies with NewPlayer Change message(s) including info about the new client and it’s id.

Event messages
Clients send move request event to Server.
Server may send NewPlayerPosition Change message(s) to connected clients.

Text messages
In game chat messages, id=0 equals “muticast chat”.

Remarks
All messages (except Join) shall contain client id and sequence number.

The Server decides actions in response to incoming messages.

Clients are only allowed to move 3D objects in response to incoming NewPlayerPosition messages.
The 3D objects shall represent a figure according to the ObjectForm for each object id.

OPTIONAL: Clients may use other 3D objects than the ObjectForm specified in the protocol.
In that case, use a proper object according to the protocols ObjectDesc.

The game world coordinate system is (-100, -100, -100 to 100,100,100).

All messages shall be coded with “0x30 ASCII codec” i.e. sent as an ASCII-string.
The only allowed byte values are ”0123456789:;<=>?” (i.e 0x30 to 0x3F) except for start (STX, 0x02) and stop
(ETX, 0x03) bits that starts/ends every message.
Every data byte is coded to two bytes before sending by appending the four high bits to 0x30 in the first byte and
appending the four low bits to 0x30 in the second byte. E.g the byte 0xB5 is sent as 0x3B and 0x35 (i.e ”;5”).
A tip is to create methods for convertToAscii() convertFromAscii()…

2010-08-23
// Enums och constants

#define MAXNAMELEN 32

enum ObjectDesc
{
Human,
NonHuman,
Vehicle,
StaticObject
};

enum ObjectForm
{
Cube,
Sphere,
Pyramid,
Cone
};

struct Coordinate //assuming all using windows (floating point)


{
float x;
float y;
float z;
};

// Message head
enum MsgType
{
Join, // Client joining game at server

Leave, // Client leaving game

Change, // Information to clients

Event, // Information from clients to server

TextMessage // Send text messages to one or all


};

// Included first in all messages

struct MsgHead
{
unsigned int length; // Total length for whole message
unsigned int seq_no; // Sequence number
unsigned int id; // Client ID or 0;
MsgType type; // Type of message
};

2010-08-23
// Message type Join (Client  Server)

struct JoinMsg
{
MsgHead head;
ObjectDesc desc;
ClientForm form;
char name[MAXNAMELEN]; // nullterminated!, or empty
};

// Message type Leave (Client  Server)

struct LeaveMsg
{
MsgHead head;
};

// Message type Change (Server  Client)


enum ChangeType
{
NewPlayer,
PlayerLeave,
NewPlayerPosition
};

// Included first in all Change messages

struct ChangeMsg
{
MsgHead head;
ChangeType type;
};

// Variations of ChangeMsg

struct NewPlayerMsg
{
ChangeMsg msg; //Change message header with new client id
ObjectDesc desc;
ClientForm form;
char name[MAXNAMELEN]; // nullterminated!, or empty
};

struct PlayerLeaveMsg
{
ChangeMsg msg; //Change message header with new client id
};

struct NewPlayerPositionMsg
{
ChangeMsg msg; //Change message header
Coordinate pos; //New object position
Coordinate dir; //New object direction
};

2010-08-23
// Messages of type Event (Client  Server)
enum EventType
{
Move
};

// Included first in all Event messages

struct EventMsg
{
MsgHead head;
EventType type;
};

// Variantions of EventMsg

struct MoveEvent
{
EventMsg event;
Coordinate pos; //New object position
Coordinate dir; //New object direction

};

// Messages of type TextMessage


struct TextMessageMsg // Optional at client side!!!
{
MsgHead head;
char text[1]; // NULL-terminerad array av chars.
};

2010-08-23

You might also like