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'); ?>
<?php include $Root_Path . "includes/javascript.php"; ?> </head> <body> <center> <textarea rows='27' cols='70' class='post'> <?php //Instantiate the CR3DCQuery Class // $oR3DCQuery = new CR3DCQuery($config); // $PGN = $oR3DCQuery->SavePGN($config, $GID); // $fen = $oR3DCQuery->GetActualFEN($sid, $GID); //GetFEN // $oR3DCQuery->Close(); // unset($oR3DCQuery); // echo $PGN; CSession::initialise($config); ChessHelper::load_chess_game($_GET['gid']); echo ChessHelper::get_game_pgn(); ?> </textarea> <br> <input type='text' value='<?php echo $fen; ?> ' size='70'> </center> </body> </html>
static function get_timing_info() { $result = array('started' => NULL, 'type' => 'UNKNOWN', 'duration' => NULL); $timeouts = array('snail' => NULL, 'slow' => NULL, 'normal' => NULL, 'short' => NULL, 'blitz' => NULL); $query = "SELECT * FROM admin_game_options WHERE o_id = 1"; $return = mysql_query($query, CSession::$db_link) or die(mysql_error()); $num = mysql_numrows($return); if ($num != 0) { $timeouts['snail'] = trim(mysql_result($return, 0, "o_snail")); $timeouts['slow'] = trim(mysql_result($return, 0, "o_slow")); $timeouts['normal'] = trim(mysql_result($return, 0, "o_normal")); $timeouts['short'] = trim(mysql_result($return, 0, "o_short")); $timeouts['blitz'] = trim(mysql_result($return, 0, "o_blitz")); } $query = "SELECT * FROM cfm_game_options WHERE o_gameid='" . ChessHelper::$game_id . "'"; $return = mysql_query($query, CSession::$db_link) or die(mysql_error()); $num = mysql_numrows($return); if ($num == 0) { return $result; } $timing_mode = (int) mysql_result($return, 0, "time_mode"); $timing_type = mysql_result($return, 0, "o_timetype"); if ($timing_mode == 1) { $timetype = substr(trim(strtolower($timing_type)), 2); $result['type'] = $timetype; $result['mode'] = 1; $duration = (int) ($timeouts[$timetype] * 86400); // Find out the time taken by both players so far and calculate the time remaining. $query = "SELECT start_time, w_time_used, b_time_used, next_move FROM game WHERE game_id = '" . ChessHelper::$game_id . "'"; $return = mysql_query($query, CSession::$db_link) or die(mysql_error()); $result['started'] = (int) trim(mysql_result($return, 0, "start_time")); $w_time_left = $duration - (int) trim(mysql_result($return, 0, "w_time_used")); $b_time_left = $duration - (int) trim(mysql_result($return, 0, "b_time_used")); $turn = mysql_result($return, 0, "next_move"); if ($turn == NULL) { $turn = 'w'; } // initially games have the player turn set to NULL. // Get the time since the last move (elapsed time for the current player). If no move has // been made then no time has elapsed. if (ChessHelper::$last_move_time === NULL) { $elapsed = 0; } else { //ChessHelper::$last_move_time = $result['started']; $elapsed = ChessHelper::get_seconds_since_last_move('@' . ChessHelper::$last_move_time); } if ($turn == 'w') { $w_time_left -= $elapsed; } else { $b_time_left -= $elapsed; } $result['w_time_left'] = $w_time_left; $result['b_time_left'] = $b_time_left; $result['w_time_allowed'] = $duration; $result['b_time_allowed'] = $duration; } else { $timetype = substr(trim(strtolower($timing_type)), 2); $result['type'] = $timetype; $result['mode'] = 0; $duration = $timeouts[$timetype]; $result['duration'] = $duration * 86400; $query = "SELECT start_time FROM game WHERE game_id = '" . ChessHelper::$game_id . "'"; $return = mysql_query($query, CSession::$db_link) or die(mysql_error()); $result['started'] = trim(mysql_result($return, 0, "start_time")); //old // $query = "SELECT * FROM move_history WHERE game_id='" . ChessHelper::$game_id . "' ORDER BY move_id DESC"; // $return = mysql_query($query, CSession::$db_link) or die(mysql_error()); // $move_cnt = mysql_numrows($return); // if($move_cnt != 0) // { // $move_time = trim(mysql_result($return, 0, "time")); // $time_diff = strtotime("+" . $duration * 86400 . " sec", $move_time) - time(); // $result['remaining'] = $time_diff; // } // else // { // $query = "SELECT start_time FROM game WHERE game_id = '" . ChessHelper::$game_id . "'"; // $return = mysql_query($query, CSession::$db_link) or die(mysql_error()); // if(mysql_numrows($return)) // { // $time_started = trim(mysql_result($return, 0, "start_time")); // $time_diff = strtotime("+" . $duration * 86400 . " sec", $time_started) - time(); // $result['remaining'] = $time_diff; // } // } } return $result; }
function process_game_values($data) { $game_id = $data['instance']['game_id']; $data['instance']['board'] = $game_id; ChessHelper::load_chess_game($game_id); $ML = ChessHelper::$CB->GetMoveList(); $moves_san = array(); foreach ($ML as $move) { $moves_san[] = $move->szSAN; } //echo '<pre>';var_dump($moves_san);echo '</pre>'; $fen = ChessHelper::get_custom_fen($game_id); $data['instance']['board'] = array('moves_san' => $moves_san, 'fen' => $fen); //exit(); }