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

This is a protocol that our framework supports for connecting to a terminal client. Terminal can send its request. We have two type of request : 1-command 2-event . Each request has a report from server to client. Events are synchron and commands are asynchron.

connection

Terminal and server connecting via a TCP connection.

Template

All transferred message between server and Terminal 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 terminal connected to server, terminal send his token to server. Then server send initial data to terminal. After initialization server is ready for terminal requests. So terminal can send its request and waiting for report of server.

Actions

Token

sender: Terminal

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.

info: Array of strings. Each string has some information about server and game.

{
  "name": "init",
  "args": [
    [
        "server version 2.0.3",
        "some useful data",
        "for help you can type help"
    ]
  ]
}

Command

sender: Terminal

Terminal can send command every time.

  • name : Each command has a name.
  • options : Array of strings. Each string is an option for this command.
{
  "name": "command",
  "args": [
      "newgame",
	  [
		"-x",
		"5",
		"/map_dir"
	  ]
  ]
}

Event

sender: Terminal

Terminal can send event every time.

Data is an object of an event.

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

Report

sender: Server

After each command , server send a report to terminal. Report contain an Array of strings.

{
  "name": "report",
  "args": [
      [
       "map size : 32 * 32",
       "1 player is online",
       "turn number : 100"
      ]
  ]
}

Clone this wiki locally