1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
<?php
// Constant
define('PACKET_SIZE', '1400');
define('SERVERQUERY_INFO', "\xFF\xFF\xFF\xFFTSource Engine Query" );
define ('REPLY_INFO', "\x49" );
// Ip address and port
$_ip = '87.98.227.61';
$_port = '27350';
// Open connection with server
$socket = stream_socket_client('udp://'.$_ip.':'.$_port, $errno, $errstr, 30);
// Send command to server
$cmd = SERVERQUERY_INFO;
$length = strlen($cmd);
fwrite($socket, $cmd, $length);
// Get response from server
$response = fread($socket, PACKET_SIZE);
// Clean response
$pattern = "#\xFF\xFF\xFF\xFF".REPLY_INFO."#";
$response = preg_replace($pattern, '', $response);
//echo $response;
//Version - byte (Network version. 0x07 is the current Steam version.)
function getByte(&$string)
{
$data = substr($string, 0, 1);
$string = substr($string, 1);
$data = unpack('Cvalue', $data);
return $data['value'];
}
function getString(&$string)
{
$data = "";
$byte = substr($string, 0, 1);
$string = substr($string, 1);
while (ord($byte) != "0")
{
$data .= $byte;
$byte = substr($string, 0, 1);
$string = substr($string, 1);
}
return $data;
}
function getLong(&$string)
{
$data = substr($string, 0, 4);
$string = substr($string, 4);
$data = unpack('Vvalue', $data);
return $data['value'];
}
$server['version'] = getbyte($response);
// Ip and port
$server['ip'] = $_ip;
$server['port'] = $_port;
//Server Name - string (The Source server's name, eg: "Recoil NZ CS Server #1" )
$server['name'] = trim(getString($response));
//Map - string (The current map being played, eg: "de_dust" )
$server['map'] = getString($response);
//Game Directory - string (The name of the folder containing the game files, eg: "cstrike" )
$server['gamedir'] = getString($response);
//Game Description- string (A friendly string name for the game type, eg: "Counter-Strike: Source" )
$server['gamedesc'] = getString($response);
//AppID - short (Steam Application ID)
//$server['appid'] = getShortSigned($response);
//Number of players - byte (The number of players currently on the server)
$server['numplayers'] = getByte($response);
//Maximum players - byte (Maximum allowed players for the server)
$server['maxplayers'] = getByte($response);
//Number of bots - byte (Number of bot players currently on the server)
$server['bot'] = getByte($response);
//Dedicated - byte ('l' for listen, 'd' for dedicated, 'p' for SourceTV)
$data = chr(getByte($response));
$server['dedicated'] = 0;
$server['sourcetv'] = 0;
$server['listen'] = 0;
if ($data == 'd') $server['dedicated'] = 1;
if ($data == 'p') $server['sourcetv'] = 1;
if ($data == 'l') $server['listen'] = 1;
//OS - byte (Host operating system. 'l' for Linux, 'w' for Windows)
$data = chr(getByte($response));
$server['os'] = 'undefined';
if ($data == 'l')
{
$server['os'] = 'linux';
}
elseif ($data == 'w')
{
$server['os'] = 'windows';
}
//Password - byte (If set to 0x01, a password is required to join this server)
$data = getByte($response);
$server['password'] = 0;
if ($data == 1)
{
$server['password'] = 1;
}
//Secure - byte (if set to 0x01, this server is VAC secured)
$data = getByte($response);
$server['secure'] = 1;
if ($data == 1)
{
$server['secure'] = 1;
}
//Game Version - string (The version of the game, eg: "1.0.0.22" )
$server['gameversion'] = getString($response);
?> |