From 1839655eb5779982087191dc04a3cfe306d0bef3 Mon Sep 17 00:00:00 2001 From: Matthew Bowra-Dean Date: Thu, 27 May 2010 01:10:45 +1200 Subject: [PATCH] Master server changes to add ID to schema. --- web/master/create.php | 32 ++++++++++-------- web/master/list.php | 52 ++++++++++++++--------------- web/master/ping.php | 76 ++++++++++++++++++++++--------------------- 3 files changed, 82 insertions(+), 78 deletions(-) diff --git a/web/master/create.php b/web/master/create.php index 16ea9fda86..d7819932c9 100644 --- a/web/master/create.php +++ b/web/master/create.php @@ -1,15 +1,19 @@ -query('DROP TABLE servers')) + echo 'Dropped table.\n'; + $schema = 'CREATE TABLE servers (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(255), + address varchar(255) UNIQUE, players integer, state integer, ts integer, map varchar(255), mods varchar(255))'; + if ($db->query($schema)) + echo 'Created table.'; + $db = null; + } + catch (PDOException $e) + { + echo $e->getMessage(); + } ?> \ No newline at end of file diff --git a/web/master/list.php b/web/master/list.php index e09f50a077..7656c72fda 100644 --- a/web/master/list.php +++ b/web/master/list.php @@ -1,28 +1,26 @@ -query('SELECT * FROM servers WHERE (' . time() . ' - ts < ' . $stale . ')'); + foreach ( $result as $row ) + { + echo "Game@" . $row['id'] . ":\n"; + echo "\tName: " . $row['name'] . "\n"; + echo "\tAddress: " . $row['address'] . "\n"; + echo "\tState: " . $row['state'] . "\n"; + echo "\tPlayers: " . $row['players'] . "\n"; + echo "\tMap: " . $row['map'] . "\n"; + echo "\tMods: " . $row['mods'] . "\n"; + echo "\tTTL: " . ($stale - (time() - $row['ts'])) . "\n"; + } + $db = null; + } + catch (PDOException $e) + { + echo $e->getMessage(); + } ?> \ No newline at end of file diff --git a/web/master/ping.php b/web/master/ping.php index 35212c10e9..36328f690d 100644 --- a/web/master/ping.php +++ b/web/master/ping.php @@ -1,38 +1,40 @@ -prepare('INSERT OR REPLACE INTO servers + (name, address, players, state, ts, map, mods) + VALUES (:name, :addr, :players, :state, :time, :map, :mods)'); + $insert->bindValue(':name', $_REQUEST['name'], PDO::PARAM_STR); + $insert->bindValue(':addr', $addr, PDO::PARAM_STR); + $insert->bindValue(':players', $_REQUEST['players'], PDO::PARAM_INT); + $insert->bindValue(':state', $_REQUEST['state'], PDO::PARAM_INT); + $insert->bindValue(':time', time(), PDO::PARAM_INT); + $insert->bindValue(':map', $_REQUEST['map'], PDO::PARAM_STR); + $insert->bindValue(':mods', $_REQUEST['mods'], PDO::PARAM_STR); + + $insert->execute(); + + if (isset( $_REQUEST['new'])) + { + $select = $db->prepare('SELECT id FROM servers WHERE address = :addr'); + $select->bindValue(':addr', $addr, PDO::PARAM_STR); + + $select->execute(); + + echo (int)$select->fetchColumn(); + + $games = file_get_contents("../games.txt"); + file_put_contents("../games.txt", $games + 1); + } + + $db = null; + } + catch (PDOException $e) + { + echo $e->getMessage(); + } ?> \ No newline at end of file