Hey, thx very much, thats better reading.
i dont wanna let people use it from here, id like to have page where people can browse urban terror servers.
features like real-time refreshing of a specified server status would be ok in my eyes.
important to collect timestamps and make it hammer/dos safe.
with gametracker i mean
http://www.gametracker.com as the holy grail of online gameserver monitoring/tracking^^
oki what i did...
I made SQL backend, having tables for
- server (master) list
- extended server info (to be updated)
- amount of players graphing (to be continued)
now im having to query ~800 servers in narrow cycles.
script runs ~3 seconds, table fills up.
starting a vas amount of tasks means using multicore:
1358 - 1061 = 297 MB
--> thats ok, anyways ~300KB Ram per process is something that could be better.
ah, heres the script that queries each gameserver:
- Code: Select all
<?php
// Turn lamish PHP E_NOTICE off!
error_reporting(E_ALL & ~E_NOTICE);
include './conf.php';
//SQL
$db = mysql_connect ($dbhost, $dbusername, $dbuserpass) or die(mysql_error());
mysql_select_db($dbname, $db) or die("Cannot select $dbname");
$vaiables = $_SERVER['argv'];
//print_r($vaiables);
$ip = $vaiables['1'];
$port = $vaiables['2'];
if ($ip == '' || $port == ''){ echo "usage: server_properties.php <server_ip> <server_port>\n"; die; }
$con = fsockopen("udp://$ip", $port, $errno, $errstr, 2);
fwrite($con, "\xFF\xFF\xFF\xFFgetstatus\x00");
stream_set_timeout($con, 2);
$s = "";
if ($con) {
$read = fread($con, 10000);
$s = substr($read, "4");
}
fclose($con);
// echo $s.'<br><br>';
$s_data = explode("\\", $s);
$response = $s_data[0];
//print_r($s_data);
if ($response == "statusResponse\n"){
$g_matchmode = explode("g_matchmode\\",$s);
$g_matchmode = substr($g_matchmode[1],"0","30");
$g_matchmode = explode("\\",$g_matchmode);
//echo "$g_matchmode[0]\n";
$g_gametype = explode("g_gametype\\",$s);
$g_gametype = substr($g_gametype[1],"0","30");
$g_gametype = explode("\\",$g_gametype);
//echo "$g_gametype[0]\n";
$sv_maxclients = explode("sv_maxclients\\",$s);
$sv_maxclients = substr($sv_maxclients[1],"0","30");
$sv_maxclients = explode("\\",$sv_maxclients);
//echo "$sv_maxclients[0]\n";
$sv_privateClients = explode("sv_privateClients\\",$s);
$sv_privateClients = substr($sv_privateClients[1],"0","30");
$sv_privateClients = explode("\\",$sv_privateClients);
//echo "$sv_privateClients[0]\n";
$g_matchmode = explode("g_matchmode\\",$s);
$g_matchmode = substr($g_matchmode[1],"0","30");
$g_matchmode = explode("\\",$g_matchmode);
//echo "$g_matchmode[0]\n";
$g_warmup = explode("g_warmup\\",$s);
$g_warmup = substr($g_warmup[1],"0","30");
$g_warmup = explode("\\",$g_warmup);
//echo "$g_warmup[0]\n";
$sv_hostname = explode("sv_hostname\\",$s);
$sv_hostname = substr($sv_hostname[1],"0","30");
$sv_hostname = explode("\\",$sv_hostname);
//echo "$sv_hostname[0]\n";
$fraglimit = explode("fraglimit\\",$s);
$fraglimit = substr($fraglimit[1],"0","30");
$fraglimit = explode("\\",$fraglimit);
//echo "$fraglimit[0]\n";
$timelimit = explode("timelimit\\",$s);
$timelimit = substr($timelimit[1],"0","30");
$timelimit = explode("\\",$timelimit);
//echo "$timelimit[0]\n";
$g_allowvote = explode("g_allowvote\\",$s);
$g_allowvote = substr($g_allowvote[1],"0","30");
$g_allowvote = explode("\\",$g_allowvote);
//echo "$g_allowvote[0]\n";
$sv_dlURL = explode("sv_dlURL\\",$s);
$sv_dlURL = substr($sv_dlURL[1],"0","30");
$sv_dlURL = explode("\\",$sv_dlURL);
//echo "$sv_dlURL[0]\n";
$Admin = explode("Admin\\",$s);
$Admin = substr($Admin[1],"0","30");
$Admin = explode("\\",$Admin);
//echo "$Admin[0]\n";
$Email = explode("Email\\",$s);
$Email = substr($Email[1],"0","30");
$Email = explode("\\",$Email);
// echo "$Email[0]\n";
//$uid = dechex("$ip$port");
//Generate UID from srv address
$ip_split = explode(".",$ip);
$uid = str_pad(dechex($ip_split[0]), 2, "0", STR_PAD_LEFT).str_pad(dechex($ip_split[1]), 2, "0", STR_PAD_LEFT).str_pad(dechex($ip_split[2]), 2, "0", STR_PAD_LEFT).str_pad(dechex($ip_split[3]), 2, "0", STR_PAD_LEFT).str_pad(dechex($port), 4, "0", STR_PAD_LEFT);
/*
echo "$uid\n";
echo "$ip\n";
echo "$port\n";
echo "$g_matchmode[0]\n";
echo "$g_gametype[0]\n";
echo "$sv_maxclients[0]\n";
echo "$sv_privateClients[0]\n";
echo "$g_matchmode[0]\n";
echo "$g_warmup[0]\n";
echo "$sv_hostname[0]\n";
echo "$fraglimit[0]\n";
echo "$timelimit[0]\n";
echo "$g_allowvote[0]\n";
echo "$sv_dlURL[0]\n";
echo "$Admin[0]\n";
echo "$Email[0]\n";
*/
$query = "
INSERT INTO `server_properties`
( `uid`, `port`, `g_matchmode`, `g_gametype`, `sv_maxclients`, `sv_privateClients`, `g_warmup`, `sv_hostname`, `fraglimit`, `timelimit`, `g_allowvote`, `sv_dlURL`, `Admin`, `Email`)
VALUES ('$uid', '$port', '$g_matchmode[0]', '$g_gametype[0]', '$sv_maxclients[0]', '$sv_privateClients[0]', '$g_warmup[0]', '$sv_hostname[0]', '$fraglimit[0]', '$timelimit[0]', '$g_allowvote[0]', '$sv_dlURL[0]', '$Admin[0]', '$Email[0]')
ON DUPLICATE KEY UPDATE
time_lastonline = UNIX_TIMESTAMP(CURRENT_TIMESTAMP)
;";
//echo $query;
mysql_query($query, $db);
echo "$ip:$port online";
}
else {
echo "$ip:$port offline";
}
//print_r($s_data);
?>
...And this shoots it:
- Code: Select all
<?php
// Turn lamish PHP E_NOTICE off!
error_reporting(E_ALL & ~E_NOTICE);
include './conf.php';
//SQL
$db = mysql_connect ($dbhost, $dbusername, $dbuserpass) or die(mysql_error());
mysql_select_db($dbname, $db) or die("Cannot select $dbname");
$query ="SELECT ip, port FROM server_list";
$result = mysql_query($query, $db);
while($row=mysql_fetch_array($result)){
//echo $row['ip']."\n";
$ip = $row['ip'];
$port = $row['port'];
shell_exec("php ./server_properties.php $ip $port > /dev/null 2>/dev/null &");
}
?>
btw.
thx blinky again for his great explode trix.
i know it eats ram but it accours to be the only way to have variable and value assigned fail safe.
#################EDIT#################
Every new Cycle on that 800 Servers brings me 800 new rows in the graphing table (where amount of players and current map are stored)
it makes ~50 KB in Database.
Doing it every minute would mean store 72 MB per Day / 2,1 GB per Month.
After, cummulating to 1 Value per hour reduces the amount of Data to additional 35 MB/ Month.
Thats Values where 1 can live with i would say...
#################EDIT#################
some output for registered users only...
masterlist.php