///////////////////////////////////////////////////////////////////////
$bGameCreated = false;
//Create the chess game
if ($cmdCreateGame != "" && $my_color != "") {
    $bRTGame = false;
    if ($chkrealtime != "") {
        $bRTGame = true;
    }
    $bRTGamepass = false;
    if ($chkrealtimeposs != "") {
        $bRTGamepass = true;
    }
    if (trim($fen) != "") {
        // validate the fen
        if (preg_match('/^([rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/\\s[wb]{1}\\s[KQkq-]{1,4}\\s-\\s[0-9]{1,4}\\s[1-9]{1,4})$/', trim($fen))) {
            $txtgid = $oR3DCQuery->CreateGame($config, $_SESSION['sid'], $_SESSION['id'], $otherplayerid, $my_color, $fen, $move1, $time1, $move2, $time2, $bRTGame, 0, $bRTGamepass, $slctGameRating, $slctGameTime);
            $bGameCreated = true;
        } elseif (preg_match('/^([rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\/?[rnbqkpRNBQKP1-8]{1,8}\\s[wb]{1}\\s[KQkq-]{1,4}\\s-\\s[0-9]{1,4}\\s[1-9]{1,4})$/', trim($fen))) {
            list($part1, $part2, $part3, $part4, $part5) = explode(" ", $fen, 5);
            $fen = "{$part1}/ {$part2} {$part3} {$part4} {$part5}";
            $txtgid = $oR3DCQuery->CreateGame($config, $_SESSION['sid'], $_SESSION['id'], $otherplayerid, $my_color, $fen, $move1, $time1, $move2, $time2, $bRTGame, 0, $bRTGamepass, $slctGameRating, $slctGameTime);
            $bGameCreated = true;
        }
    } else {
        if (trim($fen) == "") {
            $txtgid = $oR3DCQuery->CreateGame($config, $_SESSION['sid'], $_SESSION['id'], $otherplayerid, $my_color, $fen, $move1, $time1, $move2, $time2, $bRTGame, $precreate, $bRTGamepass, $slctGameRating, $slctGameTime);
            $bGameCreated = true;
        }
    }
}
?>
Пример #2
0
     // Real Time Game check
     if ($_GET['brealtimeposs'] == true && $_GET['brtGame'] == true) {
         $strErrorLine = $strErrorLine . "<ERROR>IDS_INVALID_VAR_BREALTIMEPOSS_AND_BRTGAME_BOTH_TRUE</ERROR>\n";
     }
     // Normal/Pasv game timeout check
     if (($_GET['brtGame'] == false && $_GET['brealtimeposs'] == true || $_GET['brtGame'] == false && $_GET['brealtimeposs'] == false) && $_GET['gametime'] != "C-Normal" && $_GET['gametime'] != "C-Blitz" && $_GET['gametime'] != "C-Short" && $_GET['gametime'] != "C-Slow" && $_GET['gametime'] != "C-Snail") {
         $strErrorLine = $strErrorLine . "<ERROR>IDS_INVALID_VAR_TIMEOUT_NORMAL_PASVRT_GAME</ERROR>\n";
     }
     // Active Real-time timeout check
     if ($_GET['brtGame'] == true && $_GET['brealtimeposs'] == false && $_GET['gametime'] != "RT-Custom" && $_GET['gametime'] != "RT-Blitz" && $_GET['gametime'] != "RT-Short" && $_GET['gametime'] != "RT-Normal" && $_GET['gametime'] != "RT-Slow") {
         $strErrorLine = $strErrorLine . "<ERROR>IDS_INVALID_VAR_TIMEOUT_ACTIVERT_GAME</ERROR>\n";
     }
     if ($strErrorLine == "") {
         //Instantiate theCR3DCQuery Class
         $oR3DCQuery = new CR3DCQuery($config);
         $txtgid = $oR3DCQuery->CreateGame($config, $xsid, $player_id, $_GET['oplayerid'], $_GET['mypiececolor'], $fen, $_GET['move1'], $_GET['time1'], $_GET['move2'], $_GET['time2'], $_GET['brtGame'], $precreate, $_GET['brealtimeposs'], $_GET['ratingtype'], $_GET['gametime']);
         $oR3DCQuery->Close();
         unset($oR3DCQuery);
         echo "<RESPONSE>\n";
         echo "<CREATEGAMECODE>" . $txtgid . "</CREATEGAMECODE>\n";
         echo "</RESPONSE>\n";
     } else {
         echo "<RESPONSE>\n";
         echo $strErrorLine;
         echo "</RESPONSE>\n";
     }
 } else {
     echo "<RESPONSE>\n";
     echo "<ERROR>IDS_SESSION_ID_INVALID</ERROR>\n";
     echo "</RESPONSE>\n";
 }
Пример #3
0
function create_game()
{
    $settings = $_POST['instance'];
    //$fen = $settings['board'];
    $fen = "";
    $wplayer = (int) $settings['w_player_id'];
    $bplayer = (int) $settings['b_player_id'];
    $fen = $settings['fen'];
    $rated = $settings['rated'] ? 'grated' : 'gunrated';
    $game_time = $settings['game_time'];
    if (!in_array($game_time, array('C-Blitz', 'C-Short', 'C-Normal', 'C-Slow', 'C-Snail'))) {
        return array('success' => FALSE, 'error' => 'validation_failed', 'validation_errors' => array('game_time' => array('type' => 'custom', 'error_msg' => 'Game time is invalid')));
    }
    $move1 = (int) $settings['tc']['move1'];
    $move2 = (int) $settings['tc']['move2'];
    $time1 = (int) $settings['tc']['time1'];
    $time2 = (int) $settings['tc']['time2'];
    if ($move1 == 0) {
        $move1 = NULL;
    }
    if ($move2 == 0) {
        $move2 = NULL;
    }
    if ($time1 == 0) {
        $time1 = NULL;
    }
    if ($time2 == 0) {
        $time2 = NULL;
    }
    if ($wplayer == $bplayer) {
        return array('success' => FALSE, 'error' => 'validation_failed', 'validation_errors' => array('w_player_id' => array('type' => 'custom', 'error_msg' => __l('Same person cannot play both sides'))));
    }
    $player_id = $wplayer != 0 ? $wplayer : $bplayer;
    // player id of 0 = ANYONE
    $other_player_id = $wplayer != 0 ? $bplayer : $wplayer;
    $my_color = $wplayer == $player_id ? 'w' : 'b';
    //echo "will pass: $player_id, $other_player_id, $my_color, $fen, $rated";
    $oR3DCQuery = new CR3DCQuery('../bin/config.php');
    $result = $oR3DCQuery->CreateGame(NULL, NULL, $player_id, $other_player_id, $my_color, $fen, $move1, $time1, $move2, $time2, TRUE, FALSE, TRUE, $rated, $game_time);
    //$oR3DCQuery->createGame(NULL, NULL, $player_id, $other_player_id, $my_color, $fen, $move1, $time1, $move2, $time2, $bRTGame, $precreate, $brealtimeposs, $Rating, $GameTime){
    if ($result) {
        return array('success' => TRUE);
    } else {
        return array('success' => FALSE, 'error' => __l('Unable to create game'));
    }
}