Esempio n. 1
0
    call("webchessMail('wakeup',{$_SESSION['opponent']['p_email']},'',{$_SESSION['username']},{$_SESSION['game_id']})");
    $wake_up_sent = webchessMail('wakeup', $_SESSION['opponent']['p_email'], '', $_SESSION['username'], $_SESSION['game_id']);
}
//*/
//******************************************************************************
//  load game from database for display
//******************************************************************************
// get FEN array
$query = "\n\tSELECT h_fen\n\tFROM " . T_HISTORY . "\n\tWHERE h_game_id = '{$_SESSION['game_id']}'\n\tORDER BY h_time\n";
$FENarray = $mysql->fetch_value_array($query, __LINE__, __FILE__);
$num_moves = count($FENarray) - 1;
// remove one for initpos
loadGame();
// sets up board using last entry in ".T_HISTORY." table (chessdb.inc.php)
// convert the current FEN array to an array of standard moves
FENtomoves();
// (chessutils.inc.php)
// find out if it's the current player's turn
$FENitems = explode(' ', $FENarray[$num_moves]);
$curTurn = $colorArray[$FENitems[1]];
$isPlayersTurn = $curTurn == $_SESSION['player']['p_color'] ? true : false;
//*/
// set the display to show whos turn, or shared
if ($_SESSION['shared']) {
    $turn = "Shared";
} elseif ($isPlayersTurn) {
    $turn = "Your Move";
} else {
    $turn = "Opponent's Move";
}
$head_extra = '
Esempio n. 2
0
function saveGame()
{
    global $mysql, $chess;
    global $movesArray, $FENarray;
    global $oppColorArray, $colorArray;
    call('**** saveGame( ) ****');
    // convert the previous move to an FEN string
    $fullFEN = movetoFEN();
    // (chessutils.inc.php)
    // save the full FEN into the history table
    $query = "\n\t\tINSERT INTO " . T_HISTORY . "\n\t\t\t(h_time, h_game_id, h_fen)\n\t\tVALUES\n\t\t\t(NOW( ), '{$_SESSION['game_id']}', '{$fullFEN}')\n\t";
    $mysql->query($query, __LINE__, __FILE__);
    // get the entire FEN list back out of the table for the email
    $query = "\n\t\tSELECT h_fen\n\t\tFROM " . T_HISTORY . "\n\t\tWHERE h_game_id = '{$_SESSION['game_id']}'\n\t\tORDER BY h_time\n\t";
    $FENarray = $mysql->fetch_value_array($query, __LINE__, __FILE__);
    // and convert the current FEN array to an array of standard moves for the email
    FENtomoves();
    // (chessutils.inc.php)
    // check for stalemates and checkmates
    // and update the games table if needed
    $FENbits = explode(' ', $fullFEN);
    // break up the FEN
    call($FENbits);
    call(__FILE__ . ' : ' . __LINE__);
    $chess->init_gamestate($fullFEN);
    $state = $chess->get_status($FENbits[1]);
    // get the gamestate of the current FEN
    $playerMoved = $oppColorArray[$FENbits[1]];
    $otherPlayer = $colorArray[$FENbits[1]];
    // if the game is over due to stalemate, or checkmate
    // make sure the database knows about it
    call("gameState = {$state}\ncheckmate = " . gsMate . "\nstalemate = " . gsStalemate);
    if (gsStalemate == $state) {
        $query = "\n\t\t\tUPDATE " . T_GAME . "\n\t\t\tSET g_game_message = 'Draw'\n\t\t\t\t, g_message_from = '{$_SESSION[$playerMoved]['p_color']}'\n\t\t\tWHERE g_id = '{$_SESSION['game_id']}'\n\t\t";
        $mysql->query($query, __LINE__, __FILE__);
        adjust_stats($_SESSION[$playerMoved]['p_id'], $_SESSION[$otherPlayer]['p_id'], 0.5, 0.5);
    } elseif (gsMate == $state) {
        $query = "\n\t\t\tUPDATE " . T_GAME . "\n\t\t\tSET g_game_message = 'Checkmate'\n\t\t\t\t, g_message_from = '{$_SESSION[$playerMoved]['p_color']}'\n\t\t\tWHERE g_id = '{$_SESSION['game_id']}'\n\t\t";
        $mysql->query($query, __LINE__, __FILE__);
        adjust_stats($_SESSION[$playerMoved]['p_id'], $_SESSION[$otherPlayer]['p_id'], 1, 0);
    }
    // notify opponent of move via email (if we don't already know about, because we're right there)
    if (!isset($_SESSION['shared']) || !$_SESSION['shared']) {
        call("webchessMail('move', {$_SESSION[$otherPlayer]['p_email']}, getMovesLongAlg(true), {$_SESSION[$playerMoved]['p_username']}, {$_SESSION['game_id']})");
        webchessMail('move', $_SESSION[$otherPlayer]['p_email'], getMovesLongAlg(true), $_SESSION[$playerMoved]['p_username'], $_SESSION['game_id']);
    }
    updateTimestamp();
}