Skip to content

Server API Documentation

Josh Grift edited this page Aug 23, 2019 · 1 revision

Server API Documentation

All requests are sent by json and have a command value.

Commands

Command Code Description
Register register User Register Request
Login login User Login Request
List list Lists games for user
Get Game get Get's the start game data
Action action Send the server a user's game action
Test test Send a request to the server to test an action
Changes changes Get a list of the changes since the last query
Next Turn next Signify to the server the player is ready, or is no longer read

Register

Client sends password and username.

Request

{
  "command":"register",
  "user":"jgrift",
  "pass":"normal-looking-password"
}

Server turns password into hash and stores {user:”jgrift”,pass:”HAJSDGHJASDGLASDKJ”}


Login

Sends server username and password to login

Request

Client:

{"command":"login", user:"jgrift","pass":"EDFGBNJHGF"}

Returns

check_auth("EDFGBNJHGF", "normal-looking-password")

{"auth":"456yh"} 

List

Lists games for user

Request

{
  "command":"list", // command
  "user":"jgrift",  // user
  "auth":"45678in"  // authentication token
}

Returns

{
  "games":[
    {
      "id":"XXXX",         // Game/map ID
      "name":"Josh's Game" // Game/map Description
    }
  ]
}

Get Game

Request

{
  command:”get”,  // Commmand
  user:”jgrift”,  // User
  auth:”45678in”, // Authentication Token
  game:”XXXX”     // Game/map ID
}

Return

{
  tiles:[
    {
      "ground":"water",     // ground layer (id)
      "terrain":"mountain", // terrain layer (id) or null
      "building":{          // or null
        id:"house",         // building id
        health:"100",
        team:"red",
        ...
      },
      "unit":{              // or null
        "id":"archer",
        "health":"100",
        "team":"red",
      },
      "visable":true,       // true or false
      "coords":[0,1]        // x,y
    },
    ...
  ],
  ...
}

Action

Complete an action

Request

{
  command:”action”,
  list:[
    {subject:”5,6,verb:”move”,noun:”5,7},
    ...
  ],
  auth:”45678in”,
  game:”XXXX”,
  user:”jgrift”
}

Return

{
   results:[
     {valid:true,status:null},
     ...
   ],
   changes:[
     {layer:”unit”,x:1,y:1,id:{type:”unit”,health:”80”}
   ]
}

OR

{
  results:[
    {valid:false,status:”OBSTACLE”}
  ]
}

Test

Same as action, but replace action with test


Changes (loop)

Request

{command:”changes”,auth:”45678in”,game:”XXXX”,user:”jgrift”}

Return

{turn:”play”,changes:[]}

OR

{turn:”waiting”,changes:[]}

Next Turn

Request

{command:”next”,value:"ready",auth:”45678in”,game:”XXXX”,user:”jgrift”}

OR

{command:”next”,value:"cancel",auth:”45678in”,game:”XXXX”,user:”jgrift”}

For your sanity and mine, use tableconvert.com

Clone this wiki locally