Skip to content
سید مرتضی موسوی edited this page Feb 17, 2015 · 11 revisions

This is a protocol that our framework supports for sending and receiving data between Server and Client.

connection

Client and server connecting via a TCP connection.

Template

All transferred message between server and Client is json string followed by \0 character. Every message is a key value object with two keys name and args. Name value is string and args value is array.

{
  "name": "<action name>",
  "args": []
}

Life cycle

When Client connected to server, Client send his token to server. Then server send initial data to Client. After initialization each turn server send data to Client and Client will send its events to Server.

lifecycle

Actions

Token

sender: Client

Token is 32 character from a-zA-Z0-9. Default value for token is 32 0 character 00000000000000000000000000000000.

{
  "name": "token",
  "args": ["fyxIh2tLAwt6d5Fk8Bz03Y3z71CPui8d"]
}

Wrong Token

sender: Server

When a token is wrong, server sends a wrong token message to the client.

{
  "name": "wrong token",
  "args": []
}

Init

sender: Server

First server send init message. Init message contain three data.

  • info: Object contain general data about game. for example map size or number of players. info object must contain turn key. if game not started yet, turn must be -1. Also views key is required.
  • map: Array of objects. each object must has unique id key. id is string width maximum 16 character length from a-zA-Z0-9_-.
  • static diff: static is array of objects. Each object must have id of changed object and turn of change
{
  "name": "init",
  "args": [
    {
      "turn": 100,
      "teams": ["team1", "team2"],
      "yourInfo" : {"name" : "team2",
                     "id" : 1
       },
      "mapSize": {
        "height": 30,
        "width": 60
      }
    },
    [
      {
        "id": "eybajqtEHm",
        "type": "wall",
        "position": {"x": 10, "y": 15}
      },
      {
        "id": "J2IXSJe50s",
        "type": "box",
        "position": {"x": 11, "y": 15},
        "color": "pink"
      },
      "..."
    ],
    [
      {
        "id": "92ejC5vEts",
        "turn":85,
        "type": "wall",
        "position": {"x": 12, "y": 15},
      }
    ]
  ]
}

Turn

sender: Server

Each turn server send some data.

  • turn: turn number
  • diff: diff contain three data : view, static, dynamic, and transient keys.
{
  "name": "turn",
  "args": [
    101,
    {
      "static": [],
      "dynamic": [],
      "transient": [
        {
          "type": "bomb",
          "position": {"x": 13, "y": 19},
          "duration": 2,
        }
      ]
    }
  ]
}

Event

sender: Client

Client send event every Turn.

Data is an object of an event.

{
  "name": "event",
  "args": [
      {"type" : "move",
       "objectId" : "546",
	"args" : [
		"player1",
		"x:15",
		"y:7"
	  ]
      }
  ]
}

Shutdown

sender: Server

Server sends this message when the game is finished and there is no further message transmission.

{
  "name": "shutdown",
  "args": []
}

Clone this wiki locally