<html>
<head>
<title>SA:MP Server Query Script</title>
<style type="text/css">
body { font-family: verdana; font-size: 11px; }
td { font-family: verdana; font-size: 11px; }
</style>
</head>
<body bgcolor="#1B304B" text="#EEEEEE">
<br><center><b><font color="#ffffff">SA:MP Server Query Script</font></b></center><br><br>
<table width="350" bgcolor="#000000" cellpadding="4" cellspacing="1" align="center">
<?
if (!isset($ip))
$ip = '82.135.228.238';
if (!isset($port))
$port = 8888;
$fp = fsockopen('udp://' . $ip, $port, $errno, $errstr);
if (!$fp)
{
echo "<tr><td bgcolor=\"#2B5486\">Socket Error: $errno - $errstr</td></tr>\n";
}
else
{
$packet = 'SAMP';
$packet .= chr(strtok($ip, '.'));
$packet .= chr(strtok('.'));
$packet .= chr(strtok('.'));
$packet .= chr(strtok('.'));
$packet .= chr($port & 0xFF);
$packet .= chr($port >> 8 & 0xFF);
fwrite($fp, $packet.'i');
fread($fp, 11);
$is_passworded = ord(fread($fp, 1));
$plr_count = ord(fread($fp, 2));
$max_plrs = ord(fread($fp, 2));
$strlen = ord(fread($fp, 4));
$hostname = fread($fp, $strlen);
$strlen = ord(fread($fp, 4));
$gamemode = fread($fp, $strlen);
$strlen = ord(fread($fp, 4));
$mapname = fread($fp, $strlen);
echo ' <tr><td bgcolor="#2B5486" colspan="2" align="center"><b>' . $hostname . '</b></td></tr>'."\n";
echo ' <tr><td bgcolor="#2B5486" width="100">Players: </td><td bgcolor="#2B5486" width="250">' . $plr_count . ' / ' . $max_plrs . '</td></tr>'."\n";
echo ' <tr><td bgcolor="#2B5486">GameMode: </td><td bgcolor="#2B5486">' . $gamemode . '</td></tr>'."\n";
echo ' <tr><td bgcolor="#2B5486">MapName: </td><td bgcolor="#2B5486">' . $mapname . '</td></tr>'."\n";
if ($is_passworded)
{
echo ' <tr><td bgcolor="#2B5486">Passworded: </td><td bgcolor="#2B5486">Yes</td></tr>'."\n";
} else {
echo ' <tr><td bgcolor="#2B5486">Passworded: </td><td bgcolor="#2B5486">No</td></tr>'."\n";
}
fwrite($fp, $packet.'c');
fread($fp, 11);
$plr_count = ord(fread($fp, 2));
if ($plr_count > 0)
{
echo ' </table><br>'."\n";
echo ' <table width="350" bgcolor="#000000" cellpadding="4" cellspacing="1" align="center">'."\n";
echo ' <tr><td bgcolor="#2B5486" colspan="2" align="center"><b>Players:</b></td></tr>'."\n";
echo ' <tr><td bgcolor="#2B5486" align="center" width="250"><b>Player</b></td><td bgcolor="#2B5486" align="center" width="100"><b>Score</b></td></tr>'."\n";
for ($i=0; $i<$plr_count; $i++)
{
$strlen = ord(fread($fp, 1));
$plrname = fread($fp, $strlen);
$score = ord(fread($fp, 4));
echo ' <tr><td bgcolor="#2B5486">' . $plrname . '</td><td bgcolor="#2B5486">' . $score . '</td></tr>'."\n";
}
}
fclose($fp);
}
?>
</table><br>
<center><small>© 2006 SA:MP Team. All rights reserved.</small></center>
</body>
</html>