session_start(); /* load settings */ if (!isset($_CONFIG)) require 'config.php'; /* define constants */ require 'chessconstants.php'; /* include outside functions */ if (!isset($_CHESSUTILS)) require 'chessutils.php'; require 'gui.php'; require 'chessdb.php'; require 'move.php'; require 'undo.php'; /* allow WebChess to be run on PHP systems < 4.1.0, using old http vars */ fixOldPHPVersions(); /* check session status */ require 'sessioncheck.php'; /* check if loading game */ if (isset($_POST['gameID'])) $_SESSION['gameID'] = $_POST['gameID']; /* debug flag */ define ("DEBUG", 0); /* connect to database */ require 'connectdb.php'; /* load game */ $isInCheck = ($_POST['isInCheck'] == 'true'); $isCheckMate = false; $isPromoting = false; $isUndoing = false; loadHistory(); loadGame(); processMessages(); if ($isUndoing) { doUndo(); saveGame(); } elseif (($_POST['promotion'] != "") && ($_POST['toRow'] != "") && ($_POST['toCol'] != "")) { savePromotion(); $board[$_POST['toRow']][$_POST['toCol']] = $_POST['promotion'] | ($board[$_POST['toRow']][$_POST['toCol']] & BLACK); saveGame(); } elseif (($_POST['fromRow'] != "") && ($_POST['fromCol'] != "") && ($_POST['toRow'] != "") && ($_POST['toCol'] != "")) { /* ensure it's the current player moving */ /* NOTE: if not, this will currently ignore the command... */ /* perhaps the status should be instead? */ /* (Could be confusing to player if they double-click or something */ $tmpIsValid = true; if (($numMoves == -1) || ($numMoves % 2 == 1)) { /* White's move... ensure that piece being moved is white */ if ((($board[$_POST['fromRow']][$_POST['fromCol']] & BLACK) != 0) || ($board[$_POST['fromRow']][$_POST['fromCol']] == 0)) /* invalid move */ $tmpIsValid = false; } else { /* Black's move... ensure that piece being moved is black */ if ((($board[$_POST['fromRow']][$_POST['fromCol']] & BLACK) != BLACK) || ($board[$_POST['fromRow']][$_POST['fromCol']] == 0)) /* invalid move */ $tmpIsValid = false; } if ($tmpIsValid) { saveHistory(); doMove(); saveGame(); } } mysql_close(); ?>
/* find out if it's the current player's turn */ if (( (($numMoves == -1) || (($numMoves % 2) == 1)) && ($playersColor == "white")) || ((($numMoves % 2) == 0) && ($playersColor == "black"))) $isPlayersTurn = true; else $isPlayersTurn = false; if ($_SESSION['isSharedPC']) echo("|
Note: when castling, just move the king (the rook will move automatically). |
writeStatus(); ?>
writeHistory(); ?> |