PageRenderTime 60ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/View/webchs/chessdb.php

https://bitbucket.org/onlinechessportal/onlinechessgameportal
PHP | 537 lines | 377 code | 82 blank | 78 comment | 107 complexity | 07c6ff05112d44d7dbf07d3eae1decd6 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. // $Id: chessdb.php,v 1.10 2010/08/14 16:57:54 sandking Exp $
  3. /*
  4. This file is part of WebChess. http://webchess.sourceforge.net
  5. Copyright 2010 Jonathan Evraire, Rodrigo Flores
  6. WebChess is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. WebChess is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with WebChess. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /* these functions are used to interact with the DB */
  18. function updateTimestamp()
  19. {
  20. global $CFG_TABLE;
  21. /* old PHP versions don't have _POST, _GET and _SESSION as auto_globals */
  22. if (!minimum_version("4.1.0"))
  23. global $_POST, $_GET, $_SESSION;
  24. mysql_query("UPDATE " . $CFG_TABLE[games] . " SET ga_lastmove = NOW() WHERE ga_gameid = ".$_SESSION['gameID']);
  25. }
  26. function loadHistory()
  27. {
  28. global $CFG_TABLE;
  29. global $history, $numMoves;
  30. /* old PHP versions don't have _POST, _GET and _SESSION as auto_globals */
  31. if (!minimum_version("4.1.0"))
  32. global $_POST, $_GET, $_SESSION;
  33. $allMoves = mysql_query("SELECT * FROM " . $CFG_TABLE[history] . " WHERE hi_gameid = ".$_SESSION['gameID']." ORDER BY hi_timeofmove");
  34. $numMoves = -1;
  35. while ($thisMove = mysql_fetch_array($allMoves, MYSQL_ASSOC))
  36. {
  37. $numMoves++;
  38. $history[$numMoves] = $thisMove;
  39. }
  40. }
  41. function savePromotion()
  42. {
  43. global $CFG_TABLE;
  44. global $history, $numMoves, $isInCheck;
  45. /* old PHP versions don't have _POST, _GET and _SESSION as auto_globals */
  46. if (!minimum_version("4.1.0"))
  47. global $_POST, $_GET, $_SESSION;
  48. if ($isInCheck)
  49. {
  50. $tmpIsInCheck = 1;
  51. $history[$numMoves]['isInCheck'] = 1;
  52. }
  53. else
  54. $tmpIsInCheck = 0;
  55. $history[$numMoves]['promotedTo'] = getPieceName($_POST['promotion']);
  56. $tmpQuery = "UPDATE " . $CFG_TABLE[history] . " SET hi_promotedto = '".getPieceName($_POST['promotion'])."', hi_isIncheck = ".$tmpIsInCheck." WHERE hi_gameid = ".$_SESSION['gameID']." AND hi_timeofmove = '".$history[$numMoves]['timeOfMove']."'";
  57. mysql_query($tmpQuery);
  58. updateTimestamp();
  59. /* if email notification is activated and move does not result in a pawn's promotion... */
  60. if ($CFG_USEEMAILNOTIFICATION && ! $_SESSION['isSharedPC'])
  61. {
  62. if ($history[$numMoves]['replaced'] == null)
  63. $tmpReplaced = '';
  64. else
  65. $tmpReplaced = $history[$numMoves]['replaced'];
  66. /* get opponent's color */
  67. if (($numMoves == -1) || ($numMoves % 2 == 1))
  68. $oppColor = "black";
  69. else
  70. $oppColor = "white";
  71. /* get opponent's player ID */
  72. if ($oppColor == 'white')
  73. $tmpOpponentID = mysql_query("SELECT ga_whiteplayer FROM " . $CFG_TABLE[games] . " WHERE ga_gameid = ".$_SESSION['gameID']);
  74. else
  75. $tmpOpponentID = mysql_query("SELECT ga_blackplayer FROM " . $CFG_TABLE[games] . " WHERE ga_gameid = ".$_SESSION['gameID']);
  76. $opponentID = mysql_result($tmpOpponentID, 0);
  77. /* if opponent is using email notification... */
  78. $tmpOpponentEmail = mysql_query("SELECT value FROM " . $CFG_TABLE[preferences] . " WHERE playerID = ".$opponentID." AND preference = 'emailNotification'");
  79. if (mysql_num_rows($tmpOpponentEmail) > 0)
  80. {
  81. $opponentEmail = mysql_result($tmpOpponentEmail, 0);
  82. if ($opponentEmail != '')
  83. {
  84. /* get opponent's nick */
  85. $tmpOpponentNick = mysql_query("SELECT nick FROM " . $CFG_TABLE[players] . " WHERE playerID = ".$_SESSION['playerID']);
  86. $opponentNick = mysql_result($tmpOpponentNick, 0);
  87. /* get opponent's prefered history type */
  88. $tmpOpponentHistory = mysql_query("SELECT value FROM " . $CFG_TABLE[preferences] . " WHERE playerID = ".$opponentID." AND preference = 'history'");
  89. /* default to PGN */
  90. if (mysql_num_rows($tmpOpponentHistory) > 0)
  91. $opponentHistory = mysql_result($tmpOpponentHistory, 0);
  92. else
  93. $opponentHistory = 'pgn';
  94. /* notify opponent of move via email */
  95. if ($opponentHistory == 'pgn')
  96. webchessMail('move', $opponentEmail, moveToPGNString($history[$numMoves]['curColor'], $history[$numMoves]['curPiece'], $history[$numMoves]['fromRow'], $history[$numMoves]['fromCol'], $history[$numMoves]['toRow'], $history[$numMoves]['toCol'], $tmpReplaced, $history[$numMoves]['promotedTo'], $isInCheck), $opponentNick, $_SESSION['gameID']);
  97. else
  98. webchessMail('move', $opponentEmail, moveToVerbousString($history[$numMoves]['curColor'], $history[$numMoves]['curPiece'], $history[$numMoves]['fromRow'], $history[$numMoves]['fromCol'], $history[$numMoves]['toRow'], $history[$numMoves]['toCol'], $tmpReplaced, $history[$numMoves]['promotedTo'], $isInCheck), $opponentNick, $_SESSION['gameID']);
  99. }
  100. }
  101. }
  102. }
  103. function saveHistory()
  104. {
  105. global $CFG_TABLE;
  106. global $board, $isPromoting, $history, $numMoves, $isInCheck, $CFG_USEEMAILNOTIFICATION;
  107. /* old PHP versions don't have _POST, _GET and _SESSION as auto_globals */
  108. if (!minimum_version("4.1.0"))
  109. global $_POST, $_GET, $_SESSION;
  110. /* set destination row for pawn promotion */
  111. if ($board[$_POST['fromRow']][$_POST['fromCol']] & BLACK)
  112. $targetRow = 0;
  113. else
  114. $targetRow = 7;
  115. /* determine if move results in pawn promotion */
  116. if ((($board[$_POST['fromRow']][$_POST['fromCol']] & COLOR_MASK) == PAWN) && ($_POST['toRow'] == $targetRow))
  117. $isPromoting = true;
  118. else
  119. $isPromoting = false;
  120. /* determine who's playing based on number of moves so far */
  121. if (($numMoves == -1) || ($numMoves % 2 == 1))
  122. {
  123. $curColor = "white";
  124. $oppColor = "black";
  125. }
  126. else
  127. {
  128. $curColor = "black";
  129. $oppColor = "white";
  130. }
  131. /* add move to history */
  132. $numMoves++;
  133. $history[$numMoves]['gamedID'] = $_SESSION['gameID'];
  134. $history[$numMoves]['curPiece'] = getPieceName($board[$_POST['fromRow']][$_POST['fromCol']]);
  135. $history[$numMoves]['curColor'] = $curColor;
  136. $history[$numMoves]['fromRow'] = $_POST['fromRow'];
  137. $history[$numMoves]['fromCol'] = $_POST['fromCol'];
  138. $history[$numMoves]['toRow'] = $_POST['toRow'];
  139. $history[$numMoves]['toCol'] = $_POST['toCol'];
  140. $history[$numMoves]['promotedTo'] = null;
  141. if ($isInCheck)
  142. $history[$numMoves]['isInCheck'] = 1;
  143. else
  144. $history[$numMoves]['isInCheck'] = 0;
  145. if (DEBUG)
  146. {
  147. if ($history[$numMoves]['curPiece'] == '')
  148. echo ("WARNING!!! missing piece at ".$_POST['fromRow'].", ".$_POST['fromCol'].": ".$board[$_POST['fromRow']][$_POST['fromCol']]."<p>\n");
  149. }
  150. if ($board[$_POST['toRow']][$_POST['toCol']] == 0)
  151. {
  152. $tmpQuery = "INSERT INTO " . $CFG_TABLE[history] . " (hi_timeofmove, hi_gameid, hi_curpiece, hi_curcolor, hi_fromrow, hi_fromcol, hi_torow, hi_tocol, hi_replaced, hi_promotedto, hi_isIncheck) VALUES (Now(), ".$_SESSION['gameID'].", '".getPieceName($board[$_POST['fromRow']][$_POST['fromCol']])."', '$curColor', ".$_POST['fromRow'].", ".$_POST['fromCol'].", ".$_POST['toRow'].", ".$_POST['toCol'].", null, null, ".$history[$numMoves]['isInCheck'].")";
  153. $history[$numMoves]['replaced'] = null;
  154. $tmpReplaced = "";
  155. }
  156. else
  157. {
  158. $tmpQuery = "INSERT INTO " . $CFG_TABLE[history] . " (hi_timeofmove, hi_gameid, hi_curpiece, hi_curcolor, hi_fromrow, hi_fromcol, hi_torow, hi_tocol, hi_replaced, hi_promotedto, hi_isIncheck) VALUES (Now(), ".$_SESSION['gameID'].", '".getPieceName($board[$_POST['fromRow']][$_POST['fromCol']])."', '$curColor', ".$_POST['fromRow'].", ".$_POST['fromCol'].", ".$_POST['toRow'].", ".$_POST['toCol'].", '".getPieceName($board[$_POST['toRow']][$_POST['toCol']])."', null, ".$history[$numMoves]['isInCheck'].")";
  159. $history[$numMoves]['replaced'] = getPieceName($board[$_POST['toRow']][$_POST['toCol']]);
  160. $tmpReplaced = $history[$numMoves]['replaced'];
  161. }
  162. mysql_query($tmpQuery);
  163. /* if email notification is activated and move does not result in a pawn's promotion... */
  164. /* NOTE: moves resulting in pawn promotion are handled by savePromotion() above */
  165. if ($CFG_USEEMAILNOTIFICATION && !$isPromoting && ! $_SESSION['isSharedPC'])
  166. {
  167. /* get opponent's player ID */
  168. if ($oppColor == 'white')
  169. $tmpOpponentID = mysql_query("SELECT ga_whiteplayer FROM " . $CFG_TABLE[games] . " WHERE ga_gameid = ".$_SESSION['gameID']);
  170. else
  171. $tmpOpponentID = mysql_query("SELECT ga_blackplayer FROM " . $CFG_TABLE[games] . " WHERE ga_gameid = ".$_SESSION['gameID']);
  172. $opponentID = mysql_result($tmpOpponentID, 0);
  173. }
  174. }
  175. function loadGame()
  176. {
  177. global $CFG_TABLE;
  178. global $board, $playersColor;
  179. /* old PHP versions don't have _POST, _GET and _SESSION as auto_globals */
  180. if (!minimum_version("4.1.0"))
  181. global $_POST, $_GET, $_SESSION;
  182. /* clear board data */
  183. for ($i = 0; $i < 8; $i++)
  184. for ($j = 0; $j < 8; $j++)
  185. $board[$i][$j] = 0;
  186. /* get data from database */
  187. $pieces = mysql_query("SELECT * FROM " . $CFG_TABLE[pieces] . " WHERE pi_gameid= ".$_SESSION['gameID']);
  188. /* setup board */
  189. while ($thisPiece = mysql_fetch_array($pieces, MYSQL_ASSOC))
  190. {
  191. $board[$thisPiece["pi_row"]][$thisPiece["pi_col"]] = getPieceCode($thisPiece["pi_color"], $thisPiece["pi_piece"]);
  192. }
  193. /* get current player's color */
  194. $tmpQuery = "SELECT ga_whiteplayer, ga_blackplayer FROM " . $CFG_TABLE[games] . " WHERE ga_gameid = ".$_SESSION['gameID'];
  195. $tmpTurns = mysql_query($tmpQuery);
  196. $tmpTurn = mysql_fetch_array($tmpTurns, MYSQL_ASSOC);
  197. if ($tmpTurn['ga_whiteplayer'] == $_SESSION['playerID'])
  198. $playersColor = "white";
  199. else
  200. $playersColor = "black";
  201. }
  202. function saveGame()
  203. {
  204. global $CFG_TABLE;
  205. global $board, $playersColor;
  206. /* old PHP versions don't have _POST, _GET and _SESSION as auto_globals */
  207. if (!minimum_version("4.1.0"))
  208. global $_POST, $_GET, $_SESSION;
  209. /* clear old data */
  210. mysql_query("DELETE FROM " . $CFG_TABLE[pieces] . " WHERE pi_gameid = ".$_SESSION['gameID']);
  211. /* save new game data */
  212. /* for each row... */
  213. for ($i = 0; $i < 8; $i++)
  214. {
  215. /* for each col... */
  216. for ($j = 0; $j < 8; $j++)
  217. {
  218. /* if there's a piece at that pos on the board */
  219. if ($board[$i][$j] != 0)
  220. {
  221. /* updated the database */
  222. if ($board[$i][$j] & BLACK)
  223. $tmpColor = "black";
  224. else
  225. $tmpColor = "white";
  226. $tmpPiece = getPieceName($board[$i][$j]);
  227. mysql_query("INSERT INTO " . $CFG_TABLE[pieces] . " (pi_gameid, pi_color, pi_piece, pi_row, pi_col) VALUES (".$_SESSION['gameID'].", '$tmpColor', '$tmpPiece', $i, $j)");
  228. }
  229. }
  230. }
  231. /* update lastMove timestamp */
  232. updateTimestamp();
  233. }
  234. function processMessages()
  235. {
  236. global $CFG_TABLE;
  237. global $isUndoRequested, $isDrawRequested, $isUndoing, $isGameOver, $isCheckMate, $playersColor, $numMoves, $statusMessage, $CFG_USEEMAILNOTIFICATION;
  238. /* old PHP versions don't have _POST, _GET and _SESSION as auto_globals */
  239. if (!minimum_version("4.1.0"))
  240. global $_POST, $_GET, $_SESSION;
  241. if (DEBUG)
  242. echo("Entering processMessages()<br>\n");
  243. $isUndoRequested = false;
  244. $isGameOver = false;
  245. /* find out which player (black or white) we are serving */
  246. /* NOTE: When playing in the same computer $playersColor is always the player who logged in first */
  247. if (DEBUG)
  248. echo("SharedPC..." . $_SESSION['isSharedPC'] . "<br>\n");
  249. if ($_SESSION['isSharedPC']) // Only the player to move is active in this case
  250. if( ( (($numMoves == -1) || (($numMoves % 2) == 1)) && ($playersColor == "white")) ||
  251. ((($numMoves % 2) == 0) && ($playersColor == "black")) )
  252. $currentPlayer = $playersColor;
  253. else // The player who logged in later is to move
  254. if($playersColor == "white")
  255. $currentPlayer = "black";
  256. else
  257. $currentPlayer = "white";
  258. else // The players are on different computers
  259. $currentPlayer = $playersColor;
  260. if ($currentPlayer == "white")
  261. $opponentColor = "black";
  262. else
  263. $opponentColor = "white";
  264. /* *********************************************** */
  265. /* queue user generated (ie: using forms) messages */
  266. /* *********************************************** */
  267. if (DEBUG)
  268. echo("Processing user generated (ie: form) messages...<br>\n");
  269. /* queue a request for an undo */
  270. if ($_POST['requestUndo'] == "yes")
  271. {
  272. /* if the two players are on the same system, execute undo immediately */
  273. /* NOTE: assumes the two players discussed it live before undoing */
  274. if ($_SESSION['isSharedPC'])
  275. $isUndoing = true;
  276. else
  277. {
  278. $tmpQuery = "INSERT INTO messages (me_gameid, me_msgtype, me_msgstatus, me_destination) VALUES (".$_SESSION['gameID'].", 'undo', 'request', '".$opponentColor."')";
  279. mysql_query($tmpQuery);
  280. // ToDo: Mail an undo request notice to other player??
  281. }
  282. updateTimestamp();
  283. }
  284. /* queue a request for a draw */
  285. if ($_POST['requestDraw'] == "yes")
  286. {
  287. /* if the two players are on the same system, execute Draw immediately */
  288. /* NOTE: assumes the two players discussed it live before declaring the game a draw */
  289. if ($_SESSION['isSharedPC'])
  290. {
  291. $tmpQuery = "UPDATE games SET ga_gamemessage = 'draw', ga_messagefrom = '".$currentPlayer."' WHERE ga_gameid = ".$_SESSION['gameID'];
  292. mysql_query($tmpQuery);
  293. }
  294. else
  295. {
  296. $tmpQuery = "INSERT INTO messages (me_gameid, me_msgtype, me_msgstatus, me_destination) VALUES (".$_SESSION['gameID'].", 'draw', 'request', '".$opponentColor."')";
  297. mysql_query($tmpQuery);
  298. }
  299. updateTimestamp();
  300. }
  301. /* response to a request for an undo */
  302. if (isset($_POST['undoResponse']))
  303. {
  304. if ($_POST['isUndoResponseDone'] == 'yes')
  305. {
  306. if ($_POST['undoResponse'] == "yes")
  307. {
  308. $tmpStatus = "approved";
  309. $isUndoing = true;
  310. }
  311. else
  312. $tmpStatus = "denied";
  313. $tmpQuery = "UPDATE messages SET me_msgstatus = '".$tmpStatus."', me_destination = '".$opponentColor."' WHERE me_gameid = ".$_SESSION['gameID']." AND me_msgtype = 'undo' AND me_msgstatus = 'request' AND me_destination = '".$currentPlayer."'";
  314. mysql_query($tmpQuery);
  315. updateTimestamp();
  316. }
  317. }
  318. /* response to a request for a draw */
  319. if (isset($_POST['drawResponse']))
  320. {
  321. if ($_POST['isDrawResponseDone'] == 'yes')
  322. {
  323. if ($_POST['drawResponse'] == "yes")
  324. {
  325. $tmpStatus = "approved";
  326. $tmpQuery = "UPDATE games SET ga_gameMmssage = 'draw', ga_messagefrom = '".$currentPlayer."' WHERE ga_gameid = ".$_SESSION['gameID'];
  327. mysql_query($tmpQuery);
  328. }
  329. else
  330. $tmpStatus = "denied";
  331. $tmpQuery = "UPDATE messages SET me_msgstatus = '".$tmpStatus."', me_destination = '".$opponentColor."' WHERE me_gameid = ".$_SESSION['gameID']." AND me_msgtype = 'draw' AND me_msgstatus = 'request' AND me_destination = '".$currentPlayer."'";
  332. mysql_query($tmpQuery);
  333. updateTimestamp();
  334. }
  335. }
  336. /* resign the game */
  337. if ($_POST['resign'] == "yes")
  338. {
  339. $tmpQuery = "UPDATE " . $CFG_TABLE[games] . " SET ga_gamemessage = 'playerResigned', ga_messagefrom = '".$currentPlayer."' WHERE ga_gameid = ".$_SESSION['gameID'];
  340. mysql_query($tmpQuery);
  341. updateTimestamp();
  342. /* if email notification is activated... */
  343. if ($CFG_USEEMAILNOTIFICATION && ! $_SESSION['isSharedPC'])
  344. {
  345. /* get opponent's player ID */
  346. if ($currentPlayer == 'white')
  347. $tmpOpponentID = mysql_query("SELECT ga_blackplayer FROM " . $CFG_TABLE[games] . " WHERE ga_gameid = ".$_SESSION['gameID']);
  348. else
  349. $tmpOpponentID = mysql_query("SELECT ga_whiteplayer FROM " . $CFG_TABLE[games] . " WHERE ga_gameid = ".$_SESSION['gameID']);
  350. $opponentID = mysql_result($tmpOpponentID, 0);
  351. $tmpOpponentEmail = mysql_query("SELECT value FROM " . $CFG_TABLE[preferences] . " WHERE playerID = ".$opponentID." AND preference = 'emailNotification'");
  352. /* if opponent is using email notification... */
  353. if (mysql_num_rows($tmpOpponentEmail) > 0)
  354. {
  355. $opponentEmail = mysql_result($tmpOpponentEmail, 0);
  356. if ($opponentEmail != '')
  357. {
  358. /* notify opponent of resignation via email */
  359. webchessMail('resignation', $opponentEmail, '', $_SESSION['nick'], $_SESSION['gameID']);
  360. }
  361. }
  362. }
  363. }
  364. /* ******************************************* */
  365. /* process queued messages (ie: from database) */
  366. /* ******************************************* */
  367. $tmpQuery = "SELECT * FROM messages WHERE me_gameid = ".$_SESSION['gameID']." AND me_destination = '".$currentPlayer."'";
  368. $tmpMessages = mysql_query($tmpQuery);
  369. while($tmpMessage = mysql_fetch_array($tmpMessages, MYSQL_ASSOC))
  370. {
  371. switch($tmpMessage['msgType'])
  372. {
  373. case 'undo':
  374. switch($tmpMessage['msgStatus'])
  375. {
  376. case 'request':
  377. $isUndoRequested = true;
  378. break;
  379. case 'approved':
  380. $tmpQuery = "DELETE FROM messages WHERE me_gameid = ".$_SESSION['gameID']." AND me_msgtype = 'undo' AND me_msgstatus = 'approved' AND me_destination = '".$currentPlayer."'";
  381. mysql_query($tmpQuery);
  382. $statusMessage .= "Undo approved";
  383. break;
  384. case 'denied':
  385. $isUndoing = false;
  386. $tmpQuery = "DELETE FROM messages WHERE me_gameid = ".$_SESSION['gameID']." AND me_msgtype = 'undo' AND me_msgstatus = 'denied' AND me_destination = '".$currentPlayer."'";
  387. mysql_query($tmpQuery);
  388. $statusMessage .= "Undo denied";
  389. break;
  390. }
  391. break;
  392. case 'draw':
  393. switch($tmpMessage['msgStatus'])
  394. {
  395. case 'request':
  396. $isDrawRequested = true;
  397. break;
  398. case 'approved':
  399. $tmpQuery = "DELETE FROM messages WHERE me_gameid = ".$_SESSION['gameID']." AND me_msgtype = 'draw' AND me_msgstatus = 'approved' AND me_destination = '".$currentPlayer."'";
  400. mysql_query($tmpQuery);
  401. $statusMessage .= "Draw approved";
  402. break;
  403. case 'denied':
  404. $tmpQuery = "DELETE FROM messages WHERE me_gameid = ".$_SESSION['gameID']." AND me_msgtype = 'draw' AND me_msgstatus = 'denied' AND me_destination = '".$currentPlayer."'";
  405. mysql_query($tmpQuery);
  406. $statusMessage .= "Draw denied";
  407. break;
  408. }
  409. break;
  410. }
  411. }
  412. /* requests pending */
  413. $tmpQuery = "SELECT * FROM messages WHERE me_gameid = ".$_SESSION['gameID']." AND me_msgstatus = 'request' AND me_destination = '".$opponentColor."'";
  414. $tmpMessages = mysql_query($tmpQuery);
  415. while($tmpMessage = mysql_fetch_array($tmpMessages, MYSQL_ASSOC))
  416. {
  417. switch($tmpMessage['msgType'])
  418. {
  419. case 'undo':
  420. $statusMessage .= "Your undo request is pending";
  421. break;
  422. case 'draw':
  423. $statusMessage .= "Your request for a draw is pending";
  424. break;
  425. }
  426. }
  427. /* game level status: draws, resignations and checkmate */
  428. /* if checkmate, update games table */
  429. if ($_POST['isCheckMate'] == 'true')
  430. mysql_query("UPDATE games SET ga_gamemessage = 'checkMate', ga_messagefrom = '".$currentPlayer."' WHERE ga_gameid = ".$_SESSION['gameID']);
  431. // ToDo: Mail checkmate notification to opponent
  432. $tmpQuery = "SELECT ga_gamemessage, ga_messagefrom FROM games WHERE ga_gameid = ".$_SESSION['gameID'];
  433. $tmpMessages = mysql_query($tmpQuery);
  434. $tmpMessage = mysql_fetch_array($tmpMessages, MYSQL_ASSOC);
  435. if ($tmpMessage['ga_gamemessage'] == "draw")
  436. {
  437. $statusMessage .= "Game ended in a draw";
  438. $isGameOver = true;
  439. }
  440. if ($tmpMessage['ga_gamemessage'] == "playerResigned")
  441. {
  442. $statusMessage .= $tmpMessage['ga_messagefrom']." has resigned the game";
  443. $isGameOver = true;
  444. }
  445. if ($tmpMessage['ga_gamemessage'] == "checkMate")
  446. {
  447. $statusMessage .= "Checkmate! ".$tmpMessage['ga_messagefrom']." has won the game";
  448. $isGameOver = true;
  449. $isCheckMate = true;
  450. }
  451. }
  452. ?>