if ($opponentEmail != '') { /* notify opponent of invitation via email */ webchessMail('invitation', $opponentEmail, '', $_SESSION['nick']); } } } } break; case 'ResponseToInvite': if ($_POST['response'] == 'accepted') { /* update game data */ $tmpQuery = "UPDATE games SET gameMessage = '', messageFrom = '' WHERE gameID = " . $_POST['gameID']; mysql_query($tmpQuery); /* setup new board */ $_SESSION['gameID'] = $_POST['gameID']; createNewGame($_POST['gameID']); saveGame(); } else { $tmpQuery = "UPDATE games SET gameMessage = 'inviteDeclined', messageFrom = '" . $_POST['messageFrom'] . "' WHERE gameID = " . $_POST['gameID']; mysql_query($tmpQuery); } break; case 'WithdrawRequest': /* get opponent's player ID */ $tmpOpponentID = mysql_query("SELECT whitePlayer FROM games WHERE gameID = " . $_POST['gameID']); if (mysql_num_rows($tmpOpponentID) > 0) { $opponentID = mysql_result($tmpOpponentID, 0); if ($opponentID == $_SESSION['playerID']) { $tmpOpponentID = mysql_query("SELECT blackPlayer FROM games WHERE gameID = " . $_POST['gameID']); $opponentID = mysql_result($tmpOpponentID, 0); }
function create_games($id) { global $_SESSION; $t = mysql_query("SELECT * FROM tournaments WHERE id = '$id'"); $t = mysql_fetch_array($t); if ($t['players'] == 4) { $games = array( 1 => array('whitePlayer' => $t['player1'], 'blackPlayer' => $t['player2']), 2 => array('whitePlayer' => $t['player1'], 'blackPlayer' => $t['player3']), 3 => array('whitePlayer' => $t['player1'], 'blackPlayer' => $t['player4']), 4 => array('whitePlayer' => $t['player2'], 'blackPlayer' => $t['player1']), 5 => array('whitePlayer' => $t['player2'], 'blackPlayer' => $t['player3']), 6 => array('whitePlayer' => $t['player2'], 'blackPlayer' => $t['player4']), 7 => array('whitePlayer' => $t['player3'], 'blackPlayer' => $t['player1']), 8 => array('whitePlayer' => $t['player3'], 'blackPlayer' => $t['player2']), 9 => array('whitePlayer' => $t['player3'], 'blackPlayer' => $t['player4']), 10 => array('whitePlayer' => $t['player4'], 'blackPlayer' => $t['player1']), 11 => array('whitePlayer' => $t['player4'], 'blackPlayer' => $t['player2']), 12 => array('whitePlayer' => $t['player4'], 'blackPlayer' => $t['player3'])); while (list($key, $val) = each($games)) { $query = "INSERT INTO {$db_prefix}games (timelimit, gameMessage,messageFrom, whitePlayer, blackPlayer, dateCreated, lastMove, ratingWhite, ratingBlack,ratingWhiteM,ratingBlackM,PVBlack,PVWhite,tournament,oficial,thematic) VALUES ("; $white = $games[$key]['whitePlayer']; $black = $games[$key]['blackPlayer']; $query .= "".$t['days'].", '', '', $white, $black, NOW(), NOW(),".getRating($white).",".getRating($black).",".getRatingMonth($white).",".getRatingMonth($black).",".getPV($black).",".getPV($white).", '$id', '".$t['official']."','".$t['thematic']."')"; mysql_query($query); echo mysql_error(); } // while $query = mysql_query("SELECT game_id FROM {$db_prefix}games WHERE tournament = '$id'"); while ($g = mysql_fetch_array($query)) { if (!function_exists('createNewGame')) { include 'newgame.php'; } $_SESSION['gameID'] = $g['gameID']; createNewGame($_SESSION['gameID']); saveGame(); } // while } // 4 players }
else if (($diff >= 250 && $PLY == 5) || ($diff >= 200 && $PLY == 6) || ($diff >= 150 && $PLY == 7) || ($diff >= 100 && $PLY == 8) || ($diff >= 50 && $PLY >= 9)){ echo "$now # $JOGADOR_NAME ignoring weak player: ". $row['gameID']."\n"; mysql_query("UPDATE games SET reason='#weakplayer',gameMessage = 'inviteDeclined', messageFrom = '".$JOGADOR_COR."' WHERE gameID = ".$row['gameID']); } else if ($mult[0] == 0){ // Open initBoard.txt $fp = fopen("$bot_path/initBoard.txt","rb"); $lastBoard = base64_encode(fread($fp,filesize("$bot_path/initBoard.txt"))); fclose($fp); $tmpQuery = "UPDATE games SET lastBoard='$lastBoard', gameMessage = '', messageFrom = '' WHERE gameID = '".$row['gameID']."'"; mysql_query($tmpQuery); createNewGame($row['gameID']); // Saving game // Flag the game 0 // mysql_query("UPDATE games set gameok='0' WHERE gameID = ".$_row['gameID']); mysql_query("DELETE FROM pieces WHERE gameID = ".$row['gameID']); for ($i = 0; $i < 8; $i++) { for ($j = 0; $j < 8; $j++) { if ($board[$i][$j] != 0) { if ($board[$i][$j] & BLACK) $tmpColor = "black"; else
//*/ //****************************************************************** // respond to invitation //****************************************************************** if (isset($_POST['respond'])) { if ('accepted' == $_POST['respond']) { // update game data $query = "\n\t\t\t\t\tUPDATE " . T_GAME . "\n\t\t\t\t\tSET g_game_message = ''\n\t\t\t\t\t\t, g_message_from = ''\n\t\t\t\t\tWHERE g_id = '{$_POST['game_id']}'\n\t\t\t\t"; $mysql->query($query, __LINE__, __FILE__); // get the opponents ID for email $query = "\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM " . T_GAME . "\n\t\t\t\t\tWHERE g_id = '{$_POST['game_id']}'\n\t\t\t\t"; $game = $mysql->fetch_assoc($query, __LINE__, __FILE__); $oppID = $game['g_white_player_id'] == $_SESSION['player_id'] ? $game['g_black_player_id'] : $game['g_white_player_id']; // setup new board $_SESSION['game_id'] = $_POST['game_id']; createNewGame($_POST['game_id'], $game['g_id960']); // (newgame.inc.php) # saveGame( ); // (chessdb.inc.php) // if email notification is activated... if ($CFG_USEEMAIL) { // if opponent is using email notification... $query = "\n\t\t\t\t\t\tSELECT p_email\n\t\t\t\t\t\tFROM " . T_PLAYER . "\n\t\t\t\t\t\tWHERE p_id = '{$oppID}'\n\t\t\t\t\t"; $opponentEmail = $mysql->fetch_value($query, __LINE__, __FILE__); if (0 < $mysql->num_rows()) { if ('' != $opponentEmail) { // notify opponent of invitation via email call("webchessMail('accepted',{$opponentEmail},'',{$_SESSION['username']},'')"); webchessMail('accepted', $opponentEmail, '', $_SESSION['username'], ''); } } }
function createNewDefaultGame() { global $minefieldWidth, $minefieldHeight, $startingMines; return createNewGame($minefieldWidth, $minefieldHeight, $startingMines); }
/*Autoreject*/ $tmpQuery = "UPDATE games SET gameMessage = 'inviteDeclined', messageFrom = '".$tmpFrom."' WHERE gameID = ".$tmpGame['gameID']; mysql_query($tmpQuery); } else if ($_SESSION["pref_autoaccept"] == "1"){ /*Autoaccept*/ /* update game data */ $tmpQuery = "UPDATE games SET gameMessage = '', messageFrom = '' WHERE gameID = ".$tmpGame['gameID']; mysql_query($tmpQuery); /* setup new board */ $_SESSION['gameID'] = $tmpGame['gameID']; createNewGame($tmpGame['gameID']); saveGame(); } else{ /* Opponent */ echo("<tr><td bgcolor=white>"); /* get opponent's nick */ if ($tmpGame['whitePlayer'] == $_SESSION['playerID']) $tmpOpponent = mysql_query("SELECT firstName,lastName,playerID FROM players WHERE playerID = ".$tmpGame['blackPlayer']); else $tmpOpponent = mysql_query("SELECT firstName,lastName,playerID FROM players WHERE playerID = ".$tmpGame['whitePlayer']); $row = mysql_fetch_array($tmpOpponent); $opponent = $row[0]; $id = $row[2];
function create_match_games($match_id){ //load up all signed up players and arrange in order $tmp_teams = mysql_query("SELECT * FROM matches WHERE match_id = '$match_id'"); $teams = db_result_to_array($tmp_teams); $team1 = $teams[0][1]; $team2 = $teams[0][2]; $boards = $teams[0][6]; //load up player IDs for team 1 $tmp_players = mysql_query("SELECT playerID FROM match_players WHERE match_id = '$match_id' AND teamID = '$team1'"); $team1_players = db_result_to_array($tmp_players); for ($i=0;$i<$boards;$i++){ $tmp_player_info = mysql_query("SELECT rating FROM {$db_prefix}players WHERE playerID = ".$team1_players[$i][0]); $tmp_rating = mysql_fetch_array($tmp_player_info); $rating=$tmp_rating[0]; $team1_players[$i][1] = $rating; # echo "Player team 1, player $i: ".$team1_players[$i][0]." rating = ".$team1_players[$i][1]."<br>"; } usort ($team1_players, 'compare');//sort in rank order //load up player IDs for team 2 $tmp_players = mysql_query("SELECT playerID FROM match_players WHERE match_id = '$match_id' AND teamID = '$team2'"); $team2_players = db_result_to_array($tmp_players); for ($i=0;$i<$boards;$i++){ $tmp_player_info = mysql_query("SELECT rating FROM {$db_prefix}players WHERE playerID = ".$team2_players[$i][0]); $tmp_rating = mysql_fetch_array($tmp_player_info); $rating=$tmp_rating[0]; $team2_players[$i][1] = $rating; # echo "Player team 2, player $i: ".$team2_players[$i][0]." rating = ".$team2_players[$i][1]."<br>"; } usort ($team2_players, 'compare');//sort in rank order //debug line # echo "<br>".$team1_players[0][0]." : ".$team1_players[0][1]."<br>".$team1_players[1][0]." : ".$team1_players[1][1]."<br>".$team2_players[0][0]." : ".$team2_players[0][1]."<br>".$team2_players[1][0]." : ".$team2_players[1][1]; //for each pair, create first game $tmpColor = 'white';//set first team 1 player to white for ($i=0;$i<$boards;$i++){ $tmpQuery = "INSERT INTO {$db_prefix}games (white_player, black_player, status, message_from, dateCreated, lastMove, ratingWhite, ratingBlack, ratingWhiteM, ratingBlackM, oficial, PVBlack, PVWhite, timelimit, teamMatch, team) VALUES ("; if ($tmpColor == 'white'){ $white = $team1_players[$i][0]; $black = $team2_players[$i][0]; $tmpColor = 'black'; }else{ $white = $team2_players[$i][0]; $black = $team1_players[$i][0]; $tmpColor = 'white'; } $tmpQuery .= "$white, $black, '', '', NOW(), NOW(),".getRating($white).",".getRating($black).",".getRatingMonth($white).",".getRatingMonth($black).",'1',".getPV($black).",".getPV($white).",".getMatchTimeLimit($match_id).",'1',$match_id)"; mysql_query($tmpQuery); /* if email notification is activated... */ # if ($CFG_USEEMAILNOTIFICATION){ # /* if opponent is using email notification... */ # $tmpOpponentEmail = mysql_query("SELECT value FROM ch_preferences WHERE playerID = ".$_POST['opponent']." AND preference = 'emailNotification'"); # if (mysql_num_rows($tmpOpponentEmail) > 0){ # $opponentEmail = mysql_result($tmpOpponentEmail, 0); # if ($opponentEmail != ''){ # /* notify opponent of invitation via email */ # webchessMail('invitation', $opponentEmail, '', $_SESSION['nick']); # } # } # } // setup new board $game_id = mysql_insert_id();// get ID of new game $_SESSION['game_id'] = $game_id; createNewGame($game_id); saveGame(); } //for each pair, create second game $tmpColor = 'black';//set first team 1 player to white for ($i=0;$i<$boards;$i++){ $tmpQuery = "INSERT INTO {$db_prefix}games (white_player, black_player, status, message_from, dateCreated, lastMove, ratingWhite, ratingBlack, ratingWhiteM, ratingBlackM, oficial, PVBlack, PVWhite, timelimit, teamMatch, team) VALUES ("; if ($tmpColor == 'black'){ $black = $team1_players[$i][0]; $white = $team2_players[$i][0]; $tmpColor = 'white'; }else{ $black = $team2_players[$i][0]; $white = $team1_players[$i][0]; $tmpColor = 'black'; } $tmpQuery .= "$white, $black, '', '', NOW(), NOW(),".getRating($white).",".getRating($black).",".getRatingMonth($white).",".getRatingMonth($black).",'1',".getPV($black).",".getPV($white).",".getMatchTimeLimit($match_id).",'1',$match_id)"; mysql_query($tmpQuery); /* if email notification is activated... */ # if ($CFG_USEEMAILNOTIFICATION){ # /* if opponent is using email notification... */ # $tmpOpponentEmail = mysql_query("SELECT value FROM ch_preferences WHERE playerID = ".$_POST['opponent']." AND preference = 'emailNotification'"); # if (mysql_num_rows($tmpOpponentEmail) > 0){ # $opponentEmail = mysql_result($tmpOpponentEmail, 0); # if ($opponentEmail != ''){ # /* notify opponent of invitation via email */ # webchessMail('invitation', $opponentEmail, '', $_SESSION['nick']); # } # } # } // setup new board $game_id = mysql_insert_id();// get ID of new game $_SESSION['game_id'] = $game_id; createNewGame($game_id); saveGame(); } //update match table mysql_query("UPDATE matches SET status = '' WHERE match_id = '$match_id'"); }
$tmpFrom = "white"; else $tmpFrom = "black"; if ($_SESSION["auto_accept"] == "1") { /*Autoaccept*/ /* update game data */ $tmpQuery = "UPDATE {$db_prefix}games SET status = '', message_from = '' WHERE game_id = ".$tmpGame['game_id']; mysql_query($tmpQuery); /* setup new board */ $game_id = $tmpGame['game_id']; createNewGame($tmpGame['game_id']); saveGame(); } else{ /* Opponent */ echo("<tr><td bgcolor=white>"); /* get opponent's nick */ if ($tmpGame['white_player'] == $_SESSION['player_id']) $tmpOpponent = mysql_query("SELECT username,player_id FROM {$db_prefix}players WHERE player_id = ".$tmpGame['black_player']); else $tmpOpponent = mysql_query("SELECT username,player_id FROM {$db_prefix}players WHERE player_id = ".$tmpGame['white_player']); $row = mysql_fetch_array($tmpOpponent); $opponent = $row['username']; $id = $row['player_id'];