- <?php
- /*
- * HLDS Server Monitoring
- * by [LF] | GordonFreeman
- *
- *
- */
- // if you do this wrong so dont let know others how we do this wrong
- error_reporting(0);
- $g = $_GET['s'];
- // configuration
- // servers for monitoring
- $servers = array(
- 's1' => array('name' => 'CSHIPE', 'ip' => '82.118.19.206', 'port' => '27016', 'public_adr' => 'cshipe.cshost.su'),
- );
- // Simple Source/GoldSRC server info collector by morpheus
- // very nice thing!
- 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;
- }
- // assign colors to players
- function echo_player($nikita){
- // colored players in monitoring
- $colored_players = array(
- '[UMI7EPATOP] HuKuTa' => 'red',
- 'Dima^1^zombie' => 'yellow',
- 'k.' => 'green'
- );
- if(!$colored_players[$nikita]){
- return $nikita;
- }
- else if($colored_players[$nikita]){
- $nikita = sprintf("<span style=\"color: %s\">%s</span>",$colored_players[$nikita],$nikita);
- return $nikita;
- }
- }
- // write server info by given array data
- function echo_server($server){
- $srv_info = A2S_INFO($server['ip'],$server['port']); // get server info (map, players etc.)
- $srv_noobs = A2S_PLAYER($server['ip'],$server['port']); // get server noobs (Player, biovolf, DON, Devastator etc.)
- echo '<link rel="stylesheet" href="http://cshipe.cshost.su/app/front.css">
- <ol class="rounded">';
- if($srv_info['Maximum players']!=0){
- echo '<br><span><center><font color="#AF9C50">Игроков на сервере :</font> </span><span class="count"><font color="#467FC4">'.$srv_info['Number of players'].'</font> <font color="#AF9C50">из</font> <font color="#467FC4">('.$srv_info['Maximum players'].')</font></span><br/>
- <span><font color="#AF9C50">Текущая карта на сервере:</font> </span><span class="count"><font color="#467FC4">'.$srv_info['Map']. '</font></span></center></div>';
- }else{
- echo '<center><font color="red">Сервер временно недоступен!</font></center><br>';
- }
- echo '';
- if($srv_info['Number of players']>0){
- arsort($srv_noobs['Kills']);
- foreach($srv_noobs['Kills'] as $key => $val){
- echo '<li><a href="#">' .echo_player($srv_noobs['Player Name'][$key]). '<br> (убийств: ' .$val. ')</a></li>';
- }
- }else{
- echo 'На сервере игроки отсутствуют!';
- }
- echo '</ol>';
- }
- // now do this shit
- if($g[0]){
- // write info by provided server id
- echo_server($servers[$g]);
- }else{
- // no server id provided, just write all info from all servers
- foreach ($servers as $server) {
- echo_server($server);
- }
- }
- ?>