-
Notifications
You must be signed in to change notification settings - Fork 0
Client Protocol
This is a protocol that our framework supports for sending and receiving data between Server and Client.
Client and server connecting via a TCP connection.
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": []
}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.
sender: Client
Token is 32 character from a-zA-Z0-9. Default value for token is 32 0 character 00000000000000000000000000000000.
{
"name": "token",
"args": ["fyxIh2tLAwt6d5Fk8Bz03Y3z71CPui8d"]
}sender: Server
When a token is wrong, server sends a wrong token message to the client.
{
"name": "wrong token",
"args": []
}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_-. -
static diff: static is array of objects. Each object must haveidof changed object andturnof 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},
}
]
]
}sender: Server
Each turn server send some data.
-
turn: turn number -
diff: diff contain three data :view,static,dynamic, andtransientkeys.
{
"name": "turn",
"args": [
101,
{
"static": [],
"dynamic": [],
"transient": [
{
"type": "bomb",
"position": {"x": 13, "y": 19},
"duration": 2,
}
]
}
]
}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"
]
}
]
}sender: Server
Server sends this message when the game is finished and there is no further message transmission.
{
"name": "shutdown",
"args": []
}