1. <?php
  2. /*
  3. * HLDS Server Monitoring
  4. * by [LF] | GordonFreeman
  5. *
  6. *
  7. */
  8. // if you do this wrong so dont let know others how we do this wrong
  9. error_reporting(0);
  10. $g = $_GET['s'];
  11. // configuration
  12. // servers for monitoring
  13. $servers = array(
  14. 's1' => array('name' => 'CSHIPE', 'ip' => '82.118.19.206', 'port' => '27016', 'public_adr' => 'cshipe.cshost.su'),
  15. );
  16. // Simple Source/GoldSRC server info collector by morpheus
  17. // very nice thing!
  18. function cutchar(&$string){
  19. $char = substr($string, 0, 1);
  20. $string = substr($string, 1);
  21. return $char;
  22. }
  23. function cutbyte(&$string){
  24. $byte = ord(substr($string, 0, 1));
  25. $string = substr($string, 1);
  26. return $byte;
  27. }
  28. function cutstring(&$string){
  29. $str = substr($string, 0, StrPos($string, chr(0)));
  30. $string = substr($string, StrPos($string, chr(0))+1);
  31. return $str;
  32. }
  33. function cutshort(&$string){
  34. $short = substr($string, 0, 2);
  35. list(,$short) = @unpack("S", $short);
  36. $string = substr($string, 2);
  37. return $short;
  38. }
  39. function cutlong(&$string){
  40. $long = substr($string, 0, 4);
  41. list(,$long) = @unpack("l", $long);
  42. $string = substr($string, 4);
  43. return $long;
  44. }
  45. function pastelong($long){
  46. return pack("l", $long);
  47. }
  48. function cutfloat(&$string){
  49. $float = substr($string, 0, 4);
  50. list(,$float) = @unpack("f", $float);
  51. $string = substr($string, 4);
  52. return $float;
  53. }
  54. function request($request,$host,$port){
  55. $request = "\xFF\xFF\xFF\xFF".$request."\x00";
  56. $fp = @fsockopen('udp://'.$host, $port);
  57. if (!$fp) return false;
  58. @fwrite($fp, $request);
  59. socket_set_timeout($fp, 1);
  60. $string=fread($fp, 10240);
  61. @fclose($fp);
  62. return $string;
  63. }
  64. function A2A_PING($host, $port){
  65. $st = request("\x69",$host,$port);
  66. if (!$st) return false;
  67. $st = substr($st, 4);
  68. if (substr($st, 0, 1) != "\x6A") return false; else return true;
  69. }
  70. function A2S_INFO($host, $port) {
  71. $st = request("\x54Source Engine Query",$host,$port);
  72. if (!$st) return false;
  73. $st = substr($st, 4);
  74. if (substr($st, 0, 1) == "\x49") {
  75. $result['Type'] = cutchar($st); // Char: 'I' (0x49) - For Source
  76. $result['Version'] = cutbyte($st); // Byte: Network version
  77. $result['Server Name'] = cutstring($st); // String: The server's name, eg: "Recoil NZ CS Server #1"
  78. $result['Map'] = cutstring($st); // String: The current map being played, eg: "de_dust"
  79. $result['Game Directory'] = cutstring($st); // String: The name of the folder containing the game files, eg: "cstrike"
  80. $result['Game Description'] = cutstring($st); // String: A friendly string name for the game type, eg: "Counter Strike: Source"
  81. $result['AppID'] = cutshort($st); // Short: Steam Application ID
  82. $result['Number of players'] = cutbyte($st); // Byte: The number of players currently on the server
  83. $result['Maximum players'] = cutbyte($st); // Byte: Maximum allowed players for the server
  84. $result['Number of bots'] = cutbyte($st); // Byte: Number of bot players currently on the server
  85. $result['Dedicated'] = cutchar($st); // Char: 'l' for listen, 'd' for dedicated, 'p' for SourceTV
  86. $result['OS'] = cutchar($st); // Char: Host operating system. 'l' for Linux, 'w' for Windows
  87. $result['Password'] = cutbyte($st); // Byte: If set to 0x01, a password is required to join this server
  88. $result['Secure'] = cutbyte($st); // Byte: if set to 0x01, this server is VAC secured
  89. $result['Game Version'] = cutstring($st); // String: The version of the game, eg: "1.0.0.14"
  90. } elseif (substr($st, 0, 1) == "\x6D") {
  91. $result['Type'] = cutchar($st); // Char: 'm' (0x6D) - For GoldSrc
  92. $result['Game IP'] = cutstring($st); // String: Game Server IP address and port
  93. $result['Server Name'] = cutstring($st); // String: The server's name, eg: "Recoil NZ CS Server #1"
  94. $result['Map'] = cutstring($st); // String: The current map being played, eg: "de_dust"
  95. $result['Game Directory'] = cutstring($st); // String: The name of the folder containing the game files, eg: "cstrike"
  96. $result['Game Description'] = cutstring($st); // String: A friendly string name for the game type, eg: "Counter Strike: Source"
  97. $result['Number of players'] = cutbyte($st); // Byte: The number of players currently on the server
  98. $result['Maximum players'] = cutbyte($st); // Byte: Maximum allowed players for the server
  99. $result['Version'] = cutbyte($st); // Byte: Network version
  100. $result['Dedicated'] = cutchar($st); // Char: 'l' for listen, 'd' for dedicated, 'p' for SourceTV
  101. $result['OS'] = cutchar($st); // Char: Host operating system. 'l' for Linux, 'w' for Windows
  102. $result['Password'] = cutbyte($st); // Byte: If set to 0x01, a password is required to join this server
  103. $result['IsMod'] = cutbyte($st); // Byte: If set to 0x01, this byte is followed by ModInfo
  104. $result['Secure'] = cutbyte($st); // Byte: if set to 0x01, this server is VAC secured
  105. $result['Number of bots'] = cutbyte($st); // Byte: Number of bot players currently on the server
  106. if ($result['IsMod'] == 1) {
  107. $result['URLInfo'] = cutstring($st); // String: URL containing information about this mod
  108. $result['URLDL'] = cutstring($st); // String: URL to download this mod
  109. $result['Nul'] = cutbyte($st); // Byte: 0x00
  110. $result['ModVersion'] = cutlong($st); // Long: Version of the installed mod
  111. $result['ModSize'] = cutlong($st); // Long: The download size of this mod
  112. $result['SvOnly'] = cutbyte($st); // Byte: If 1 this is a server side only mod
  113. $result['ClDLL'] = cutbyte($st); // Byte: If 1 this mod has a custom client dll
  114. }
  115. } else return false;
  116. return $result;
  117. }
  118. function A2S_SERVERQUERY_GETCHALLENGE($host, $port){
  119. $st = request("\x57",$host,$port);
  120. if (!$st) return false;
  121. $st = substr($st, 4);
  122. if (substr($st, 0, 1) != "\x41") return false; else return cutlong(substr($st, 1));
  123. }
  124. function A2S_RULES($host, $port, $challenge) {
  125. $st = request("\x56".pastelong($challenge),$host,$port);
  126. if (!$st) return false;
  127. $st=substr($st, 4);
  128. if (substr($st, 0, 1) == "\x41") {
  129. $challenge = cutlong(substr($st, 1));
  130. $st = request("\x56".pastelong($challenge),$host,$port);
  131. if (!$st) return false;
  132. $st = substr($st, 4);
  133. }
  134. if (substr($st, 0, 1) != "\x45") return false;
  135. $result['Type'] = cutchar($st); // Char: Should be equal to 'E'
  136. $result['Num Rules'] = cutshort($st); // Short: The number of rules reported in response
  137. for ($i = 1; $i <= $result['Num Rules']; $i++) {
  138. $result['Rule Name'][$i] = cutstring($st); // String: The name of the rule
  139. $result['Rule Value'][$i] = cutstring($st); // String: The rule's value
  140. }
  141. return $result;
  142. }
  143. function A2S_PLAYER($host, $port, $challenge) {
  144. $st = request("\x55".pastelong($challenge),$host,$port);
  145. if (!$st) return false;
  146. $st = substr($st, 4);
  147. if (substr($st, 0, 1) == "\x41") {
  148. $challenge = cutlong(substr($st, 1));
  149. $st = request("\x55".pastelong($challenge),$host,$port);
  150. if (!$st) return false;
  151. $st = substr($st, 4);
  152. }
  153. if (substr($st, 0, 1) != "\x44") return false;
  154. $result['Type'] = cutchar($st); // Char: Should be equal to 'D'
  155. $result['Num Players'] = cutbyte($st); // Byte: The number of players reported in response
  156. for ($i = 1; $i <= $result['Num Players']; $i++) {
  157. $result['Index'][$i] = cutbyte($st); // Byte: The index into [0.. Num Players] for this entry
  158. $result['Player Name'][$i] = cutstring($st); // String: Player's name
  159. $result['Kills'][$i] = cutlong($st); // Long: Number of kills this player has
  160. $result['Time connected'][$i] = cutfloat($st); // Float: The time in seconds this player has been connected
  161. }
  162. return $result;
  163. }
  164. // assign colors to players
  165. function echo_player($nikita){
  166. // colored players in monitoring
  167. $colored_players = array(
  168. '[UMI7EPATOP] HuKuTa' => 'red',
  169. 'Dima^1^zombie' => 'yellow',
  170. 'k.' => 'green'
  171. );
  172. if(!$colored_players[$nikita]){
  173. return $nikita;
  174. }
  175. else if($colored_players[$nikita]){
  176. $nikita = sprintf("<span style=\"color: %s\">%s</span>",$colored_players[$nikita],$nikita);
  177. return $nikita;
  178. }
  179. }
  180. // write server info by given array data
  181. function echo_server($server){
  182. $srv_info = A2S_INFO($server['ip'],$server['port']); // get server info (map, players etc.)
  183. $srv_noobs = A2S_PLAYER($server['ip'],$server['port']); // get server noobs (Player, biovolf, DON, Devastator etc.)
  184. echo '<link rel="stylesheet" href="http://cshipe.cshost.su/app/front.css">
  185. <ol class="rounded">';
  186. if($srv_info['Maximum players']!=0){
  187. 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/>
  188. <span><font color="#AF9C50">Текущая карта на сервере:</font> </span><span class="count"><font color="#467FC4">'.$srv_info['Map']. '</font></span></center></div>';
  189. }else{
  190. echo '<center><font color="red">Сервер временно недоступен!</font></center><br>';
  191. }
  192. echo '';
  193. if($srv_info['Number of players']>0){
  194. arsort($srv_noobs['Kills']);
  195. foreach($srv_noobs['Kills'] as $key => $val){
  196. echo '<li><a href="#">' .echo_player($srv_noobs['Player Name'][$key]). '<br> (убийств: ' .$val. ')</a></li>';
  197. }
  198. }else{
  199. echo 'На сервере игроки отсутствуют!';
  200. }
  201. echo '</ol>';
  202. }
  203. // now do this shit
  204. if($g[0]){
  205. // write info by provided server id
  206. echo_server($servers[$g]);
  207. }else{
  208. // no server id provided, just write all info from all servers
  209. foreach ($servers as $server) {
  210. echo_server($server);
  211. }
  212. }
  213. ?>