Skip to content

Latest commit

 

History

History
82 lines (57 loc) · 1.83 KB

File metadata and controls

82 lines (57 loc) · 1.83 KB

Message protocol

The protocol uses TCP internally. The messages consist of the message length (first 8 bytes, little endian format) and a JSON message in string form with the length given before.

A message will be read by first getting the first 8 bytes and then reading only the number of bytes defined by the first reading. If more information is sent, it will be interpreted as a new message.

Objects

This section talks about the "objects" present in the messages below.

When defining a message, I will use the object terms here using the notation <object_name>.

Piece

A normal game piece.

{
    "pos": <position>,      // The piece position
    "color": <color>,       // The piece color
    "blocks": [<position>]  // The relative positions of the individual blocks of a piece
}

Tile

A tile from the game grid.

{
    "color": <color>        // The tile color
    "pos": <position>       // The tile position
}

Position

A 2 element integer array defining an XY position.

[5, 2]

Color

A 4 element integer array defining a RGBA color.

[255, 255, 0, 255] // Yellow

Messages

Join

Sent from the server to all other clients when a new player joins.

{"type": "join"}

GameInfo

Sent from the server to the new client joining containing the information about the rest of the players

{
    "type": "gameinfo",
    "players": int          // Number of players (in the future it will be an array of <player>)
}

Update

Sent periodically from a client to update its game state with the rest of the players. Also serves as a heartbeat for the server to know a client is still alive (wip)

{
    "type": "update",
    "current": <piece>,     // Currently holded piece information
    "map": [<tile>]         // List of filled tiles
}