Skip to content
sdunham edited this page Dec 8, 2012 · 15 revisions

Version 0.3.

Table of Contents

General Server Information

The web server functions as a very loose RESTful HTTP API. This means all communication with the server happens over HTTP.

Server: puppetmaster.pugetsound.edu

Port: 1730

NOTE: Port 4242 still has a test turret object which is being by the game engine. Once they have a chance to update their code, it will be taken offline.

Accessible gameState Versions

There are three gameStates that you can access.

  • gameState.json -- the main game state. Use this to actually play the game when all clients are connected.
  • phoneSim.json -- a gameState that simulates two phone clients circling around the game board for the purpose of the game engine group testing.
  • gameSim.json -- a gameState that simulates a player character running around the game board for the purpose of the phone group testing.

Here are the two sorts of requests you can make.

GET /gameState.json

Parameters:

  • None

Returns:

  • The entire updated gamestate JSON object

This will return a JSON object with the entire gamestate in it. Example data:

{
    "message"       : "Welcome to our game!",
    "timeRemaining" : "120",
    "robotStatus"   : {
        "mood" : "happy",
        "hp"   : "20"
    }
}

POST /gameState.json

Parameters:

  • JSON object with your updates

Returns:

  • The entire updated gamestate JSON object

Your post data here will be a JSON object. The contents of this JSON object will merge with the gameState object, overriding any duplicated variables. That is to say, if the gamestate were:

{
    "message"       : "Welcome to our game!",
    "gameStatus"    : "normal",
    "timeRemaining" : "120",
    "robotStatus"   : {
        "mood" : "happy",
        "hp"   : "20"
    }
}

And you POSTed a JSON object containing

{
    "timeRemaining" : "0",
    "gameStatus"    : "overtime",
    "robotStatus"   : {
        "mood" : "stressed"
    }
}

The end result would be:

{
    "message"       : "Welcome to our game!",
    "gameStatus"    : "overtime"
    "timeRemaining" : "0",
    "robotStatus"   : {
        "mood" : "stressed",
        "hp"   : "20"
    }
}

Check out tests/postRequest.py in the WebServerGroup repo to see a basic python script that makes a post request.

POST /gameState.json?phone=[PHONE]&score=[SCORE]

This is the API for modifying the score of the phones. Direct modification of the score object is discouraged, because concurrent modification is problematic.

Parameters:

  • PHONE: The ID of the phone.
  • SCORE: The amount by which to modify the score. score=-10 to remove ten points, score=500 to add 500.

Returns:

  • The entire updated gamestate JSON object

POST /gameState.json?restartGame=true[&logScores=true]

This is the API for reinitializing the gameState JSON, and (optionally) logging the scores from the current gameState. To just restart the JSON, only include the restartGame parameter. To restart it and log the current scores in the leaderboard, also include the logScores parameter.

Parameters:

  • restartGame: true.
  • logScores: true (optional).

Returns:

  • Nothing

GET /leaderboard.json

Parameters:

  • None

Returns:

  • JSON object containing leaderboard data