function mobile_get_game_update_on_state_change($xsid) { //$session = base64_decode($xsid); //list($uniq, $player_id) = preg_split("/\|/", $session); if ($_GET['gameid'] != "") { $game_id = $_GET['gameid']; try { $dbh = CSession::$dbh; $side_to_move = $_GET['side_to_move']; $get_game_over = (bool) $_GET['get_game_over']; $get_new_move = (bool) $_GET['get_new_move']; $with_full_update = (bool) $_GET['with_full_update']; $require_full_update = FALSE; $new_move = FALSE; // Work out whose turn it is. $player_w = -1; $player_b = -1; $next_move = ''; $stmt = $dbh->prepare("SELECT `w_player_id`,`b_player_id`,`next_move` FROM `game` WHERE `game_id` = ?"); $stmt->bind_param('s', $game_id); if ($stmt->execute()) { $stmt->bind_result($player_w, $player_b, $next_move); $result = $stmt->fetch(); if ($result) { if ($next_move == NULL) { $next_move = 'w'; } // Game creation does not initially set a next move value. Assume white to move as custom game setup isn't yet implemented. } $stmt->close(); } else { echo "<ERROR>Database Error</ERROR>\n"; return false; } if ($get_new_move) { //echo "next $next_move , side $side_to_move"; if ($next_move != $side_to_move) { echo "<NEW_MOVE>true</NEW_MOVE>\n"; $new_move = TRUE; $require_full_update = TRUE; } else { echo "<NEW_MOVE>false</NEW_MOVE>\n"; } } if ($get_game_over) { // See if the game is over (because the opponent resigned, there was a draw or a player won). $game_result = 0; $stmt = $dbh->prepare("SELECT `completion_status` FROM `game` WHERE `game_id` = ?"); $stmt->bind_param('s', $game_id); if ($stmt->execute()) { $stmt->bind_result($status); $result = $stmt->fetch(); if ($result) { if ($status == "W") { $game_result = 1; } elseif ($status == "B") { $game_result = 2; } elseif ($status == "D") { $game_result = 3; } } $stmt->close(); } else { echo "<ERROR>Database Error</ERROR>\n"; return false; } if ($game_result != 0) { echo "<GAME_OVER>true</GAME_OVER>\n"; $require_full_update = TRUE; } else { echo "<GAME_OVER>false</GAME_OVER>\n"; } } if ($require_full_update && $with_full_update) { // There might be cases where we only want to know if a move was made or the game is over without the details of the game state. mobile_get_full_game_update(); } if ($new_move) { $move = ChessHelper::get_last_move(); echo "<MOVE_SAN>" . $move['SAN'] . "</MOVE_SAN>\n"; echo "<MOVE_FROM>" . $move['from'] . "</MOVE_FROM>\n"; echo "<MOVE_TO>" . $move['to'] . "</MOVE_TO>\n"; } // Return the draw status. $session = base64_decode($xsid); list($uniq, $player_id) = preg_split("/\\|/", $session); $oR3DCQuery = new CR3DCQuery($Root_Path . "bin/config.php"); $isblack = $oR3DCQuery->IsPlayerBlack($Root_Path . "bin/config.php", $game_id, $player_id); $isdraw = $oR3DCQuery->IsRequestDraw($Root_Path . "bin/config.php", $game_id, $isblack); echo "<DRAWCODE>"; echo $isdraw; echo "</DRAWCODE>\n"; } catch (mysqli_sql_exception $e) { echo "<ERROR>Database Connection Error</ERROR>\n"; return false; } } else { echo "<ERROR>IDS_GAME_ID_INVALID</ERROR>\n"; } }
} /////////////// $cmdRevokeDraw = $_GET['cmdRevokeDraw']; if ($cmdRevokeDraw != "") { $oR3DCQuery->RevokeDrawGame($ConfigFile, $gid, $_SESSION['id']); } $cmdDraw = $_GET['cmdDraw']; if ($cmdDraw != "") { if ($isblack) { $oR3DCQuery->DrawGame($config, $gid, "b"); } else { $oR3DCQuery->DrawGame($config, $gid, "w"); } } $isexitrealtime = false; $isdraw = $oR3DCQuery->IsRequestDraw($config, $gid, $isblack); $cmdExitRealtime = $_GET['cmdExitRealtime']; if ($cmdExitRealtime != "") { $oR3DCQuery->ExitRealTimeGame($config, $gid); $isexitrealtime = true; $_SESSION['RealTimeDoOnce'] = 0; } $rtend = $_GET['rtend']; if ($rtend == 1) { $isexitrealtime = true; $_SESSION['RealTimeDoOnce'] = 0; } $cmdSwitchRealtime = $_GET['cmdSwitchRealtime']; $oR3DCQuery->ManageRealTimeGame($config, $gid); if ($cmdSwitchRealtime != "") { if ($isblack) {
CSession::initialise($config); ChessHelper::load_chess_game($gid); $str = "<RESPONSE><PGN>"; $str .= ChessHelper::get_game_pgn(); $str .= "</PGN>\n"; $pieces = ChessHelper::get_captured_pieces(); $str .= "<CAPTURED_BY_WHITE>" . join(', ', $pieces['white']) . "</CAPTURED_BY_WHITE>\n"; $str .= "<CAPTURED_BY_BLACK>" . join(', ', $pieces['black']) . "</CAPTURED_BY_BLACK>\n"; $str .= "<GAME_STATE>"; $str .= ChessHelper::get_game_state(); $str .= "</GAME_STATE>\n"; $str .= "<GAME_RESULT>"; $str .= ChessHelper::get_game_result(); $str .= "</GAME_RESULT>\n"; $str .= "<DRAWCODE>"; $str .= $oR3DCQuery->IsRequestDraw($config, $_GET['gameid'], $player == 'black' ? TRUE : FALSE); $str .= "</DRAWCODE>\n"; $timeinfo = ChessHelper::get_timing_info(); $str .= "<TIME_STARTED>" . $timeinfo['started'] . "</TIME_STARTED>\n"; $str .= "<TIME_TYPE>" . $timeinfo['type'] . "</TIME_TYPE>\n"; $str .= '<TIME_MODE>' . $timeinfo['mode'] . '</TIME_MODE>\\n'; if ($timeinfo['mode'] == 1) { $str .= '<TIME_W_LEFT>' . $timeinfo['w_time_left'] . '</TIME_W_LEFT>'; $str .= '<TIME_B_LEFT>' . $timeinfo['b_time_left'] . '</TIME_B_LEFT>'; $str .= '<TIME_W_ALLOWED>' . $timeinfo['w_time_allowed'] . '</TIME_W_ALLOWED>'; $str .= '<TIME_B_ALLOWED>' . $timeinfo['b_time_allowed'] . '</TIME_B_ALLOWED>'; } else { $str .= "<TIME_DURATION>" . $timeinfo['duration'] . "</TIME_DURATION>\n"; $str .= '<TIME_W_ALLOWED>' . $timeinfo['duration'] . '</TIME_W_ALLOWED>'; $str .= '<TIME_B_ALLOWED>' . $timeinfo['duration'] . '</TIME_B_ALLOWED>'; }
$oR3DCQuery->ELOCreateRatings(); } $oR3DCQuery->MangeGameTimeOuts(); $oR3DCQuery->Close(); unset($oR3DCQuery); return $bValid; } if (isSessionIDValid($config, $xsid)) { $session = base64_decode($xsid); list($uniq, $player_id) = preg_split("/\\|/", $session); if ($_GET['gameid'] != "") { //Instantiate theCR3DCQuery Class $oR3DCQuery = new CR3DCQuery($config); $oR3DCQuery->GetNewMoveForMobile($_GET['gameid']); $isblack = $oR3DCQuery->IsPlayerBlack($config, $_GET['gameid'], $player_id); $isdraw = $oR3DCQuery->IsRequestDraw($config, $_GET['gameid'], $isblack); echo "<RESPONSE>\n"; echo "<DRAWCODE>" . $isdraw . "</DRAWCODE>\n"; echo "</RESPONSE>\n"; $initiator = ""; $w_player_id = ""; $b_player_id = ""; $status = ""; $completion_status = ""; $start_time = ""; $next_move = ""; $oR3DCQuery->GetGameInfoByRef($config, $_GET['gameid'], $initiator, $w_player_id, $b_player_id, $status, $completion_status, $start_time, $next_move); echo "<RESPONSE>\n"; echo "<STATUS>" . $completion_status . "</STATUS>\n"; echo "</RESPONSE>\n"; $oR3DCQuery->Close();