Created
January 14, 2010 17:17
-
-
Save navarr/277324 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/php5/bin/php | |
<?php | |
error_reporting(E_ALL); | |
if(!isset($server)) { $server = $argv[1]; } | |
$servers = array | |
( | |
"yellow" => array("pdoayellow.servegame.com",1337) | |
); | |
list($return,$error) = getData($servers[$server]); | |
if ($return == null || $return == "") { list($status,$time,$users) = array(2,time(),0); } | |
else { list($status,$time,$users) = parseData($return); } | |
writeData(array($status,$time,$users),$server); | |
print("Updated $server to $status ($users) at $time\r\n"); | |
$best = file_get_contents(dirname(__FILE__)."/".$server.".best"); | |
if ($users > $best) { $f = fopen(dirname(__FILE__)."/".$server.".best","w");fwrite($f,$users);fclose($f); } | |
function getData($serverArray) | |
{ | |
list($server,$port) = $serverArray; | |
$f = fsockopen($server,$port,$ERRno,$ERR,15); | |
if ($f === FALSE) { $status = 0; } else { $status = 1; } | |
if ($status) | |
{ | |
$a = fgets($f,15); | |
if ($a === false) { $status = 3;$users = -1; } | |
else { $users = substr($a,10,2)-1; } | |
} | |
fclose($f); | |
return array(implode(":",array($status,time(),$users)),$ERR); | |
} | |
function parseData($data) | |
{ | |
return explode(":",$data); | |
} | |
function writeData($data,$server) | |
{ | |
$f = fopen(dirname(__FILE__)."/".$server.".cache","w"); | |
fwrite($f,implode(":",$data)); | |
fclose($f); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment