Difference between revisions of "Design Document PHP Coding Details"

From BOARD18 Project WIKI
Jump to navigation Jump to search
(→‎myGameList.php: Initial contents)
Line 120: Line 120:


===myGameList.php===
===myGameList.php===
This is the server side code for the AJAX myGameList call.
It produces the data needed to create a list of all games
that the signed in player is playing.
There are no input parameters.
Output is the following stringified JSON data structure.
  {
    "stat":"success",
    "games":
    [
      {
        "game_id":"nnnn",
        "gname":"gggg",
        "bname":"bbbb",
        "version":"vvvv",
        "start_date":"mm/dd/yyyy"
      },
      . . . . more games . . . . .
    ]
  }
===newUser.php===
===newUser.php===
===updateGame.php===
===updateGame.php===

Revision as of 16:43, 16 December 2013

Design Document edit


This page has details of all of the PHP files that are described in the Server Side Overview. The origional description for each file has been taken from the comments at the top of the file in question. While creating this page I will also be bringing these comments in line with these Standards.

AJAX Called Programs

An oveview discussion of these programs is available here.

changePlayers.php

changePlayers.php is the server side code for the AJAX changePlayers call. This program adds and/or removes players from existing game sessions.

Inputs:

  mode - A string with a value of '1', '2' or '3'.
         1 - Remove player with login ID in prem.
         2 - Add player with login ID in padd.
         3 - Take both of the above actions.
  game - game_id of current game.
  prem - Login ID of the player to be removed from the game.
  padd - Login ID of the player to be added to the game.  

Output is an echo return status of either "success", "fail" or "dupadd".

createGame.php

This is the server side code for the AJAX createGame call. It creates a new row in the game table and adds a row in the game_player table for each player in the game. Input is the following JSON string.

 {
   "gname": "name",
   "boxid": "boxid",
   "players": [
     "pname0",
     . . . . . 
     "pnamen",
   ] 
 }

Output is the echo return status "success", "fail", "nobox" or "noplayer #".

emailPlayerAdd.php

emailPlayerAdd.php is the server side code for the AJAX emailPlayerAdd call. It creates a text email to notify a player that has been added to a game. If the email creation is successful it then calls sendEmail.php and exits. This leaves it to sendEmail to return the final 'success" status.

Input consists the following parameters:

 login
 game

Output, if any, is the echo return status "fail".

emailPlayerRem.php

emailPlayerRem.php is the server side code for the AJAX emailPlayerRem call. It creates a text email to notify a player that has been removed from a game. If the email creation is successful it then calls sendEmail.php and exits. This leaves it to sendEmail to return the final 'success" status.

Input consists the following parameters:

 login
 game

Output, if any, is the echo return status "fail".

emailPlayerID.php

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

It creates a text email to remind a player (that has forgotten) of his player ID. If the email creation is successful it then calls sendEmail.php and exits. This leaves it to sendEmail to return the final 'success" status.

Input consists the "email" parameter.

Output, if any, is the echo return status "fail" or "bademail".

emailPassword.php

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

It creates a text email to inform a player of his new temporary password. If the email creation is successful it then calls sendEmail.php and exits. This leaves it to sendEmail to return the final 'success" status.

Input consists the following parameters:

 name
 email

Output, if any, is the echo return status "fail" or "bademail".

forcePasswd.php

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

It will process a forced password change.

Input consists the following parameters:

  player
  passwd

Output will be "success", "fail" or an edit failure code.

gameBox.php

gameSession.php

logout.php

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

It will unset all of the session variables, delete the session cookie and, finally, destroy the session.

There are no input parameters.

Output will always be "success".

myGameList.php

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

It produces the data needed to create a list of all games that the signed in player is playing.

There are no input parameters.

Output is the following stringified JSON data structure.

 {
   "stat":"success",
   "games":
   [
     {
       "game_id":"nnnn",
       "gname":"gggg",
       "bname":"bbbb",
       "version":"vvvv",
       "start_date":"mm/dd/yyyy"
     },
     . . . . more games . . . . . 
   ]
 }

newUser.php

updateGame.php

updateUser.php

validateUser.php

Include Modules

An oveview discussion of these modules is available here.

auth.php

auth.php is included at the start of all password protected pages and all password protected PHP programs called via AJAX.
It starts a php session and then checks to see that the player is logged in and has been active sometime in the last 30 minutes.

configMail.php

configMail.php is included at the start of sendEmail.php which sends SMTP emails via PHPMailer. Modify MAIL_HOST, MAIL_PORT, MAIL_USER and MAIL_PASS to the values appropriate for your Email server.

 define('MAIL_HOST', 'mail.server.org');
 define('MAIL_PORT', '587');  // STARTTLS
 define('MAIL_USER', 'user@server.org');
 define('MAIL_PASS', 'xxxxxxxxxx');

config.php

config.php is included at the start of all pages and php routines that access the board18 database. Modify DB_HOST and if necessary DB_DATABASE to contain the correct database host and name. You can also change the database user ID and password here.

 define('DB_HOST', 'localhost');
 define('DB_DATABASE', 'board18');
 define('DB_USER', 'board18');
 define('DB_PASSWORD', 'board18');

sendEmail.php

sendEmail.php uses SMTP to send plain text emails.
Use configMail.php to specify the server and server access information.
You should use the SMTP server provided by your ISP or your hosting service for these Emails.

makeTables.php

makeTables.php is included via "require_once()" into various board18 PHP pages. It supplies a number of functions for creating the HTML to display various tables on the page. These tables must be displayed on initial creation of these pages. They cannot be updated later by these functions without reloading the entire page. This file contains these functions:

 showBoxes($conn) - create a table of all game boxes in database.
 showPlayers($conn) - create a table of all players in database.
 gamePlayers($gameid, $conn) - create a table of players in game.

makeTables.php initializes these variables:

 $theLink - value returned by mysqli_connect function.
 $open - set to an empty string if the database connect succeeded.
       - set to 'fail' if the database connect failed.


This page is a stub.
The BOARD18 Project will soon be expanding it.