Skip to content

Communication Protocol

Stefano Civelli edited this page Jul 2, 2021 · 30 revisions

Premise

The communication protocol used is JSON based so it is completly language indipendent. Using the provided documentation you can write your own client for our application using your favourite language.

Message Structure

All messages share the following structure:

  • username (String)
    • Client -> Server : username of the message sender
    • Server -> Client :
      • Model messages: username of the player that changed his model state
      • non-Model messages: username of the receiver (BroadCast on null)
  • messageType (enum)
  • payload (String)
    • if messageType == ACTION -> then payload is a JSON representation of an action class;
    • if messageType == MODEL_UPDATE -> then payload is a JSON representation of the objects that contains the changes made to the model;
    • if messageType == ERROR -> then payload is a JSON representation of the error enumeration.

Communication Examples

Checking nodes connection

When connection is established both server and client set a socket timeout. Then client and server keep sending each other periodical messages to keep the timeout from expiring.
Note: this isn’t a request - reply protocol. Every message is standAlone.

Player connection with match creation


Example of a login message with new match creation:
{
   "username": "adelaide",
   "messageType": "CREATE_MATCH",
   "payload": "GameID"
}

Example of a message from server asking for number of players:
{
   "username": "adelaide",
   "messageType": "NUMBER_OF_PLAYERS",
   "payload": null
}

Example of a message from client to specify the number of players:
{
   "username": "adelaide",
   "messageType": "NUMBER_OF_PLAYERS",
   "payload": "3"
}

Example of a possible error message during login:
{
   "username": null,
   "messageType": "ERROR",
   "payload": "INVALID_LOGIN_USERNAME"
}

Player connection joining an existing match


Example of a login message to join an existing match:
{
   "username": "adelaide",
   "messageType": "JOIN_MATCH",
   "payload": "GameID"
}

Start game

Ask to perform an action


Example of a request to perform an action to buy a develop card:
{
   "username": "adelaide",
   "messageType": "ACTION",
   "payload":
   {
      "type": "BUY_CARD",
      "row": "2",
      "column": "0",
      "cardSlotIndex": "1"
   }
}

Examples of possible updates messages after a buy card actions:
{
   "username": "adelaide",
   "messageType": "DEVELOP_CARD_DECK_UPDATED",
   "payload":
   {
      "row": "2",
      "column": "0"
   }
}
{
   "username": "adelaide",
   "messageType": "CARD_SLOT_UPDATE",
   "payload":
   {
   "SlotNumber": "2",
   "DevelopCardID": "D47"
   }
}

Example of a possible error message after a buy card actions:
{
   "username": "adelaide",
   "messageType": "ERROR",
   "payload": "INVALID_DEVELOP_CARD"
}

End game