Parašė Scarletas· 2012 Sau. 19 17:01:02
#6
Štai padariau, pasiredaguok tik ;]
// Serveris 1
$ip = "77.241.199.156";
$port = "27019";
$packet = "\xFF\xFF\xFF\xFFTSource Engine Query\x00";
function getnextstring(&$data)
{
$temp="";
$counter=0;
while (ord($data[$counter++])!=0) $temp.=$data[$counter-1];
$data=substr($data,strlen($temp)+1);
return $temp;
}
function getnextbytevalue(&$data)
{
$temp=ord($data[0]);
$data=substr($data,1);
return $temp;
}
if(!$live_server = fsockopen("udp://".$ip.":".$port.""))
{
$output = "Offline";
}
else
{
fwrite($live_server, $packet);
socket_set_timeout($live_server,1,0);
$junk = fread($live_server,5);
$status = socket_get_status($live_server);
$do = 1;
$server_info= "";
while($do)
{
$str_1 = fread($live_server,1);
$server_info .= $str_1;
$status = socket_get_status($live_server);
if($status["unread_bytes"] == 0) {$do = 0;}
}
fclose($live_server);
if (strlen($server_info) > 0)
{
$success = 1;
$junk = getnextstring($server_info);
$servername = getnextstring($server_info);
$map = getnextstring($server_info);
$junk = getnextstring($server_info);
$junk = getnextstring($server_info);
$players = getnextbytevalue($server_info);
$maxplayers = getnextbytevalue($server_info);
}
if ($players != '') {
$players = $players;
} else {
$players = "0";
}
if ($maxplayers != '')
{
$maxplayers = $maxplayers;
}
else
{
$maxplayers = "0";
}
if ($players < $maxplayers)
{
$output = "<font color='green'>Online</font>";
}
else
{
$output = "<font color='red'>Full</font>";
}
if ($output != "Full" and $players != "0" or $maxplayers != "0")
{
$output = $output;
}
else
{
$output = "<font color='red'>Offline</font>";
}
if ($map != '')
{
$map = "".$map."";
}
else
{
$map = "-----";
}
if ($servername != '') {
$servername = $servername;
} else {
$servername = "<font color='#ff3600'>Serveris neveikia</font>";
}
echo "<table cellpadding='0' cellspacing='1' width='100%' height='25'>\n<tr>\n";
echo"<td align='center'><font color='333333'>".$output."</td>
<td class='vovercikas' align='center'><font color='333333'>".$ip.":".$port."</td>
<td class='vovercikas' align='center'><font color='333333'>".$servername."</td>
<td class='vovercikas' align='center'><font color='333333'>".$map."</td>
<td class='vovercikas' align='center'><font color='333333'>".$players."/".$maxplayers."</td>";
echo "</tr>\n</table>\n";
}
// Serveris 2
$ip = "77.241.199.156";
$port = "27019";
$packet = "\xFF\xFF\xFF\xFFTSource Engine Query\x00";
function getnextstring2(&$data)
{
$temp="";
$counter=0;
while (ord($data[$counter++])!=0) $temp.=$data[$counter-1];
$data=substr($data,strlen($temp)+1);
return $temp;
}
function getnextbytevalue2(&$data)
{
$temp=ord($data[0]);
$data=substr($data,1);
return $temp;
}
if(!$live_server = fsockopen("udp://".$ip.":".$port.""))
{
$output = "Offline";
}
else
{
fwrite($live_server, $packet);
socket_set_timeout($live_server,1,0);
$junk = fread($live_server,5);
$status = socket_get_status($live_server);
$do = 1;
$server_info= "";
while($do)
{
$str_1 = fread($live_server,1);
$server_info .= $str_1;
$status = socket_get_status($live_server);
if($status["unread_bytes"] == 0) {$do = 0;}
}
fclose($live_server);
if (strlen($server_info) > 0)
{
$success = 1;
$junk = getnextstring($server_info);
$servername = getnextstring($server_info);
$map = getnextstring($server_info);
$junk = getnextstring($server_info);
$junk = getnextstring($server_info);
$players = getnextbytevalue($server_info);
$maxplayers = getnextbytevalue($server_info);
}
if ($players != '') {
$players = $players;
} else {
$players = "0";
}
if ($maxplayers != '')
{
$maxplayers = $maxplayers;
}
else
{
$maxplayers = "0";
}
if ($players < $maxplayers)
{
$output = "<font color='green'>Online</font>";
}
else
{
$output = "<font color='red'>Full</font>";
}
if ($output != "Full" and $players != "0" or $maxplayers != "0")
{
$output = $output;
}
else
{
$output = "<font color='red'>Offline</font>";
}
if ($map != '')
{
$map = "".$map."";
}
else
{
$map = "-----";
}
if ($servername != '') {
$servername = $servername;
} else {
$servername = "<font color='#ff3600'>Serveris neveikia</font>";
}
echo "<table cellpadding='0' cellspacing='1' width='100%' height='25'>\n<tr>\n";
echo"<td align='center'><font color='333333'>".$output."</td>
<td class='vovercikas' align='center'><font color='333333'>".$ip.":".$port."</td>
<td class='vovercikas' align='center'><font color='333333'>".$servername."</td>
<td class='vovercikas' align='center'><font color='333333'>".$map."</td>
<td class='vovercikas' align='center'><font color='333333'>".$players."/".$maxplayers."</td>";
echo "</tr>\n</table>\n";
}