Design Document PHP AJAX Coding Details Part 3

From BOARD18 Project WIKI
Revision as of 14:38, 28 August 2020 by Rich (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
This page has been updated to comply with Release 2.6.x of BOARD18.
Design Document edit


This page documents part 3 of the PHP AJAX called programs.

An oveview discussion of all PHP programs is available here.

playerGet.php

playerGet.php is the server side code for the AJAX playerGet call.

It returns most fields for a player in the players table. It also returns a list of the games the player is playing.

Input is: login.

Output is the following stringified JSON data structure.

 
  {
    "stat":"success||"fail"||"nogames",
    "playerid":"nnnnnn",
    "login":"aaaaaa",
    "firstname":"bbbbbb",
    "lastname":"cccccc",
    "email":"eeeeee",
    "level":"llllll",
    "games":
    [
      {
        "gname":"gggggg",
        "status":"ssssss"
      },
      . . . . more games . . . . . 
    ]
  }

playerShow.php

playerShow.php is the server side code for the AJAX playerShow call.

It returns an array of records from the players table.

Input is: blocksz and startrow.

Output is the following stringified JSON data structure.

 
  {
    "stat":"success||"fail",
    "players":
    [
      {
        "login":"aaaaaa",
        "firstname":"bbbbbb",
        "lastname":"cccccc",
        "email":"eeeeee",
        "level":"llllll",
        "gcount":"nnnnnn"
        "acount":"nnnnnn"
      },
      . . . . more players . . . . . 
    ]
  }

playerSort.php

playerSort.php is the server side code for the AJAX playerSort call.

It returns a sorted array of records from the players table.

Input is: sortkey.

Output is the following stringified JSON data structure.

 {
   "stat":"success||fail||empty",
   "players":
   [
     {
       "login":"aaaaaa",
       "firstname":"bbbbbb",
       "lastname":"cccccc",
     },
     . . . . more players . . . . . 
   ]
 }

playerUpdate.php

playerUpdate.php is the server side code for the AJAX playerUpdate call.

It updates a row in the players table. Unlike updateUser, playerUpdate keys on player_id.

Input consists the following parameters:

 player  
 login
 email
 fname
 lname
 level

Output is the echo return status:

 "success", "fail", "login", "bademail" or "email xxxx". 

snapShot.php

This is the server side code for the AJAX snapShot call.

It loads game status updates into the database.

Input is the gameID and the operating or stock round name.

Output is one of these the echo return statuses:

 "success"
 "failure"
 "notplaying"
 "collision"

snapShow.php

This is the server side code for the AJAX snapShow call.

It returns an array of the game_snap records for this game.

Input is: gameid, blocksz and startrow.

Output is the following stringified JSON data structure.

 {
   "stat":"success||none||fail",
   "snaps":
   [
     {
       "cp_id":"nnnn",
       "round":"gggg",
       "snaper":"bbbb",
       "updater":"vvvv",
       "cp_date":"mm/dd/yyyy"
     },
     . . . . more snaps . . . . . 
   ]
 }

statSwap.php

statSwap.php is the server side code for the AJAX statSwap call.

It toggles the game status field in the database. This status field can contain either "Active" or "Completed".

Input is the gameID.

Output will be "success", "failure" "notplaying" or "collision".

The SESS_UPDATE_COUNTER session variable is used by statSwap.php to support optimistic database locking.
This should stop concurrent updates from messing up the database. (And do this without incurring high overhead.)

tokenCheck.php

tokenCheck.php is the server side code for the AJAX tokenCheck call.

It deletes from the auth_tokens table any expired rows with the given selector. It also checks each such row for a matching validator. If it finds one it will return "tokenfound" and it will also delete the matching row from the table.

Input is: selector and validator.

Output is the echo return status: "tokenfound", "notoken" or "fail"

Note that this script does not check for a signed on user. This is because it is called before any signon has taken place.

tokenInsert.php

tokenInsert.php is the server side code for the AJAX tokenInsert call.

It inserts a new row in the auth_tokens table.

Input is: selector and validator.

Output is the echo return status: "success" or "fail"

tokenRemove.php

tokenRemove.php is the server side code for the AJAX tokenRemove call.

It deletes from the auth_tokens table any rows that exist for the logged in player.

This function requires no input parameters.

Output is the echo return status: "success" or "fail"

updateGame.php

updateGame.php is the server side code for the AJAX updateGame call.

It loads game updates into the database.

Input is the JSON game session data and the gameID.

Output will be "success", "failure" "notplaying" or "collision".

The SESS_UPDATE_COUNTER session variable is used by updateGame.php to support optimistic database locking.
This should stop concurrent updates from messing up the database. [And do this without incurring high overhead.]

updateUser.php

updateUser.php is the server side code for the AJAX updateUser call.

It updates a row in the players table.

Input consists the following parameters:

 pname
 email
 fname
 lname
 passwrd (optional)

Output is an echo return status of:

 "success", 
 "fail", 
 "bademail" or 
 "email login"

validateUser.php

validateUser.php is the server side code for the AJAX validateUser call.

It checks the current players login and password and, if they are valid, it logs the current player in to BOARD18.

Input consists the following parameters:

 login
 password

Output will be an array containing at a minimum the named value "stat" which will be set to "success", "fail" or an edit failure code. If "stat" = "success" then the array will also contain values for the following key names:

 "id" 
 "login"
 "firstname" 
 "lastname" 
 "level" 
 "changeit"