Exemple #1
0
<?php

$app->on('connect', function ($context) use($app) {
    // extract($context);
});
$app->on('login', function ($context) use($app) {
    extract($context);
    echo "{$fd} " . $message->username;
    $app->users->login($fd, $message->username);
});
$app->on('close', function ($context) use($app) {
    extract($context);
    logout($server, $fd);
});
$app->on('chat', [function ($context) use($app) {
    extract($context);
    sendMessage($server, 'chat', $message);
}]);
$app->on('load_history', [function ($context) use($app) {
    extract($context);
    loadHistory($server, $message);
}]);
$app->on('service', [function ($context) use($app) {
    extract($context);
    service($server, "service", $message);
}]);
$app->on('receive', [function ($context) use($app) {
    extract($context);
    receive($server, "receive", $message);
}]);
        /* include outside functions */
        if (!isset($_CHESSUTILS))
                require_once ( 'chessutils.php');
     require_once('gui.php');
     #   require 'move.php';
     #   require 'undo.php';
     #   require_once 'blocks.php';

        fixOldPHPVersions();

        require_once( 'connectdb.php');

	echo("//game=$game\n");
	$_SESSION['gameID'] = $game;
	//session_register($_SESSION);
        loadHistory();

	global $history, $numMoves;
	#echo("var theme=\""+$_SESSION['uiTheme']+"\";");
        /* write out constants */
        for ($i = 0; $i <= $numMoves; $i++)
        {
              #echo ("chessHistory[$i] = new Array();\n");
              #echo ("chessHistory[$i][CURPIECE] = '".$history[$i]['curPiece']."';\n");
              #echo ("chessHistory[$i][CURCOLOR] = '".$history[$i]['curColor']."';\n");
              #echo ("chessHistory[$i][FROMROW] = ".$history[$i]['fromRow'].";\n");
              #echo ("chessHistory[$i][FROMCOL] = ".$history[$i]['fromCol'].";\n");
              #echo ("chessHistory[$i][TOROW] = ".$history[$i]['toRow'].";\n");
              #echo ("chessHistory[$i][TOCOL] = ".$history[$i]['toCol'].";\n");
	      $fR = $history[$i]['fromRow'];
	      $fC = $history[$i]['fromCol'];
//it contains the stuff that converts a "pgn" data set into the board positions. it's quite nice
//probably want to update it a little bit however....
//OK let's get this sucker loaded.
if (!empty($_POST['is_in_check'])) {
    $is_in_check = $_POST['is_in_check'];
} else {
    $is_in_check = false;
}
//initialize the variables - let's keep em organized as well....
$isCheckMate = false;
$isPromoting = false;
$isUndoing = false;
if (empty($game_id)) {
    $game_id = $_SESSION['game_id'];
}
$load_history = loadHistory($game_id);
//should be load_history($game_id) and return value is history array, better than globaling everything
$load_game = loadGame($game_id);
//dont know - should this return a true or false we can check? or does it return specific data?
$sql = $db->Prepare("SELECT * from {$db_prefix}games WHERE game_id=?");
$query = $db->Execute($sql, array($game_id));
db_op_result($query, __LINE__, __FILE__);
$row = $query->fields;
if (empty($row)) {
    //this is rather silly, really .. let's instead show a notice "game deleted" and have done with it :)
    //offer options such as pgn download, review, kibbitz, etc - the game cleanup script will archive saved games
    //The game was deleted
    //echo "<script>window.location='mainmenu.php'</script>";
    //exit;
}
$white = $row['white_player'];