AngelOfFear
Пользователь
- Регистрация
- 11 Июн 2017
- Сообщения
- 197
- Симпатии
- 16
- Пол
- Мужской
Нужен простенький скрипт для получения списка игроков через сокет.
В инете есть такие говнокоды, которые не работают, что не удивительно.
В инете есть такие говнокоды, которые не работают, что не удивительно.
PHP:
<?php
if(isset($_GET['players']))
{
$timeout = 10;
$myserver = substr(getenv('REQUEST_URI'),
strlen($_SERVER['SCRIPT_NAME']) + 1,
strlen(getenv('REQUEST_URI')));
$myserver = htmlspecialchars($myserver, ENT_QUOTES);
list($myserver,) = explode("&", $myserver);
list($ip, $port) = explode(":", $myserver);
//--------------------------/----------------------------//
if(@$fp = @fsockopen("udp://$ip", $port, $errno, $errstr))
{
socket_set_timeout($fp,$timeout);
$challenge_code = "\xFF\xFF\xFF\xFF\x57";
fwrite($fp, $challenge_code);
$buffer = fread($fp, 4096);
$server_status = ($buffer ? 'ON' : 'OFF');
$challenge_code = substr($buffer, 5, 4);
$challenge = "\xFF\xFF\xFF\xFFU".$challenge_code;
fwrite($fp, $challenge);
$buffer = fread($fp, 4096);
fclose($fp);
}
//--------------------------/----------------------------//
if ($server_status == "ON"){
$player_number = 0;
//$player[0]['name'] = "<b>Имя:</b>";
//$player[0]['score'] = "<b>Фраги:</b>";
$position = 6;
do
{
$player_number++;
$player[$player_number]['id'] = ord($buffer[$position]);
$position ++;
while($buffer[$position] != "\x00" && $position < 4000)
{
$player[$player_number]['name'] .= $buffer[$position];
$position ++;
}
$player[$player_number]['score'] = (ord($buffer[$position + 1]))
+ (ord($buffer[$position + 2]) * 256)
+ (ord($buffer[$position + 3]) * 65536)
+ (ord($buffer[$position + 4]) * 16777216);
if ($player[$player_number]['score'] > 2147483648) { $player[$player_number]['score'] -= 4294967296; }
$position += 9;
}
while ($position < strlen($buffer));
echo "<table height=\"100%\" width=\"100%\"><tr><td valign=\"middle\" align=\"center\">";
echo "<table width=\"100%\">\r\n";
echo "<tr><td align=\"center\" style=\"border:2px dotted;margin:5px;
padding-left:5px;padding-right:5px;padding-top:5px;padding-bottom:5px;font-family:tahoma;font-size:11px;background:#E5EBF3;
color:#6E6E6E;line-height:12px;\"><b>Имя:</b></td><td style=\"border:2px dotted;margin:5px;padding-left:5px;padding-right:5px;
padding-top:5px;padding-bottom:5px;font-family:tahoma;font-size:11px;background:#E5EBF3;color:#6E6E6E;line-height:12px;\" align=\"center\"><b>Фраги:</b></td></tr>";
if( empty($player[1]['name']) )
{
echo "<tr><td align=\"center\" style=\"border:1px solid #2c2c2c;margin:5px;padding-left:5px;
padding-right:5px;padding-top:5px;padding-bottom:5px;font-family:tahoma;font-size:11px;color:#6E6E6E;line-height:12px;\"> -- </td>
<td align=\"center\" style=\"border:1px solid;margin:5px;padding-left:5px;padding-right:5px;padding-top:5px;padding-bottom:5px;font-family:tahoma;font-size:11px;color:#6E6E6E;line-height:12px;\"> -- </td></tr>\r\n";
echo "<tr><td align=\"center\" colspan=\"2\" style=\"font-family:tahoma;font-size:11px;color:#6E6E6E;line-height:12px;\">На сервере нет игроков</td></tr>";
}
else
for($i=1; isset($player[$i]['name']); $i++)
{
echo "<tr><td align=\"center\" style=\"border:1px solid #2c2c2c;margin:5px;padding-left:5px;
padding-right:5px;padding-top:5px;padding-bottom:5px;font-family:tahoma;font-size:11px;color:#6E6E6E;line-height:12px;\">
".htmlspecialchars($player[$i]['name'], ENT_QUOTES)."</td><td align=\"center\" style=\"border:1px solid;
margin:5px;padding-left:5px;padding-right:5px;padding-top:5px;padding-bottom:5px;font-family:tahoma;font-size:11px;color:#6E6E6E;line-height:12px;\">
".$player[$i]['score']."</td></tr>\r\n";
$i++;
if(isset($player[$i]['name']))echo "<tr>
<td align=\"center\" style=\"border:1px solid #2c2c2c;margin:5px;padding-left:5px;padding-right:5px;padding-top:5px;
padding-bottom:5px;font-family:tahoma;font-size:11px; background:#EEE; color:#6E6E6E;line-height:12px;\">".htmlspecialchars($player[$i]['name'], ENT_QUOTES)."</td>
<td align=\"center\" style=\"border:1px solid #2c2c2c;margin:5px;padding-left:5px;padding-right:5px;padding-top:5px;
padding-bottom:5px;font-family:tahoma;font-size:11px;background:#EEE;color:#6E6E6E;line-height:12px;\">".$player[$i]['score']."</td></tr>\r\n";
}
echo "</table><a OnClick=\"window.close()\" href=\"#\" style=\"color:#666666;text-align:center;text-decoration:underline;font-size:13px;font-weight:bold;\">Закрыть</a></td></tr></table>\r\n";
}
exit();
}
$timeout = $_GET['timeout'] > 100 ? 10 : $_GET['timeout'];
$my = substr(substr(getenv('REQUEST_URI'),strlen($_SERVER['SCRIPT_NAME'])),1);
list($my,) = explode('?', $my);
$my = str_replace("%20","",$my);
$servers = explode(',',$my);
$out = <<<EOF
var mystatusbar = document.getElementById("statusbar");
var out='';
var OldColors = new Array(15);
var OldColor;
function lightCell(cell)
{
OldColor = cell.style.backgroundColor;
cell.style.backgroundColor = CellBackground;
}
function darkCell(cell)
{
cell.style.backgroundColor = OldColor;
}
EOF;
$out .= "\r\n\r\n";
$out .= "out += \"<div class='monitoring'><table align='center' class='monitoring'><tr>\";\r\n";
foreach ($servers as $server)
{
list($ip, $port) = explode(":", $server);unset($server);
if( $server = @fsockopen( "udp://".$ip, (int) $port, $errno, $errstr ) )
{
$write = "\xFF\xFF\xFF\xFFTSource Engine Query\x00";
socket_set_timeout($server,$timeout);
fwrite($server, $write);
$server_response = fread($server,4096);
fclose($server);
$server_status = ($server_response ? 'ON' : 'OFF');
}
if($server_status == 'ON')
{
$server_response = substr($server_response, 5);
$server_info = explode(chr(0x00), $server_response);
$server_info['hostname'] = $server_info['1'];
if(strlen($server_info['hostname']) >= ($kk=35))
$server_info['hostname'] = str_replace(substr($server_info['hostname'], $kk, strlen($server_info['hostname'])),'...', $server_info['hostname']);
$server_info['address'] = "$ip:$port";
$server_info['map'] = $server_info['2'];
if(strlen($server_info['map']) >= ($kk=11))
$server_info['map'] = str_replace(substr($server_info['map'], $kk, strlen($server_info['map'])),'...', $server_info['map']);
$server_info['players'] = ord(substr($server_info[5], 0, 1));
$server_info['max'] = $server_info['players'] == 0 ? ord(substr($server_info[6], 0, 1)) : ord(substr($server_info[5], 1, 1));
$server_status = "<b><font color='green'>($server_status)</font></b>";
}
if($server_status == 'OFF')
{
$server_info['hostname'] = "Выкл;)";
$server_info['address'] = "$ip:$port";
$server_info['map'] = "unknown";
$server_info['players'] = "0";
$server_info['max'] = "0";
$server_status = "<b><font color='red'>($server_status)</font></b>";
}
if($server_status)
if($server_info['players'])
$out .= "out += \"<td align='center' class='monitoring' onmouseover='lightCell(this);' onmouseout='darkCell(this);'
onclick='window.open(\\\"http://monitoring.c-s.net.ua/statusbar.php?$ip:$port&players\\\", \\\"Players :: $ip:$port\\\", \\\"width=260, height=390, menubar=no, scrollbars=1,resizable=1\\\");' >
".$server_info['hostname']."<br />$ip:$port $server_status<br /><b>Map:</b> ".$server_info['map']."; <b>Players:</b> ".$server_info['players']."/".$server_info['max']."</td>\";\r\n";
else
$out .= "out += \"<td align='center' class='monitoring' onmouseover='lightCell(this);' onmouseout='darkCell(this);' onclick='my();' >
".$server_info['hostname']."<br />$ip:$port $server_status<br /><b>Map:</b> ".$server_info['map']."; <b>Players:</b> ".$server_info['players']."/".$server_info['max']."</td>\";\r\n";
unset($server_status);
}
$out .= "out += \"</tr></table>\";\r\n";
$out .= "out += \"</div>\";\r\n";
$out .= "mystatusbar.innerHTML = out;\r\n";
$out .= "\r\n\r\n// c-s.net.ua © Lavrik";
echo $out;
?>