Master server changes to add ID to schema.
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
<?php
|
||||
|
||||
if ($db = sqlite_open('openra.db', 0666, $e))
|
||||
{
|
||||
echo 'sqlite_open ok.';
|
||||
sqlite_query( $sb, 'DROP TABLE servers' );
|
||||
sqlite_query( $db, 'CREATE TABLE servers (name varchar(255), address varchar(255), players integer, state integer, ts integer, map varchar(255), mods varchar(255))' );
|
||||
sqlite_close( $db );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $e;
|
||||
}
|
||||
|
||||
<?php
|
||||
header( 'Content-type: text/plain' );
|
||||
try
|
||||
{
|
||||
$db = new PDO('sqlite:openra.db');
|
||||
echo 'Connection to DB established.\n';
|
||||
if ($db->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();
|
||||
}
|
||||
?>
|
||||
@@ -1,28 +1,26 @@
|
||||
<?php
|
||||
header( 'Content-type: text/plain' );
|
||||
|
||||
if (!($db = sqlite_open( 'openra.db', 0666, $e )))
|
||||
{
|
||||
echo 'Database error: ', $e;
|
||||
return;
|
||||
}
|
||||
|
||||
$stale = 60 * 5;
|
||||
$result = sqlite_query( $db, 'SELECT * FROM servers WHERE (' . time() . ' - ts < ' . $stale . ')' );
|
||||
|
||||
$rows = sqlite_fetch_all( $result, SQLITE_ASSOC );
|
||||
|
||||
$n = 0;
|
||||
foreach( $rows as $a ) {
|
||||
echo "Game@" . $n++ . ":\n";
|
||||
echo "\tName: " . $a['name'] . "\n";
|
||||
echo "\tAddress: " . $a['address'] . "\n";
|
||||
echo "\tState: " . $a['state'] . "\n";
|
||||
echo "\tPlayers: " . $a['players'] . "\n";
|
||||
echo "\tMap: " . $a['map'] . "\n";
|
||||
echo "\tMods: " . $a['mods'] . "\n";
|
||||
echo "\tTTL: " . ($stale - (time() - $a['ts'])) . "\n";
|
||||
}
|
||||
|
||||
sqlite_close( $db );
|
||||
<?php
|
||||
header( 'Content-type: text/plain' );
|
||||
|
||||
try
|
||||
{
|
||||
$db = new PDO('sqlite:openra.db');
|
||||
$stale = 60 * 5;
|
||||
$result = $db->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();
|
||||
}
|
||||
?>
|
||||
@@ -1,38 +1,40 @@
|
||||
<?php
|
||||
|
||||
if (!($db = sqlite_open( 'openra.db', 0666, $e )))
|
||||
{
|
||||
echo 'Database error: ', $e;
|
||||
return;
|
||||
}
|
||||
|
||||
$addr = $_SERVER['REMOTE_ADDR'] . ':' . $_REQUEST['port'];
|
||||
$prune = 'DELETE FROM servers WHERE address = \'' . sqlite_escape_string( $addr ) . '\'';
|
||||
echo $prune . "\n\n";
|
||||
|
||||
sqlite_exec( $db, $prune );
|
||||
|
||||
$q = 'INSERT INTO servers VALUES ('.
|
||||
'\'' . sqlite_escape_string( $_REQUEST['name'] ) . '\', '.
|
||||
'\'' . sqlite_escape_string( $addr ) . '\', '.
|
||||
sqlite_escape_string( $_REQUEST['players'] ) . ', '.
|
||||
sqlite_escape_string( $_REQUEST['state'] ) . ', '.
|
||||
time() . ', '.
|
||||
'\'' . sqlite_escape_string( $_REQUEST['map'] ) . '\', '.
|
||||
'\'' . sqlite_escape_string( $_REQUEST['mods'] ) . '\')';
|
||||
|
||||
echo $q;
|
||||
|
||||
if (!sqlite_exec( $db, $q ))
|
||||
{
|
||||
echo 'Error in query:' . sqlite_error_string( sqlite_last_error() );
|
||||
}
|
||||
|
||||
sqlite_close( $db );
|
||||
|
||||
if (isset( $_REQUEST['new']))
|
||||
{
|
||||
$games = file_get_contents("../games.txt");
|
||||
file_put_contents("../games.txt", $games + 1);
|
||||
}
|
||||
<?php
|
||||
header( 'Content-type: text/plain' );
|
||||
try
|
||||
{
|
||||
$db = new PDO('sqlite:openra.db');
|
||||
$addr = $_SERVER['REMOTE_ADDR'] . ':' . $_REQUEST['port'];
|
||||
|
||||
$insert = $db->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();
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user