Skip to content

Latest commit

 

History

History
168 lines (106 loc) · 4.14 KB

File metadata and controls

168 lines (106 loc) · 4.14 KB

Network Request

Introduction

Requests are handled as std::vector<std::byte>

All requests are formed with a header and a payload.
This is the header configuration :

#pragma pack(push, 1)
typedef struct header {
	uint8_t type;
	uint32_t length;
	uint8_t magic;
	uint16_t id;
} RTypeHeader_t;
#pragma pack(pop)

Type is the request type, defined in the enum RequestType
Length is the total length of the payload
Magic is a "magicNumber", it will change depending on the protocol version. This number is defined in the constexpr MAGIC_NUMBER in the protocolDefined include
Id is a unique id, it will be increased by on each request

After the header, you must stick the payload with a size of "length"


The next parts will present you the different request for the Client and the Server side.
The title of subpart is the values in the enum RequestType.
After you will find the different value type found in the payload in the right order.

Client Side

addNewRoom

Event when a new room is created

→ Int: roomId | Id of the new room
→ Int: nbrPlayer | Number of player in the new room
→ String[16]: roomName | The roomName, max 16 char will be given

ForceJoinRoom

Force the client to join a room

→ Int: roomId | Room ID to join
→ Int: roomPort | The port of the room

ServerError

A scalable error class.
Contains Int representing the error code. After this code you will find a variable string for the error description

→ Int: errorCode | The error code
→ Int: StringSize | Contain the size of the string after
→ Char[StringSize]: errorDescription | Contain the description of the error

ModifyRoom

Event when room data is modify (ex: player join)

→ Int: roomId
→ Int: nbrPlayer
→ String[16]: roomName

KickFromRoom

No payload, inform the to go back to the room-menu

StartGameClient

Inform the client to start the game, contain all data for initialization

→ Int: myId | Contain the player ship (0, 1, 2, 3)
→ Int: ship1 | Contain player 1 ShipType
→ Int: ship2 | Contain player 2 ShipType
→ Int: ship3 | Contain player 3 ShipType
→ Int: ship4 | Contain player 4 ShipType

UpdatePlayerShipPositionClient

Update other playerShip data (position and vector)

→ Int: shipId | The ship to modify data (0, 1, 2, 3) → Int: PosX | the new posX → Int: PosY | the new posY → Int: VelX | the new velX → Int: VelY | the new velY

NewShootClient

Inform that ship start shooting

→ Int: shipId | The ship who shoot (0, 1, 2, 3)

SpawnEnemyShip

Event when an enemy (IA) spawn

→ Int: serverID | The ID of the ship in the server → Int: shipType | The ShipType of the ship → Int: PosX | x position → Int: PosY | y position → Int: VelX | x velocity → Int: VelY | y velocity

PlayerDisconnected

inform that a player disconnected of the room

→ Int: playerID | The ID of the connected player (0, 1, 2, 3)

DeleteRoom

Inform that a room has been deleted

→ Int: roomId | The id of the room deleted

Server Side

DebugServer

A debug request, receive a number and display it in the console

→ Int: Number | The number to display in console

CreateRoom

Received when a user tries to create a room

→ String[16]: roomName | The room name, max 16 char

GetAllRoom

Request to send when we want to get all the opened room. After reception the server will send all room data with addNewRoom request

No Payload

JoinRoom

Request when a user tries to join a room.
Can send ServerError with an error message.

→ Int: roomId | Room ID of the room to join

StartGameServer

Request when we launch Infinite game mod.
Can send ServerError with an error message if not allowed

No Payload

UpdatePlayerShipPosition

Received when a player changes direction, can be relayed to other players.

→ Int: shipId | The ship to modify data (0, 1, 2, 3)
→ Int: PosX | the new posX
→ Int: PosY | the new posY
→ Int: VelX | the new velX
→ Int: VelY | the new velY

NewShootServer

Received when a player changes shoot, can be relayed to other players.

No Payload, the player is determined automatically