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.
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>.
A normal game piece.
A tile from the game grid.
{
"color": <color> // The tile color
"pos": <position> // The tile position
}A 2 element integer array defining an XY position.
[5, 2]A 4 element integer array defining a RGBA color.
[255, 255, 0, 255] // YellowSent from the server to all other clients when a new player joins.
{"type": "join"}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>)
}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
}
{ "pos": <position>, // The piece position "color": <color>, // The piece color "blocks": [<position>] // The relative positions of the individual blocks of a piece }