-
Notifications
You must be signed in to change notification settings - Fork 0
UI Protocol
This is a protocol that our framework supports for sending UI data to client.
UI and server connecting via a TCP connection.
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": []
}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.
sender: UI
Token is 32 character from a-zA-Z0-9. Default value for token is 32 0 character 00000000000000000000000000000000.
{
"name": "token",
"args": ["fyxIh2tLAwt6d5Fk8Bz03Y3z71CPui8d"]
}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 containturnkey. if game not started yet, turn must be-1. Alsoviewskey is required. -
map: Array of objects. each object must has uniqueidkey. id is string width maximum 16 character length froma-zA-Z0-9_-. -
diff: Array of objects. each object hasviewanddatakeys.viewis string.staticis array of objects. Each object must haveidof changed object andturnof 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": []
}
]
]
}sender: Server
Each turn server send some data.
-
turn: turn number -
diff: array of objects. each object hasview,static,dynamic, andtransientkeys.
{
"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": []
}
]
]
}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"
}
]
]
}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
}
}
]
}