Example #1
0
 function CreateGame($ConfigFile, $SID, $player_id, $other_player_id, $my_color, $fen, $move1, $time1, $move2, $time2, $bRTGame, $precreate, $brealtimeposs, $Rating, $GameTime)
 {
     $returncode = "";
     // if($bRTGame == true && $move1 == "" && $time1 == ""){
     // $brealtimeposs = true;
     // $bRTGame = false;
     // $GameTime = "C-Normal";
     // }elseif($bRTGame == true && $move1 != "" && $time1 == ""){
     // $brealtimeposs = true;
     // $bRTGame = false;
     // $GameTime = "C-Normal";
     // }elseif($bRTGame == true && $move1 == "" && $time1 != ""){
     // $brealtimeposs = true;
     // $bRTGame = false;
     // $GameTime = "C-Normal";
     // }
     $this->GetServerGameOptions($CSnail, $CSlow, $CNormal, $CShort, $CBlitz, $timing_mode);
     if ($fen != "") {
         // format the fen
         $fen = $this->FormatInputedFEN($fen);
         //Instantiate the CChess Class
         $oChess = new CChess($this->ChessCFGFileLocation);
         $returncode = $oChess->create_game($this->ChessCFGFileLocation, $player_id, $other_player_id, $my_color, $fen);
         unset($oChess);
         $GameID = substr($returncode, 0, 32);
         //if(!$bRTGame){
         $insert11 = "INSERT INTO cfm_game_options VALUES('" . $GameID . "', '" . $Rating . "', '" . $GameTime . "', " . $timing_mode . ")";
         //}else{
         //  $insert11 = "INSERT INTO cfm_game_options VALUES('".$GameID."', '".$Rating."', '-', " . $timing_mode . ")";
         // }
         mysql_query($insert11, $this->link) or die(mysql_error());
         if ($move1 != "" && $time1 != "" && $move2 != "" && $time2 != "") {
             if (is_numeric($move1) && is_numeric($time1) && is_numeric($move2) && is_numeric($time2)) {
                 if (is_int((int) $move1) && is_int((int) $time1) && is_int((int) $move2) && is_int((int) $time2)) {
                     $insert = "INSERT INTO timed_games VALUES('" . $GameID . "', " . $move1 . ", " . $time1 . ", " . $move2 . ", " . $time2 . ")";
                     mysql_query($insert, $this->link) or die(mysql_error());
                 }
             }
         } else {
             if ($move1 != "" && $time1 != "") {
                 if (is_numeric($move1) && is_numeric($time1)) {
                     if (is_int((int) $move1) && is_int((int) $time1)) {
                         $insert = "INSERT INTO timed_games VALUES('" . $GameID . "', " . $move1 . ", " . $time1 . ", 0, 0)";
                         mysql_query($insert, $this->link) or die(mysql_error());
                     }
                 }
             } else {
                 if ($brealtimeposs) {
                     $insert = "INSERT INTO cfm_gamesrealtime VALUES('" . $GameID . "', NOW())";
                     mysql_query($insert, $this->link) or die(mysql_error());
                 }
             }
         }
     } else {
         //Instantiate the CChess Class
         $oChess = new CChess($this->ChessCFGFileLocation);
         $returncode = $oChess->create_game($this->ChessCFGFileLocation, $player_id, $other_player_id, $my_color, "");
         unset($oChess);
         $GameID = substr($returncode, 0, 32);
         //if(!$bRTGame){
         $insert11 = "INSERT INTO cfm_game_options VALUES('" . $GameID . "', '" . $Rating . "', '" . $GameTime . "', " . $timing_mode . ")";
         //}else{
         //  $insert11 = "INSERT INTO cfm_game_options VALUES('".$GameID."', '".$Rating."', '-', " . $timing_mode . ")";
         //}
         mysql_query($insert11, $this->link) or die(mysql_error());
         if ($move1 != "" && $time1 != "" && $move2 != "" && $time2 != "") {
             if (is_numeric($move1) && is_numeric($time1) && is_numeric($move2) && is_numeric($time2)) {
                 if (is_int((int) $move1) && is_int((int) $time1) && is_int((int) $move2) && is_int((int) $time2)) {
                     $insert = "INSERT INTO timed_games VALUES('" . $GameID . "', " . $move1 . ", " . $time1 . ", " . $move2 . ", " . $time2 . ")";
                     mysql_query($insert, $this->link) or die(mysql_error());
                 }
             }
         } else {
             if ($move1 != "" && $time1 != "") {
                 if (is_numeric($move1) && is_numeric($time1)) {
                     if (is_int((int) $move1) && is_int((int) $time1)) {
                         $insert = "INSERT INTO timed_games VALUES('" . $GameID . "', " . $move1 . ", " . $time1 . ", 0, 0)";
                         mysql_query($insert, $this->link) or die(mysql_error());
                     }
                 }
             } else {
                 if ($brealtimeposs) {
                     $insert = "INSERT INTO cfm_gamesrealtime VALUES('" . $GameID . "', NOW())";
                     mysql_query($insert, $this->link) or die(mysql_error());
                 }
             }
         }
         //Create the new game with the pre-created moves
         if ($precreate != 0 && $fen == "") {
             // Set Player Color
             $w_player_id1 = "";
             $b_player_id1 = "";
             if ($req_color != "" && $req_color == "w") {
                 $w_player_id1 = $player_id;
                 $b_player_id1 = $other_player_id;
             } else {
                 $w_player_id1 = $other_player_id;
                 $b_player_id1 = $player_id;
             }
             $query = "SELECT * FROM cfm_creategamefen WHERE o_id =" . $precreate;
             $return = mysql_query($query, $this->link) or die(mysql_error());
             $num = mysql_numrows($return);
             if ($num != 0) {
                 $query2 = "SELECT * FROM cfm_creategamefen_moves WHERE o_cgfid =" . $precreate . " ORDER BY o_id ASC";
                 $return2 = mysql_query($query2, $this->link) or die(mysql_error());
                 $num2 = mysql_numrows($return2);
                 if ($num2 != 0) {
                     $ii = 0;
                     while ($ii < $num2) {
                         $o_move = trim(mysql_result($return2, $ii, "o_move"));
                         if ($ii == 0) {
                             $insert1 = "INSERT INTO move_history VALUES(NULL, " . time() . ", " . $w_player_id1 . ", '" . $o_move . "','" . $GameID . "')";
                             mysql_query($insert1, $this->link) or die(mysql_error());
                         } else {
                             if ($ii % 2 == 0) {
                                 $insert1 = "INSERT INTO move_history VALUES(NULL, " . time() . ", " . $w_player_id1 . ", '" . $o_move . "','" . $GameID . "')";
                                 mysql_query($insert1, $this->link) or die(mysql_error());
                             } else {
                                 $insert1 = "INSERT INTO move_history VALUES(NULL, " . time() . ", " . $b_player_id1 . ", '" . $o_move . "','" . $GameID . "')";
                                 mysql_query($insert1, $this->link) or die(mysql_error());
                             }
                         }
                         $ii++;
                     }
                 }
             }
         }
     }
     return $returncode;
 }