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"; } }
$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>'; } $str .= "</RESPONSE>\n"; echo preg_replace("/\n/", "", addslashes($str)); ?> "; settings['last_move'] = <?php $lm = ChessHelper::get_last_move(); $str = $lm['from'] . ' ' . $lm['to']; if (trim($str) == '') { $str = FALSE; } echo json_encode($str); ?> ; settings['chat'] = {input_ctrl: 'sendbox', send_ctrl: 'sendmsgbtn', output_ctrl: 'chatbox'}; // Setup language strings LANG = { txt_promotion: '<?php echo __l('Select piece to promote pawn to'); ?>