- Readme First! - Read and follow the rules, otherwise your posts will be closed
There are currently, 59 guest(s) and 2 member(s) that are online. You are Anonymous user. You can register for free by clicking here
Nuke Cops :: View topic - Server Status Block [ ]
Author
Message
Noxwizard
Nuke Cadet
Joined: Jan 22, 2006
Posts: 2
Posted:
Sun Jan 22, 2006 4:41 pm
Hi, I have a script that will display the status of a game server and list the players on it. I tried to put it in a block, but none of the data is showing. Here's the block's code:
Code:
<?php
$server = "69.112.33.45";
$port = "28001";
function CantConn()
{
$content = "<table border=\"1\" align=\"left\" style=\"border-collapse: collapse\" width=\"100%\" id=\"table1\"><tr><td><B>Connection Error: Server Link Down</B></td></tr></table>";
}
function getData($server, $port, $retrying='1')
{
$input = Chr(98).Chr(0).Chr(0);
@$fp = fsockopen('udp://'.$server, $port);
stream_set_timeout($fp, (0.5*$retrying));
if(!$fp)
CantConn();
fputs($fp, $input);
$out = fopen('./serverDump.txt', 'a+');
$output;
for($problem = stream_get_meta_data($fp);!$problem[timed_out];$problem = stream_get_meta_data($fp))
$output .= fread($fp, 2048);
fclose($fp);
if(!displayData($output))
{
if($retrying == 2)
CantConn();
else
getData($server, $port, ($retrying+1));
}
return true;
}
function displayData($data)
{
$header = substr($data, 0, 4);
if($header != chr(99).chr(0).chr(0).chr(98))
return false;
$game = substr($data, 5, 6);
$rest = substr($data, 11);
$verC = ord(substr($rest, 0, 1));
$version = substr($rest, 1, $verC);
$rest = substr($rest, $verC+1);
$nameC = ord(substr($rest, 0, 1));
$name = substr($rest, 1, $nameC);
$numPL = ord(substr($rest, $nameC+3, 1));
$maxPL = ord(substr($rest, $nameC+4, 1));
$rest = substr($rest, $nameC+7);
$modCount = ord(substr($rest, 0, 1));
$mod = substr($rest, 1, $modCount);
$rest = substr($rest, $modCount+1);
$mapTC = ord(substr($rest, 0, 1));
$mapType = substr($rest, 1, $mapTC);
$rest = substr($rest, $mapTC+1);
$mapNC = ord(substr($rest, 0, 1));
$mapName = substr($rest, 1, $mapNC);
$rest = substr($rest, $mapNC+1);
$servDC = ord(substr($rest, 0, 1));
$servDetail = substr($rest, 1, $servDC);
$teams = ord(substr($rest, $servDC+1, 1));
$rest = substr($rest, $servDC+2);
//== Time to chop off all other stuff, starting from teams...
$b1c = ord(substr($rest, 0, 1));
$rest = substr($rest, $b1c+1);
$b2c = ord(substr($rest, 0, 1));
$rest = substr($rest, $b2c+1);
//== Getting team names
$teamName[255] = "Observer"; //== ALWAYS
for($i = 0; $i < $teams; $i++)
{
$teamNC = ord(substr($rest, 0, 1));
$teamName[$i] = substr($rest, 1, $teamNC);
$rest = substr($rest, $teamNC+1);
$chopC = ord(substr($rest, 0, 1));
$rest = substr($rest, $chopC+1);
# echo("$i: $chopC : ".substr($rest, 0, 1)).' ';
}
$playerName;
$playerTeam;
$playerPing;
$playerPL;
for($i = 0; $i < $numPL; $i++)
{
$playerPing[$i] = ord(substr($rest, 0, 1))*4;
$playerPL[$i] = ord(substr($rest, 1, 1));
$playerTeam[$i] = ord(substr($rest, 2, 1));
$playerNC = ord(substr($rest, 3, 1));
$playerName[$i] = substr($rest, 4, $playerNC);
$rest = substr($rest, (4+$playerNC));
$chopC = ord(substr($rest, 0, 1));
$rest = substr($rest, $chopC+1);
}
$content = "<table border=\"1\" align=\"left\" style=\"border-collapse: collapse\" width=\"100%\" id=\"table1\"><tr><td><B>$name</B><br /><B>$numPL</B> / <B>$maxPL</B> players</td></tr>";
$content = "<tr><td><U><B>Player:</B></U></td></tr>";
for($i = 0; $i < $numPL; $i++)
$content = "<tr><td>$playerName[$i]</td></tr>";
$content = "</table>";
return true;
}
function a($in)
{
$out = $in;
return $out;
}
$server = $_GET['server'];
$port = $_GET['port'];
// Generate Page
//makeForm($server,$port);
if($server && $port)
{
?>
<br>
<?php
getData($server, $port);
}
?>
I know I'm missing the protection part, I'll add it in when I get this working.
Thanks.
Evaders99
Site Admin
Joined: Aug 17, 2003
Posts: 12383
Posted:
Sun Jan 22, 2006 5:50 pm
Noxwizard
Nuke Cadet
Joined: Jan 22, 2006
Posts: 2
Posted:
Sun Jan 22, 2006 6:20 pm
Ok, did that. It's still showing as if there's no content.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum