check_game(); // Listen for a notification that we have been assigned an opponent. // Note that this uses some dynamic data in the query, due to the // limitations of PostgreSQL's listen syntax. $res = pg_query("LISTEN bot_{$bot['id']};"); if ($res === FALSE) { failure("Failed to listen for matchmaking events."); } pg_free_result($res); // Try every second for thirty seconds as to be assigned an opponent. for ($i = 0; $i < 30; $i++) { // Add this bot to the matchmaking queue. Note that this uses some // dynamic data in the query, due to the limitations of PostgreSQL's // notify syntax. $res = pg_query("NOTIFY matchmaker, '{$bot['id']}';"); if ($res === FALSE) { failure("Failed to notify the matchmaker that this bot is ready for a new game."); } pg_free_result($res); $res = pg_get_notify($db, PGSQL_ASSOC); if ($res !== FALSE) { break; } sleep(1); } // Check whether we're in a game, now that we're out of the loop. check_game(); // If we haven't gotten a notification by now, fail encouragingly. pg_query("BEGIN;"); reset_timeout("session"); retry("Failed to find an opponent to play against within 30 seconds, please try again.", "session");
<input type="text" name="name" id="input_name" autofocus required> <br><br> <label for="Player1">Player 1 :</label><br> <?php $pl = select_all_user($bdd); echo "<select name=\"player1\" id=\"Player1\" required>"; if (!empty($pl)) { foreach ($pl as $k => $v) { if (!check_game($bdd, $pl[$k]['id_player'])) { echo "<option value=\"" . $pl[$k]['id_player'] . "\">" . $pl[$k]['login'] . "</option>"; } } } echo "</select>"; echo "<br /><br /><label for=\"Player2\">Player 2 : </label><br>"; echo "<select name=\"player2\" id=\"Player2\" required>"; if (!empty($pl)) { foreach ($pl as $x => $y) { if (!check_game($bdd, $pl[$x]['id_player'])) { echo "<option value=\"" . $pl[$x]['id_player'] . "\">" . $pl[$x]['login'] . "</option>"; } } } echo "</select>"; ?> <br><br> <input type="submit" name="submit" value="Create"> </form>
<?php error_reporting(0); if ($_SERVER['REQUEST_METHOD'] == 'POST') { require_once 'CreateGameFunctions.inc.php'; require_once 'Connection.php'; list($check, $data) = check_game($dbc, $_POST['Game']); if ($check) { header('Location: index.php'); } else { $errors = $data; } } include 'CreateGamePage.inc.php';