Skip to content
سید محمد رضی موسوی edited this page Jan 7, 2015 · 2 revisions

This is a protocol that our framework supports for sending UI data to client.

connection

UI and server connecting via a TCP connection.

Template

All transferred message between server and UI 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 UI connected to server, UI send his token to server. Then server send initial data to UI. After initialization each turn server send data to UI.

Actions

Token

sender: UI

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

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

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_-.
  • diff: Array of objects. each object has view and data keys. view is string. 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"],
      "views": ["global", "team1", "team2"],
      "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"
      },
      "..."
    ],
    [
      {
        "view": "global",
        "static": [
          {
            "id": "92ejC5vEts",
            "turn":85,
            "type": "wall",
            "position": {"x": 12, "y": 15},
          }
        ]
      },
      {
        "view": "team1",
        "static": [
          {
            "id": "92ejC5vEts",
            "turn":85,
            "type": "wall",
            "position": {"x": 12, "y": 15},
          }
        ]
      },
      {
        "view": "team2",
        "static": []
      }
    ]
  ]
}

Turn

sender: Server

Each turn server send some data.

  • turn: turn number
  • diff: array of objects. each object has view, static, dynamic, and transient keys.
{
  "name": "turn",
  "args": [
    101,
    [
      {
        "view": "global",
        "static": [],
        "dynamic": [],
        "transient": [
          {
            "type": "bomb",
            "position": {"x": 13, "y": 19},
            "duration": 2,
          }
        ]
      },
      {
        "view": "team1",
        "static": [],
        "dynamic": [],
        "transient": []
      },
      {
        "view": "team2",
        "static": [
          {
            "id": "92ejC5vEts",
            "turn":85,
            "type": "wall",
            "position": {"x": 12, "y": 15},
          }
        ],
        "dynamic": [],
        "transient": []
      }
    ]
  ]
}

msgs

sender: Server

Some times server send list of messages.

{
  "name": "msgs",
  "args": [
    [
      {
        "text": "Team 2 disconnected.",
        "type": "danger"
      },
      {
        "text": "Team 1 is Winner.",
        "type": "success"
      }
    ]
  ]
}

Status

sender: Server

When status of game changed, server send status message.

{
  "name": "status",
  "args": [
    {
      "gameStatus": "run",
      "points": {
        "team1": 80,
        "team2": 73
      },
      "connections": {
        "team1": true,
        "team2": true
      }
    }
  ]
}

Clone this wiki locally