Post by Kristal Rose Phoenix McKinstry on Oct 17, 2005 3:31:40 GMT -5
<?php
##########################################################################################
######################### SMC CS85 CHESS PROGRAM #########################################
##########################################################################################
if ($ulShowVersions) print('
#### oStorage.rpq ########################################################################<br />
// modified comments
#### 2005.11.09 22:00 - km Table qtForum now supports unicode. ############<br />
#### 2005.11.07 03:00 - km oReg->fGetNameFromId now works with either column. ############<br />
#### 2005.11.06 18:00 - km added oReg->fPlayerIsFirst($lsId). ###############<br />');
#### 2005.11.05 09:15 - km repaired ..fGetGameFromId($lsId). ###############
#### 2005.11.05 00:05 - km added oReg..fGetGameFromId($lsId). ###############
#### 2005.11.04 01:30 - km added oReg..fIsPlayersTurn($lsId). ###############
#### 2005.11.03 05:45 - km finished: fRegisterGame. ###############
#### 2005.11.03 05:45 - km added/finished: fGetOtherId, fGetNameFromId, fGetIdFromName. ##
#### 2005.11.01 17:00 - km ###############
#### 2005.10.31 04:15 - km working on oReg->fRegisterGame. ###############
#### 2005.10.31 04:15 - km MODIFIED TABLE qtRegisteredGames. ###############
#### 2005.10.31 00:20 - km DELETED UNUSED TABLE qtPlayers. ###############
#### 2005.10.30 02:15 - km added fGetOwner to oRegistration. ###############
#### 2005.10.29 02:30 - km added oRegistration->fGetOtherPlayers($lsId). ###############
#### 2005.10.28 20:45 - km added oRegistration->fIsNameAvail($lsTestName). ###############
#### 2005.10.27 06:45 - km modified oId to work multiple times. ###############
#### 2005.10.27 06:45 - km CREATED oRegistration object. ###############
#### 2005.10.26 22:40 - km modified to support new oServer object ! ! ###############
#### 2005.10.26 19:40 - km added $ulShowVersions for testing. ###############
#### 2005.10.26 18:40 - km - added definitions. #####
#### 2005.10.24 11:15 - km - reformatted title block. #####
#### 2005.10.23 06:10 - km - now requires sConnect.rsp #####
#### 2005.10.22 04:50 - km completed oId object to create unique ID's. #####
#### 2005.10.21 15:40 - added oId object specs #####
#### 2005.10.20 21:00 - (same as 20:09) km - NO EDIT Req'd for VAR NAMES conventions #####
#### 2005.10.20 20:09 - km edited variable names - New variable naming conventions! ######
#### 2005.10.20 18:20 - km added oStore->fStoreThing & fRestoreThing specs ###############
#### 2005.10.17 19:00 - km added oStore spec #############################################
#### 2005.10.17 03:00 - km added Title block #############################################
##########################################################################################
##########################################################################################
#### Status: Partially available to edit #################################################
#### Object oId is DONE ! #################################################
##########################################################################################
##########################################################################################
#### Description: ####################################
#### ####################################
#### ######################
##########################################################################################
##########################################################################################
#### Agenda: #############################################################################
#### [ ] SQL Serializer Object for objects and arrays #################################
#### [ ] SQL Serializer Object for objects and arrays #################################
#### [] Player deserializer (from log-in, finds current game and deser's obj's) ######
#### (oGame and oBoard) ######
#### [ ] oStorage // Contains all generic functions ######
#### eg. call: oAbstractStorage::fLoginUser($lsUserId) ######
#### Note, this call doesn't require an instance to exist, ######
#### It's just a convenient place to store our misc sql funcs. ######
##########################################################################################
##########################################################################################
############################################ TEST STATUS: #################
############################################ No testing has been done. #################
##########################################################################################
##########################################################################################
#### Programmers: Kristal McKinstry, ######################
##########################################################################################
##########################################################################################
#~~~~PROGRAMMER NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Author ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# {notes here}
# {etc. etc. etc}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Other Author ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# {notes here}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##########################################################################################
##########################################################################################
/*
..oStorage
....uses:
......fSaveGame (lsGameId, laNewBoard, laGameStatus)
......gGetGame (lsGameId)
....methods:
......fConstructNew // default, does nothing.
......fStoreThing (lsUsedId, , lsEnvId, &ThingRef) // stores objects and arrays.
// These functions will be a bit more complex because you will need to test if an entry (row record) already exists
// for that combo of userId & envId, then update or delete&insert if so.
// pseudo-code $a = serialize(laArray)
// pseudo-code ('INSERT INTO qtChessData (qfUsedId, qfEnvId, qfArray) VALUES ($lsUserId, , $lsEnvId, $a)))
......fRestoreThing (lsUsedId, , lsEnvId)
........returns original object (by reference if possible).
// pseudo-code return(unserialize('select qfArray from qtChessData where qfUserId==$lsUserId and qfEnvId==$lsEnvId));
..oId
....methods:
......fGetUniqueId(lsType) // returns lowest available Id (AAAAAA) of that type after inserting row.
Tables:
CREATE TABLE `qtIds` (
`qfUID` INT( 9 ) NOT NULL AUTO_INCREMENT ,
`qfType` CHAR( 12 ) DEFAULT 'zilch' NOT NULL ,
`qfVal` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfCreateDate` INT( 9 ) NOT NULL ,
PRIMARY KEY ( `qfUID` )
) TYPE = MYISAM ;
INSERT INTO `qtIds` (qfType, qfVal) VALUES ('lsUserId', 'AAAAAA')
lsUserId, lsEnvId, and lsGameId can all have values of that same format, eg. AAAACJ
CREATE TABLE `qtRegisteredGames` (
`qfUID` INT( 9 ) NOT NULL AUTO_INCREMENT ,
`qfPlayerOneId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfLongNameOne` CHAR( 20 ) UNICODE DEFAULT 'zilch' NOT NULL ,
`qfPlayerTwoId` CHAR( 6 ) UNICODE DEFAULT 'zilch' NOT NULL ,
`qfLongNameTwo` CHAR( 20 ) DEFAULT 'zilch' NOT NULL ,
`qfTurn` INT( 1 ) DEFAULT '0' NOT NULL ,
`qfGameId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfWinner` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfLastBoard` INT( 4 ) DEFAULT '0' ,
PRIMARY KEY ( `qfUID` )
) TYPE = MYISAM ;
CREATE TABLE `qtForum` (
`qfUID` INT( 9 ) NOT NULL AUTO_INCREMENT ,
`qfFromId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfToId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfPublic` INT( 1 ) DEFAULT '0' NOT NULL ,
`qfDateTime` INT( 10 ) DEFAULT '0' NOT NULL ,
`qfComment` MEDIUMTEXT UNICODE NOT NULL ,
PRIMARY KEY ( `qfUID` )
) TYPE = MYISAM ;
CREATE TABLE `qtBoards` (
`qfUID` INT( 9 ) NOT NULL AUTO_INCREMENT ,
`qfGameId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfTurnNum` INT( 4 ) DEFAULT '0' NOT NULL ,
`qfBoardArray` MEDIUMTEXT NOT NULL ,
PRIMARY KEY ( `qfUID` )
) TYPE = MYISAM ;
..laMove
....liPlayer, laFrom, laTo, lsSpecialMove
..liSubmitter [1,2] // Which player has submitted refresh?
..liTurn [1,2] // Whose turn is it?
*/
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class oId {
var $voServer;
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function oId (&$loServer){
$this->voServer = $loServer;
}//end-meth oId
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fGetUniqueId($lsType){ //worked
// Creates next unique ID of proper type, inserts in DB and returns generated ID for use in creating rows in other tables.
//Types: userId, gameId
// PART A - Get existing ID values
##printf("MySQL server version: %s\n", mysql_get_server_info()); //works. basic connect test.
##echo "<br /> fGetUnique is using server $this->voServer <br />";####@@@@
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfVal FROM qtIds WHERE qfType = '$lsType' ORDER BY qfVal";
$lsQueryHandle = mysql_query($query);
$liX = 0;
while ($temp = mysql_fetch_row ($lsQueryHandle)) {
$laTable[$liX] = array($temp[0]); // replacement
$liX++;
}
####exhibit_array($laTable);
// PART B - Determine next ID.
// Find first empty slot eg. If elements are AAAAAA, AAAAAC then creates AAAAAB
// Two functions reqd for PART B:
if (!function_exists('lfMakeNextAlpha')){ // BECAUSE APPARENTLY FUNCTIONS WITHIN METHODS OF CLASSES BECOME GLOBAL.
function lfMakeNextAlpha($lsCurrent){
for($i=0; $i<6; $i++)
$laChars[$i] = substr($lsCurrent, $i, 1);
$laChars[5] = chr(ord($laChars[5]) +1);
If ($laChars[5]>'Z') {
$laChars[5] = 'A';
$laChars[4] = chr(ord($laChars[4]) +1);
If ($laChars[4]>'Z') {
$laChars[4] = 'A';
$laChars[3] = chr(ord($laChars[3]) +1);
If ($laChars[3]>'Z') {
$laChars[3] = 'A';
$laChars[2] = chr(ord($laChars[2]) +1);
If ($laChars[2]>'Z') {
$laChars[2] = 'A';
$laChars[1] = chr(ord($laChars[1]) +1);
If ($laChars[1]>'Z') {
$laChars[1] = 'A';
$laChars[0] = chr(ord($laChars[0]) +1);
} } } } }//end-5if's
return(implode('', $laChars));
}//end-func lfMakeNextAlpha
}//end-if!exists
if (!function_exists('lfIsNextAlpha')){
function lfIsNextAlpha ($lsCurrent, $lsNext) {
if ($lsNext == lfMakeNextAlpha($lsCurrent)) {
return TRUE;
}
else {
return FALSE;
}
}//end-func lfIsNextAlpha
}//end-if!exists
$lsTempId = 'AAAAAA';
if (isset($laTable)) { // if 1st exists... Else Use unchanged $lsTempId 'AAAAAA'. (if (count($laTable)>0) Fails when table empty).
reset($laTable); //start at beginning
if (count($laTable)>1) { // if next exists...
While (TRUE) {
$lsCurrent = current($laTable);
$lsCurrent = $lsCurrent[0];
$lsNext = next($laTable); // !! This skips pointer ahead to become current in line above after continuing while.
$lsNext = $lsNext[0];
if (lfIsNextAlpha($lsCurrent, $lsNext)) {
continue; //SKIP AND GO AGAIN
} //end-if lfIsNextAlpha
else { // Wasn't NextAlpha
$lsTempId = lfMakeNextAlpha($lsCurrent); // Empty slot; THIS IS WHERE ID IS CREATED (except for new table)
break;
} //end-else Wasn't NextAlpha
} //end-while
} // end-if next exists
else { // next didn't exist
$lsTempId = 'AAAAAB';
} // end-else next didn't exist
} //end-if 1st exists
// PART C - Write new ID into table.
$query = "INSERT INTO `qtIds` (qfType, qfVal) VALUES ('$lsType', '$lsTempId')";
mysql_query($query);
// PART D - return newly written Unique ID.
return($lsTempId);
} //end-meth fGetUniqueId
} //end-class oId
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class oRegistration {
// The Registered Users Table qtRegisteredGames:
// Fields: qfPlayer (char 6), qfLongName (char 20), qfGame (char 6), qfWinner (char 6)
// Separate records per player until second player is assigned to first record.
// Player available if no game assigned.
// Don't delete records when game ends. (to keep track of winners).
/* CURRENT !!
CREATE TABLE `qtRegisteredGames` (
`qfUID` INT( 9 ) NOT NULL AUTO_INCREMENT ,
`qfPlayerOneId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfLongNameOne` CHAR( 20 ) DEFAULT 'zilch' NOT NULL ,
`qfPlayerTwoId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfLongNameTwo` CHAR( 20 ) DEFAULT 'zilch' NOT NULL ,
`qfTurn` INT( 1 ) DEFAULT '0' NOT NULL ,
`qfGameId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfWinner` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfLastBoard` INT( 4 ) DEFAULT '0' ,
PRIMARY KEY ( `qfUID` )
) TYPE = MYISAM ;
*/
var $voServer;
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function oRegistration (&$loServer){
// Although both players ultimately share one game record, they each have a separate record
// until a game is created and the second record is deleted.
$this->voServer = $loServer;
}//end-meth oRegistration
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fIsNameAvail($lsTestName){ #### NEEDS WORK?
$loId = new oId($this->voServer);
$query = "SELECT DISTINCT qfLongNameOne FROM qtRegisteredGames WHERE qfLongNameOne = '$lsTestName' AND qfGameId = 'zilch'";
$this->voServer->fSelectDB();
$liCount = mysql_num_rows(mysql_query($query));
if ($liCount == 0) return(TRUE);
else return(FALSE);
}//end-meth "fTestName"
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fAddActiveUser ($lsLongName){
##echo $lsLongName;//@@@@
$loId = new oId($this->voServer);
$lsId = $loId->fGetUniqueId('userId');
//Insert userId into qtRegisteredGames
$query = "INSERT INTO `qtRegisteredGames` (qfPlayerOneId, qfLongNameOne) VALUES ('$lsId', '$lsLongName')";
$this->voServer->fSelectDB();
mysql_query($query);
return($lsId);
}//end-meth fAddActiveUser
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fGetOtherPlayers($lsId){
$loId = new oId($this->voServer);
$query = "SELECT ALL qfLongNameOne FROM qtRegisteredGames WHERE qfPlayerOneId != '$lsId' AND qfGameId = 'zilch'"; //worked
$this->voServer->fSelectDB();
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
if ($liX>0) return($laTable);
else return(NULL);
}//end-meth "fGetOtherPlayers"
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fGetOtherId($lsId){
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfPlayerTwoId FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsId'"; //worked
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
##echocall("oReg.fGOI at first found $liX records.");
if ($liX<1){
$query = "SELECT DISTINCT qfPlayerOneId FROM qtRegisteredGames WHERE qfPlayerTwoId = '$lsId'"; //worked
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
##echocall("oReg.fGOI again and found $liX records.");
}//end-if
if ($liX<1){
##echocall('oS_oReg->fGOI. No Other ID existed!'); ####@@@@
$lsOtherId = 'zilch';
}//end-if
else {
$lsOtherId = $laTable[0][0];
##COOL echocall("Called oS->fGOI. OtherID was $lsOtherId");
}//end-else
return($lsOtherId);
}//end-meth
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fGetIdFromName($lsLongName){
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfPlayerOneId FROM qtRegisteredGames WHERE qfLongNameOne = '$lsLongName'";
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
$lsId = $laTable[0][0];
return($lsId);
}//end-meth
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fGetNameFromId($lsId){
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfLongNameOne, qfLongNameTwo, qfPlayerOneId, qfPlayerTwoId FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsId' OR qfPlayerTwoId = '$lsId'";
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
$lsLongName = '!!fGetNameFromId FAILED!!';
if ($laTable[0][2]==$lsId) $lsLongName = $laTable[0][0];
if ($laTable[0][3]==$lsId) $lsLongName = $laTable[0][1];
return($lsLongName);
}//end-meth
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fGetGameFromId($lsId){
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfGameId FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsId' OR qfPlayerTwoId = '$lsId'";
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
$lsGameId = $laTable[0][0];
return($lsGameId);
}//end-meth
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fRegisterGame($loCFV){
// First person to select a partner becomes Player One. Other players qtGames record is deleted.
$lsPlayerOneId = $loCFV->fGetVal('vhPlayer');
$lsLongNameOne = $this->fGetNameFromId($lsPlayerOneId);
$lsLongNameTwo = $loCFV->fGetVal('vsOtherPlayer');
$lsPlayerTwoId = $this->fGetIdFromName($lsLongNameTwo);
$loId = new oId($this->voServer);
$lsGameId = $loId->fGetUniqueId('gameId');
$this->voServer->fSelectDB();
$query = "DELETE FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsPlayerOneId'";
mysql_query($query);
$query = "DELETE FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsPlayerTwoId'";
mysql_query($query);
$query = "INSERT INTO qtRegisteredGames (qfPlayerOneId, qfLongNameOne, qfPlayerTwoId, qfLongNameTwo, qfTurn, qfGameId, qfWinner, qfLastBoard) VALUES ('$lsPlayerOneId', '$lsLongNameOne', '$lsPlayerTwoId', '$lsLongNameTwo', 1, '$lsGameId', 'zilch', 0);";
mysql_query($query);
// Insert an entry into qtBoards using gameId, turn=0 (no moves yet), fGetNewBoard
$loB = new oBoard();
$laBoard = serialize($loB->fGetNewBoard());
$query = "INSERT INTO qtBoards (qfGameId, qfTurnNum, qfBoardArray) VALUES ('$lsGameId', 0, '$laBoard')";
mysql_query($query);
return($lsPlayerTwoId);
}//end-meth fRegisterGame
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fIsPlayersTurn($lsId){
//select id1, id2, turn where oneId = lsId or Twoid = lsId
//if id1 = lsId and turn =1 TRUE
//elseif id2 = lsId and turn =2 TRUE
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfPlayerOneId, qfPlayerTwoId, qfTurn FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsId' OR qfPlayerTwoId = '$lsId'";
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
if (($laTable[0][0]==$lsId)AND($laTable[0][2]==1)OR($laTable[0][1]==$lsId)AND($laTable[0][2]==2)) return(TRUE);
else return(FALSE);
}//end-meth
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fPlayerIsFirst($lsId){
//select id1, id2, turn where oneId = lsId or Twoid = lsId
//if id1 = lsId and turn =1 TRUE
//elseif id2 = lsId and turn =2 TRUE
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfPlayerOneId, qfPlayerTwoId, qfTurn FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsId' OR qfPlayerTwoId = '$lsId'";
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
if (($laTable[0][0]==$lsId)AND($laTable[0][2]==1)) return(TRUE);
else return(FALSE);
}//end-meth
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
}//end-class oRegistration
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?>
##########################################################################################
######################### SMC CS85 CHESS PROGRAM #########################################
##########################################################################################
if ($ulShowVersions) print('
#### oStorage.rpq ########################################################################<br />
// modified comments
#### 2005.11.09 22:00 - km Table qtForum now supports unicode. ############<br />
#### 2005.11.07 03:00 - km oReg->fGetNameFromId now works with either column. ############<br />
#### 2005.11.06 18:00 - km added oReg->fPlayerIsFirst($lsId). ###############<br />');
#### 2005.11.05 09:15 - km repaired ..fGetGameFromId($lsId). ###############
#### 2005.11.05 00:05 - km added oReg..fGetGameFromId($lsId). ###############
#### 2005.11.04 01:30 - km added oReg..fIsPlayersTurn($lsId). ###############
#### 2005.11.03 05:45 - km finished: fRegisterGame. ###############
#### 2005.11.03 05:45 - km added/finished: fGetOtherId, fGetNameFromId, fGetIdFromName. ##
#### 2005.11.01 17:00 - km ###############
#### 2005.10.31 04:15 - km working on oReg->fRegisterGame. ###############
#### 2005.10.31 04:15 - km MODIFIED TABLE qtRegisteredGames. ###############
#### 2005.10.31 00:20 - km DELETED UNUSED TABLE qtPlayers. ###############
#### 2005.10.30 02:15 - km added fGetOwner to oRegistration. ###############
#### 2005.10.29 02:30 - km added oRegistration->fGetOtherPlayers($lsId). ###############
#### 2005.10.28 20:45 - km added oRegistration->fIsNameAvail($lsTestName). ###############
#### 2005.10.27 06:45 - km modified oId to work multiple times. ###############
#### 2005.10.27 06:45 - km CREATED oRegistration object. ###############
#### 2005.10.26 22:40 - km modified to support new oServer object ! ! ###############
#### 2005.10.26 19:40 - km added $ulShowVersions for testing. ###############
#### 2005.10.26 18:40 - km - added definitions. #####
#### 2005.10.24 11:15 - km - reformatted title block. #####
#### 2005.10.23 06:10 - km - now requires sConnect.rsp #####
#### 2005.10.22 04:50 - km completed oId object to create unique ID's. #####
#### 2005.10.21 15:40 - added oId object specs #####
#### 2005.10.20 21:00 - (same as 20:09) km - NO EDIT Req'd for VAR NAMES conventions #####
#### 2005.10.20 20:09 - km edited variable names - New variable naming conventions! ######
#### 2005.10.20 18:20 - km added oStore->fStoreThing & fRestoreThing specs ###############
#### 2005.10.17 19:00 - km added oStore spec #############################################
#### 2005.10.17 03:00 - km added Title block #############################################
##########################################################################################
##########################################################################################
#### Status: Partially available to edit #################################################
#### Object oId is DONE ! #################################################
##########################################################################################
##########################################################################################
#### Description: ####################################
#### ####################################
#### ######################
##########################################################################################
##########################################################################################
#### Agenda: #############################################################################
#### [ ] SQL Serializer Object for objects and arrays #################################
#### [ ] SQL Serializer Object for objects and arrays #################################
#### [] Player deserializer (from log-in, finds current game and deser's obj's) ######
#### (oGame and oBoard) ######
#### [ ] oStorage // Contains all generic functions ######
#### eg. call: oAbstractStorage::fLoginUser($lsUserId) ######
#### Note, this call doesn't require an instance to exist, ######
#### It's just a convenient place to store our misc sql funcs. ######
##########################################################################################
##########################################################################################
############################################ TEST STATUS: #################
############################################ No testing has been done. #################
##########################################################################################
##########################################################################################
#### Programmers: Kristal McKinstry, ######################
##########################################################################################
##########################################################################################
#~~~~PROGRAMMER NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Author ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# {notes here}
# {etc. etc. etc}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Other Author ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# {notes here}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##########################################################################################
##########################################################################################
/*
..oStorage
....uses:
......fSaveGame (lsGameId, laNewBoard, laGameStatus)
......gGetGame (lsGameId)
....methods:
......fConstructNew // default, does nothing.
......fStoreThing (lsUsedId, , lsEnvId, &ThingRef) // stores objects and arrays.
// These functions will be a bit more complex because you will need to test if an entry (row record) already exists
// for that combo of userId & envId, then update or delete&insert if so.
// pseudo-code $a = serialize(laArray)
// pseudo-code ('INSERT INTO qtChessData (qfUsedId, qfEnvId, qfArray) VALUES ($lsUserId, , $lsEnvId, $a)))
......fRestoreThing (lsUsedId, , lsEnvId)
........returns original object (by reference if possible).
// pseudo-code return(unserialize('select qfArray from qtChessData where qfUserId==$lsUserId and qfEnvId==$lsEnvId));
..oId
....methods:
......fGetUniqueId(lsType) // returns lowest available Id (AAAAAA) of that type after inserting row.
Tables:
CREATE TABLE `qtIds` (
`qfUID` INT( 9 ) NOT NULL AUTO_INCREMENT ,
`qfType` CHAR( 12 ) DEFAULT 'zilch' NOT NULL ,
`qfVal` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfCreateDate` INT( 9 ) NOT NULL ,
PRIMARY KEY ( `qfUID` )
) TYPE = MYISAM ;
INSERT INTO `qtIds` (qfType, qfVal) VALUES ('lsUserId', 'AAAAAA')
lsUserId, lsEnvId, and lsGameId can all have values of that same format, eg. AAAACJ
CREATE TABLE `qtRegisteredGames` (
`qfUID` INT( 9 ) NOT NULL AUTO_INCREMENT ,
`qfPlayerOneId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfLongNameOne` CHAR( 20 ) UNICODE DEFAULT 'zilch' NOT NULL ,
`qfPlayerTwoId` CHAR( 6 ) UNICODE DEFAULT 'zilch' NOT NULL ,
`qfLongNameTwo` CHAR( 20 ) DEFAULT 'zilch' NOT NULL ,
`qfTurn` INT( 1 ) DEFAULT '0' NOT NULL ,
`qfGameId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfWinner` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfLastBoard` INT( 4 ) DEFAULT '0' ,
PRIMARY KEY ( `qfUID` )
) TYPE = MYISAM ;
CREATE TABLE `qtForum` (
`qfUID` INT( 9 ) NOT NULL AUTO_INCREMENT ,
`qfFromId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfToId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfPublic` INT( 1 ) DEFAULT '0' NOT NULL ,
`qfDateTime` INT( 10 ) DEFAULT '0' NOT NULL ,
`qfComment` MEDIUMTEXT UNICODE NOT NULL ,
PRIMARY KEY ( `qfUID` )
) TYPE = MYISAM ;
CREATE TABLE `qtBoards` (
`qfUID` INT( 9 ) NOT NULL AUTO_INCREMENT ,
`qfGameId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfTurnNum` INT( 4 ) DEFAULT '0' NOT NULL ,
`qfBoardArray` MEDIUMTEXT NOT NULL ,
PRIMARY KEY ( `qfUID` )
) TYPE = MYISAM ;
..laMove
....liPlayer, laFrom, laTo, lsSpecialMove
..liSubmitter [1,2] // Which player has submitted refresh?
..liTurn [1,2] // Whose turn is it?
*/
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class oId {
var $voServer;
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function oId (&$loServer){
$this->voServer = $loServer;
}//end-meth oId
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fGetUniqueId($lsType){ //worked
// Creates next unique ID of proper type, inserts in DB and returns generated ID for use in creating rows in other tables.
//Types: userId, gameId
// PART A - Get existing ID values
##printf("MySQL server version: %s\n", mysql_get_server_info()); //works. basic connect test.
##echo "<br /> fGetUnique is using server $this->voServer <br />";####@@@@
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfVal FROM qtIds WHERE qfType = '$lsType' ORDER BY qfVal";
$lsQueryHandle = mysql_query($query);
$liX = 0;
while ($temp = mysql_fetch_row ($lsQueryHandle)) {
$laTable[$liX] = array($temp[0]); // replacement
$liX++;
}
####exhibit_array($laTable);
// PART B - Determine next ID.
// Find first empty slot eg. If elements are AAAAAA, AAAAAC then creates AAAAAB
// Two functions reqd for PART B:
if (!function_exists('lfMakeNextAlpha')){ // BECAUSE APPARENTLY FUNCTIONS WITHIN METHODS OF CLASSES BECOME GLOBAL.
function lfMakeNextAlpha($lsCurrent){
for($i=0; $i<6; $i++)
$laChars[$i] = substr($lsCurrent, $i, 1);
$laChars[5] = chr(ord($laChars[5]) +1);
If ($laChars[5]>'Z') {
$laChars[5] = 'A';
$laChars[4] = chr(ord($laChars[4]) +1);
If ($laChars[4]>'Z') {
$laChars[4] = 'A';
$laChars[3] = chr(ord($laChars[3]) +1);
If ($laChars[3]>'Z') {
$laChars[3] = 'A';
$laChars[2] = chr(ord($laChars[2]) +1);
If ($laChars[2]>'Z') {
$laChars[2] = 'A';
$laChars[1] = chr(ord($laChars[1]) +1);
If ($laChars[1]>'Z') {
$laChars[1] = 'A';
$laChars[0] = chr(ord($laChars[0]) +1);
} } } } }//end-5if's
return(implode('', $laChars));
}//end-func lfMakeNextAlpha
}//end-if!exists
if (!function_exists('lfIsNextAlpha')){
function lfIsNextAlpha ($lsCurrent, $lsNext) {
if ($lsNext == lfMakeNextAlpha($lsCurrent)) {
return TRUE;
}
else {
return FALSE;
}
}//end-func lfIsNextAlpha
}//end-if!exists
$lsTempId = 'AAAAAA';
if (isset($laTable)) { // if 1st exists... Else Use unchanged $lsTempId 'AAAAAA'. (if (count($laTable)>0) Fails when table empty).
reset($laTable); //start at beginning
if (count($laTable)>1) { // if next exists...
While (TRUE) {
$lsCurrent = current($laTable);
$lsCurrent = $lsCurrent[0];
$lsNext = next($laTable); // !! This skips pointer ahead to become current in line above after continuing while.
$lsNext = $lsNext[0];
if (lfIsNextAlpha($lsCurrent, $lsNext)) {
continue; //SKIP AND GO AGAIN
} //end-if lfIsNextAlpha
else { // Wasn't NextAlpha
$lsTempId = lfMakeNextAlpha($lsCurrent); // Empty slot; THIS IS WHERE ID IS CREATED (except for new table)
break;
} //end-else Wasn't NextAlpha
} //end-while
} // end-if next exists
else { // next didn't exist
$lsTempId = 'AAAAAB';
} // end-else next didn't exist
} //end-if 1st exists
// PART C - Write new ID into table.
$query = "INSERT INTO `qtIds` (qfType, qfVal) VALUES ('$lsType', '$lsTempId')";
mysql_query($query);
// PART D - return newly written Unique ID.
return($lsTempId);
} //end-meth fGetUniqueId
} //end-class oId
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class oRegistration {
// The Registered Users Table qtRegisteredGames:
// Fields: qfPlayer (char 6), qfLongName (char 20), qfGame (char 6), qfWinner (char 6)
// Separate records per player until second player is assigned to first record.
// Player available if no game assigned.
// Don't delete records when game ends. (to keep track of winners).
/* CURRENT !!
CREATE TABLE `qtRegisteredGames` (
`qfUID` INT( 9 ) NOT NULL AUTO_INCREMENT ,
`qfPlayerOneId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfLongNameOne` CHAR( 20 ) DEFAULT 'zilch' NOT NULL ,
`qfPlayerTwoId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfLongNameTwo` CHAR( 20 ) DEFAULT 'zilch' NOT NULL ,
`qfTurn` INT( 1 ) DEFAULT '0' NOT NULL ,
`qfGameId` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfWinner` CHAR( 6 ) DEFAULT 'zilch' NOT NULL ,
`qfLastBoard` INT( 4 ) DEFAULT '0' ,
PRIMARY KEY ( `qfUID` )
) TYPE = MYISAM ;
*/
var $voServer;
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function oRegistration (&$loServer){
// Although both players ultimately share one game record, they each have a separate record
// until a game is created and the second record is deleted.
$this->voServer = $loServer;
}//end-meth oRegistration
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fIsNameAvail($lsTestName){ #### NEEDS WORK?
$loId = new oId($this->voServer);
$query = "SELECT DISTINCT qfLongNameOne FROM qtRegisteredGames WHERE qfLongNameOne = '$lsTestName' AND qfGameId = 'zilch'";
$this->voServer->fSelectDB();
$liCount = mysql_num_rows(mysql_query($query));
if ($liCount == 0) return(TRUE);
else return(FALSE);
}//end-meth "fTestName"
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fAddActiveUser ($lsLongName){
##echo $lsLongName;//@@@@
$loId = new oId($this->voServer);
$lsId = $loId->fGetUniqueId('userId');
//Insert userId into qtRegisteredGames
$query = "INSERT INTO `qtRegisteredGames` (qfPlayerOneId, qfLongNameOne) VALUES ('$lsId', '$lsLongName')";
$this->voServer->fSelectDB();
mysql_query($query);
return($lsId);
}//end-meth fAddActiveUser
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fGetOtherPlayers($lsId){
$loId = new oId($this->voServer);
$query = "SELECT ALL qfLongNameOne FROM qtRegisteredGames WHERE qfPlayerOneId != '$lsId' AND qfGameId = 'zilch'"; //worked
$this->voServer->fSelectDB();
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
if ($liX>0) return($laTable);
else return(NULL);
}//end-meth "fGetOtherPlayers"
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fGetOtherId($lsId){
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfPlayerTwoId FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsId'"; //worked
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
##echocall("oReg.fGOI at first found $liX records.");
if ($liX<1){
$query = "SELECT DISTINCT qfPlayerOneId FROM qtRegisteredGames WHERE qfPlayerTwoId = '$lsId'"; //worked
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
##echocall("oReg.fGOI again and found $liX records.");
}//end-if
if ($liX<1){
##echocall('oS_oReg->fGOI. No Other ID existed!'); ####@@@@
$lsOtherId = 'zilch';
}//end-if
else {
$lsOtherId = $laTable[0][0];
##COOL echocall("Called oS->fGOI. OtherID was $lsOtherId");
}//end-else
return($lsOtherId);
}//end-meth
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fGetIdFromName($lsLongName){
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfPlayerOneId FROM qtRegisteredGames WHERE qfLongNameOne = '$lsLongName'";
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
$lsId = $laTable[0][0];
return($lsId);
}//end-meth
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fGetNameFromId($lsId){
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfLongNameOne, qfLongNameTwo, qfPlayerOneId, qfPlayerTwoId FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsId' OR qfPlayerTwoId = '$lsId'";
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
$lsLongName = '!!fGetNameFromId FAILED!!';
if ($laTable[0][2]==$lsId) $lsLongName = $laTable[0][0];
if ($laTable[0][3]==$lsId) $lsLongName = $laTable[0][1];
return($lsLongName);
}//end-meth
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fGetGameFromId($lsId){
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfGameId FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsId' OR qfPlayerTwoId = '$lsId'";
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
$lsGameId = $laTable[0][0];
return($lsGameId);
}//end-meth
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fRegisterGame($loCFV){
// First person to select a partner becomes Player One. Other players qtGames record is deleted.
$lsPlayerOneId = $loCFV->fGetVal('vhPlayer');
$lsLongNameOne = $this->fGetNameFromId($lsPlayerOneId);
$lsLongNameTwo = $loCFV->fGetVal('vsOtherPlayer');
$lsPlayerTwoId = $this->fGetIdFromName($lsLongNameTwo);
$loId = new oId($this->voServer);
$lsGameId = $loId->fGetUniqueId('gameId');
$this->voServer->fSelectDB();
$query = "DELETE FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsPlayerOneId'";
mysql_query($query);
$query = "DELETE FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsPlayerTwoId'";
mysql_query($query);
$query = "INSERT INTO qtRegisteredGames (qfPlayerOneId, qfLongNameOne, qfPlayerTwoId, qfLongNameTwo, qfTurn, qfGameId, qfWinner, qfLastBoard) VALUES ('$lsPlayerOneId', '$lsLongNameOne', '$lsPlayerTwoId', '$lsLongNameTwo', 1, '$lsGameId', 'zilch', 0);";
mysql_query($query);
// Insert an entry into qtBoards using gameId, turn=0 (no moves yet), fGetNewBoard
$loB = new oBoard();
$laBoard = serialize($loB->fGetNewBoard());
$query = "INSERT INTO qtBoards (qfGameId, qfTurnNum, qfBoardArray) VALUES ('$lsGameId', 0, '$laBoard')";
mysql_query($query);
return($lsPlayerTwoId);
}//end-meth fRegisterGame
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fIsPlayersTurn($lsId){
//select id1, id2, turn where oneId = lsId or Twoid = lsId
//if id1 = lsId and turn =1 TRUE
//elseif id2 = lsId and turn =2 TRUE
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfPlayerOneId, qfPlayerTwoId, qfTurn FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsId' OR qfPlayerTwoId = '$lsId'";
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
if (($laTable[0][0]==$lsId)AND($laTable[0][2]==1)OR($laTable[0][1]==$lsId)AND($laTable[0][2]==2)) return(TRUE);
else return(FALSE);
}//end-meth
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function fPlayerIsFirst($lsId){
//select id1, id2, turn where oneId = lsId or Twoid = lsId
//if id1 = lsId and turn =1 TRUE
//elseif id2 = lsId and turn =2 TRUE
$this->voServer->fSelectDB();
$query = "SELECT DISTINCT qfPlayerOneId, qfPlayerTwoId, qfTurn FROM qtRegisteredGames WHERE qfPlayerOneId = '$lsId' OR qfPlayerTwoId = '$lsId'";
list($liX, $laTable) = mysql_fetch_table_array(mysql_query($query));
if (($laTable[0][0]==$lsId)AND($laTable[0][2]==1)) return(TRUE);
else return(FALSE);
}//end-meth
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
}//end-class oRegistration
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?>