Skip to content

Connecting To The Server

PartyLich edited this page Nov 19, 2012 · 6 revisions

This document outlines how a client connects to the server:

Connecting

  • The user authenticates OUT OF SCOPE
  • The service returns a list of open games
  • The user selects an open game

Alternatively, the user flow could be:

  • The user authenticates OUT OF SCOPE
  • The service returns a list of open games
  • The user is dissatisfied and chooses to start a new game OUT OF SCOPE

Authentication

These authentication APIs are subject to change.

To create the user, call out to this

POST /api/players/createplayer HTTP/1.1
Accept: application/json
Content-Length: 43
Content-Type: application/json

{ "name" : "shiftkey" }

Which returns the new user object

{
    "ok": true,
    "Player": {
        "Id": "7738560a-e224-49b8-adcf-2040c63d7eb5",
        "Name": "shiftkey",
        "ApiKey": "somevalue",
        "Wins": 0,
        "GamesPlayed": 0,
        "LastSeen": "/Date(-62135596800000)/",
        "IsOnline": true,
        "IsActive": false
    }
}

To then login when returning to the app, the client calls to the service:

POST /api/players/login HTTP/1.1
Accept: application/json
Content-Length: 43
Content-Type: application/json

{ "name" : "shiftkey", "token" : "someValue" }

Finding a game

After the user has authenticated, the client asks the server for a list of open games.

The client sends details to the service about the current user:

GET /api/games/getopengames
Accept: application/json
Content-Length: 25
Content-Type: application/json

{ "userName" : "shiftkey" }

Parse the list of available games

The service returns you some metadata about the games:

{
   "ok" : true,
   "games":[
      {
         "Id":"5aed8cf0-d94b-436e-ab05-fba28763f31b",
         "Name":"some game",
         "Players":[

         ],
         "Turn":0,
         "MapId":"00000000-0000-0000-0000-000000000000"
      },
      ...
      {
         "Id":"bab85eb4-5358-413a-9c6d-b75725de3e2c",
         "Name":"another game",
         "Players":[

         ],
         "Turn":0,
         "MapId":"00000000-0000-0000-0000-000000000000"
      }
   ]
}

Joining a game

Once the client has identified a game, it sends off details to the service.

POST /api/games/joingame
Accept: application/json
Content-Length: 103
Content-Type: application/json

    { 
        "gameId" : "656ed0d8-d63f-48b0-b0d3-072316194255",
        "playerId" : "3bad43e6-6cd1-1d26-dd9b-bff419941c79"
    }

The server will send back a response to indicate the state of the game:

{
   "ok": true,
   "game": {
      "Id":"1dca4426-3493-48e2-bb20-05dff1253923",
      "Name": "some other game",
      "Players": [
         {
            "Id": "5c7beaf6-4942-4b19-a846-eb27b717c78a",
            "Player": null,
            "Units": null,
            "Score": 0,
            "IsAlive": true
         }
      ],
      "Turn": 0,
      "MapId": "00000000-0000-0000-0000-000000000000"
   }
}

Starting a new game

POST /api/games/creategameandjoin

Accept: application/json
Content-Length: 103
Content-Type: application/json

Request Body: { "name" : "my awesome game", "playerId" : "3bad43e6-6cd1-1d26-dd9b-bff419941c79"  }

The server will send back a response in

{
   "ok":true,
   "game":{
      "Id":"1dca4426-3493-48e2-bb20-05dff1253923",
      "Name":"my awesome game",
      "Players":[
         {
            "Id":"5c7beaf6-4942-4b19-a846-eb27b717c78a",
            "Player":null,
            "Units":null,
            "Score":0,
            "IsAlive":true
         }
      ],
      "Turn":0,
      "MapId":"00000000-0000-0000-0000-000000000000"
   }
}

Map Selection

A user may choose a map, or a map can be chosen randomly from a set.

Maps will have areas which are inaccessible (e.g. water, forest, etc) to give players opportunities for strategic benefits.