added PHP master server
This commit is contained in:
14
web/master/create.php
Normal file
14
web/master/create.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if ($db = sqlite_open('openra.db', 0666, $e))
|
||||||
|
{
|
||||||
|
echo 'sqlite_open ok.';
|
||||||
|
sqlite_query( $db, 'CREATE TABLE servers (name varchar(255), address varchar(255), players integer, state integer, ts integer)' );
|
||||||
|
sqlite_close( $db );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
26
web/master/list.php
Normal file
26
web/master/list.php
Normal file
@@ -0,0 +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 "\tTTL: " . ($stale - (time() - $a['ts'])) . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite_close( $db );
|
||||||
|
?>
|
||||||
30
web/master/ping.php
Normal file
30
web/master/ping.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?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() . ')';
|
||||||
|
|
||||||
|
echo $q;
|
||||||
|
|
||||||
|
if (!sqlite_exec( $db, $q ))
|
||||||
|
{
|
||||||
|
echo 'Error in query:' . sqlite_error_string( sqlite_last_error() );
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite_close( $db );
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user