Код
Код: Выделить всё
<?
// Simple Source/GoldSRC server info collector by morpheus
function cutchar(&$string)
{
$char = substr($string, 0, 1);
$string = substr($string, 1);
return $char;
}
function cutbyte(&$string)
{
$byte = ord(substr($string, 0, 1));
$string = substr($string, 1);
return $byte;
}
function cutstring(&$string)
{
$str = substr($string, 0, StrPos($string, chr(0)));
$string = substr($string, StrPos($string, chr(0))+1);
return $str;
}
function cutshort(&$string)
{
$short = substr($string, 0, 2);
list(,$short) = @unpack("S", $short);
$string = substr($string, 2);
return $short;
}
function cutlong(&$string)
{
$long = substr($string, 0, 4);
list(,$long) = @unpack("l", $long);
$string = substr($string, 4);
return $long;
}
function pastelong($long)
{
return pack("l", $long);
}
function cutfloat(&$string)
{
$float = substr($string, 0, 4);
list(,$float) = @unpack("f", $float);
$string = substr($string, 4);
return $float;
}
function request($request,$host,$port)
{
$request = "\xFF\xFF\xFF\xFF".$request."\x00";
$fp = @fsockopen('udp://'.$host, $port);
if (!$fp) return false;
@fwrite($fp, $request);
socket_set_timeout($fp, 1);
$string=fread($fp, 10240);
@fclose($fp);
return $string;
}
function A2A_PING($host, $port) {
$st = request("\x69",$host,$port);
if (!$st) return false;
$st = substr($st, 4);
if (substr($st, 0, 1) != "\x6A") return false; else return true;
}
function A2S_INFO($host, $port) {
$st = request("\x54Source Engine Query",$host,$port);
if (!$st) return false;
$st = substr($st, 4);
if (substr($st, 0, 1) == "\x49") {
$result['Type'] = cutchar($st); // Char: 'I' (0x49) - For Source
$result['Version'] = cutbyte($st); // Byte: Network version
$result['Server Name'] = cutstring($st); // String: The server's name, eg: "Recoil NZ CS Server #1"
$result['Map'] = cutstring($st); // String: The current map being played, eg: "de_dust"
$result['Game Directory'] = cutstring($st); // String: The name of the folder containing the game files, eg: "cstrike"
$result['Game Description'] = cutstring($st); // String: A friendly string name for the game type, eg: "Counter Strike: Source"
$result['AppID'] = cutshort($st); // Short: Steam Application ID
$result['Number of players'] = cutbyte($st); // Byte: The number of players currently on the server
$result['Maximum players'] = cutbyte($st); // Byte: Maximum allowed players for the server
$result['Number of bots'] = cutbyte($st); // Byte: Number of bot players currently on the server
$result['Dedicated'] = cutchar($st); // Char: 'l' for listen, 'd' for dedicated, 'p' for SourceTV
$result['OS'] = cutchar($st); // Char: Host operating system. 'l' for Linux, 'w' for Windows
$result['Password'] = cutbyte($st); // Byte: If set to 0x01, a password is required to join this server
$result['Secure'] = cutbyte($st); // Byte: if set to 0x01, this server is VAC secured
$result['Game Version'] = cutstring($st); // String: The version of the game, eg: "1.0.0.14"
} elseif (substr($st, 0, 1) == "\x6D") {
$result['Type'] = cutchar($st); // Char: 'm' (0x6D) - For GoldSrc
$result['Game IP'] = cutstring($st); // String: Game Server IP address and port
$result['Server Name'] = cutstring($st); // String: The server's name, eg: "Recoil NZ CS Server #1"
$result['Map'] = cutstring($st); // String: The current map being played, eg: "de_dust"
$result['Game Directory'] = cutstring($st); // String: The name of the folder containing the game files, eg: "cstrike"
$result['Game Description'] = cutstring($st); // String: A friendly string name for the game type, eg: "Counter Strike: Source"
$result['Number of players'] = cutbyte($st); // Byte: The number of players currently on the server
$result['Maximum players'] = cutbyte($st); // Byte: Maximum allowed players for the server
$result['Version'] = cutbyte($st); // Byte: Network version
$result['Dedicated'] = cutchar($st); // Char: 'l' for listen, 'd' for dedicated, 'p' for SourceTV
$result['OS'] = cutchar($st); // Char: Host operating system. 'l' for Linux, 'w' for Windows
$result['Password'] = cutbyte($st); // Byte: If set to 0x01, a password is required to join this server
$result['IsMod'] = cutbyte($st); // Byte: If set to 0x01, this byte is followed by ModInfo
$result['Secure'] = cutbyte($st); // Byte: if set to 0x01, this server is VAC secured
$result['Number of bots'] = cutbyte($st); // Byte: Number of bot players currently on the server
if ($result['IsMod'] == 1) {
$result['URLInfo'] = cutstring($st); // String: URL containing information about this mod
$result['URLDL'] = cutstring($st); // String: URL to download this mod
$result['Nul'] = cutbyte($st); // Byte: 0x00
$result['ModVersion'] = cutlong($st); // Long: Version of the installed mod
$result['ModSize'] = cutlong($st); // Long: The download size of this mod
$result['SvOnly'] = cutbyte($st); // Byte: If 1 this is a server side only mod
$result['ClDLL'] = cutbyte($st); // Byte: If 1 this mod has a custom client dll
}
} else return false;
return $result;
}
function A2S_SERVERQUERY_GETCHALLENGE($host, $port) {
$st = request("\x57",$host,$port);
if (!$st) return false;
$st = substr($st, 4);
if (substr($st, 0, 1) != "\x41") return false; else return cutlong(substr($st, 1));
}
function A2S_RULES($host, $port, $challenge) {
$st = request("\x56".pastelong($challenge),$host,$port);
if (!$st) return false;
$st=substr($st, 4);
if (substr($st, 0, 1) == "\x41") {
$challenge = cutlong(substr($st, 1));
$st = request("\x56".pastelong($challenge),$host,$port);
if (!$st) return false;
$st = substr($st, 4);
}
if (substr($st, 0, 1) != "\x45") return false;
$result['Type'] = cutchar($st); // Char: Should be equal to 'E'
$result['Num Rules'] = cutshort($st); // Short: The number of rules reported in response
for ($i = 1; $i <= $result['Num Rules']; $i++) {
$result['Rule Name'][$i] = cutstring($st); // String: The name of the rule
$result['Rule Value'][$i] = cutstring($st); // String: The rule's value
}
return $result;
}
function A2S_PLAYER($host, $port, $challenge) {
$st = request("\x55".pastelong($challenge),$host,$port);
if (!$st) return false;
$st = substr($st, 4);
if (substr($st, 0, 1) == "\x41") {
$challenge = cutlong(substr($st, 1));
$st = request("\x55".pastelong($challenge),$host,$port);
if (!$st) return false;
$st = substr($st, 4);
}
if (substr($st, 0, 1) != "\x44") return false;
$result['Type'] = cutchar($st); // Char: Should be equal to 'D'
$result['Num Players'] = cutbyte($st); // Byte: The number of players reported in response
for ($i = 1; $i <= $result['Num Players']; $i++) {
$result['Index'][$i] = cutbyte($st); // Byte: The index into [0.. Num Players] for this entry
$result['Player Name'][$i] = cutstring($st); // String: Player's name
$result['Kills'][$i] = cutlong($st); // Long: Number of kills this player has
$result['Time connected'][$i] = cutfloat($st); // Float: The time in seconds this player has been connected
}
return $result;
}
/*print("\n");
print_r(A2S_INFO("109.169.60.13",27015));
print_r(A2S_RULES("109.169.60.13",27015,A2S_SERVERQUERY_GETCHALLENGE("109.169.60.13",27015)));
print_r(A2S_PLAYER("109.169.60.13",27015,A2S_SERVERQUERY_GETCHALLENGE("109.169.60.13",27015)));*/
?>