Guest User

Untitled

a guest
Jun 25th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. <?php
  2. /* SOURCE ENGINE QUERY FUNCTION, requires the server ip:port */
  3. function source_query($ip){
  4. $cut = explode("178.239.161.42:27015", $ip);
  5. $HL2_address = $cut[0];
  6. $HL2_port = $cut[1];
  7.  
  8. $HL2_command = "\377\377\377\377TSource Engine Query\0";
  9.  
  10. $HL2_socket = fsockopen("udp://".$HL2_address, $HL2_port, $errno, $errstr,3);
  11. fwrite($HL2_socket, $HL2_command);
  12. $JunkHead = fread($HL2_socket,4);
  13. $CheckStatus = socket_get_status($HL2_socket);
  14.  
  15. if($CheckStatus["unread_bytes"] == 0)return 0;
  16.  
  17. $do = 1;
  18. while($do){
  19. $str = fread($HL2_socket,1);
  20. $HL2_stats.= $str;
  21. $status = socket_get_status($HL2_socket);
  22. if($status["unread_bytes"] == 0){
  23. $do = 0;
  24. }
  25. }
  26. fclose($HL2_socket);
  27.  
  28. $x = 0;
  29. while ($x <= strlen($HL2_stats)){
  30. $x++;
  31. $result.= substr($HL2_stats, $x, 1);
  32. }
  33.  
  34. // ord ( string $string );
  35. $result = str_split($result);
  36. $info['network'] = ord($result[0]);$char = 1;
  37. while(ord($result[$char]) != "%00"){$info['name'] .= $result[$char];$char++;}$char++;
  38. while(ord($result[$char]) != "%00"){$info['map'] .= $result[$char];$char++;}$char++;
  39. while(ord($result[$char]) != "%00"){$info['dir'] .= $result[$char];$char++;}$char++;
  40. while(ord($result[$char]) != "%00"){$info['description'] .= $result[$char];$char++;}$char++;
  41. $info['appid'] = ord($result[$char].$result[($char+1)]);$char += 2;
  42. $info['players'] = ord($result[$char]);$char++;
  43. $info['max'] = ord($result[$char]);$char++;
  44. $info['bots'] = ord($result[$char]);$char++;
  45. $info['dedicated'] = ord($result[$char]);$char++;
  46. $info['os'] = chr(ord($result[$char]));$char++;
  47. $info['password'] = ord($result[$char]);$char++;
  48. $info['secure'] = ord($result[$char]);$char++;
  49. while(ord($result[$char]) != "%00"){$info['version'] .= $result[$char];$char++;}
  50.  
  51. return $info;
  52. }
  53. $q = source_query('202.89.33.158:27016');
  54.  
  55. echo "network: ".$q['network']."<br/>";
  56. echo "name: ".$q['name']."<br/>";
  57. echo "map: ".$q['map']."<br/>";
  58. echo "dir: ".$q['dir']."<br/>";
  59. echo "desc: ".$q['description']."<br/>";
  60. echo "id: ".$q['appid']."<br/>";
  61. echo "players: ".$q['players']."<br/>";
  62. echo "max: ".$q['max']."<br/>";
  63. echo "bots: ".$q['bots']."<br/>";
  64. echo "dedicated: ".$q['dedicated']."<br/>";
  65. echo "os: ".$q['os']."<br/>";
  66. echo "password: ".$q['password']."<br/>";
  67. echo "secure: ".$q['secure']."<br/>";
  68. echo "version: ".$q['version']."<br/>";
  69. ?>
Add Comment
Please, Sign In to add comment