19.07.2012, 15:10
Еще вопрос как исправить php блок мониторинга ниже представленный код вставляю в php файл прописываю свой ip и мониторинга просто нету страничка пустая.
PHP код:
<?php
$data = monitor_samp("127.0.0.1", 7777, samp, info); // измените ай-пи и порт на свой!!!!
$server_samp = "<center>
<b>".$data[hostname]."</b><br>
".$data[ip].":".$data[qport]."<br>
<img src=\"". $img ."\" width=\"160\" height=\"120\" style=\"border:1px solid #000000;\"><br>
Игроков: <b>".$data[players]."/".$data[maxplayers]."</b><br>
Карта: <b>".$data[mapname]."</b>
<script language=\"JavaScript\">
<!--
function winop()
{
windop = window.open(\"engine/modules/monitoring/server_samp_players.php\",\"mywin\" ,\"height=400,width=250 ,scrollbars=yes\");
}
-->
</script>
<center>
<a href=\"javascript:winop();\"><b><font color=\"red\">Кто играет ?</font></b></a>
</center>";
function monitor_samp($ip, $qport, $game, $request)
{
$fp = @fsockopen("udp://$ip", $qport, $errno, $errstr, 1);
if (!$fp) { return FALSE; }
stream_set_timeout($fp, 1, 0); stream_set_blocking($fp, true);
$ip_array = explode(".", $ip);
$challenge = 'SAMP';
$challenge .= chr($ip_array[0]).chr($ip_array[1]).chr($ip_array[2]).chr($ip_array[3]);
$challenge .= chr($port & "\xFF");
$challenge .= chr($port >> 8 & "\xFF");
if ($request == "info") { $challenge .= "i"; }
if ($request == "settings") { $challenge .= "r"; }
if ($request == "players") { $challenge .= "d"; }
fwrite($fp, $challenge);
$buffer = fread($fp, 4096);
fclose($fp);
if (!trim($buffer)) { return FALSE; }
if (!substr($buffer, 0, 4) == "SAMP") { return FALSE; }
$buffer = substr($buffer, 11);
if ($request == "info")
{
$data['password'] = ord(substr($buffer, 0, 1));
$data['players'] = ord(substr($buffer, 1, 2));
$data['maxplayers'] = ord(substr($buffer, 3, 2));
$buffer = substr($buffer, 5);
$data_length = ord(substr($buffer, 0, 4));
$data['hostname'] = substr($buffer, 4, $data_length);
$buffer = substr($buffer, 4 + $data_length);
$data_length = ord(substr($buffer, 0, 4));
$data['gametype'] = substr($buffer, 4, $data_length);
$buffer = substr($buffer, 4 + $data_length);
$data_length = ord(substr($buffer, 0, 4));
$data['mapname'] = substr($buffer, 4, $data_length);
$data['ip'] = $ip;
$data['qport'] = $qport;
return $data;
}
if ($request == "settings")
{
$setting_count = ord(substr($buffer, 0, 2));
$buffer = substr($buffer, 2);
if ($setting_count > 128) { return FALSE; }
for ($i=0; $i<$setting_count; $i++)
{
if (!$buffer) { return FALSE; }
$data_length = ord(substr($buffer, 0, 1));
$key = substr($buffer, 1, $data_length);
$buffer = substr($buffer, 1 + $data_length);
$data_length = ord(substr($buffer, 0, 1));
$value = substr($buffer, 1, $data_length);
$buffer = substr($buffer, 1 + $data_length);
$setting[$key] = $value;
}
return $setting;
}
if ($request == "players")
{
$player_count = ord(substr($buffer, 0, 2));
$buffer = substr($buffer, 2);
if ($player_count > 128) { return FALSE; }
for ($i=1; $i<=$player_count; $i++)
{
if (!$buffer) { return FALSE; }
$player[$i]['pid'] = ord(substr($buffer, 0, 1));
$buffer = substr($buffer, 1);
$data_length = ord(substr($buffer, 0, 1));
$player[$i]['name'] = substr($buffer, 1, $data_length);
$buffer = substr($buffer, 1 + $data_length);
list(,$player[$i]['score']) = unpack("s", substr($buffer, 0, 4));
$buffer = substr($buffer, 4);
$player[$i]['ping'] = ord(substr($buffer, 0, 4));
$buffer = substr($buffer, 4);
}
return $player;
}
}
?>