Advertisement
SSYT

Functions

Nov 8th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2.     function tokenKeys($length) {
  3.         $keys = array_merge(range(0,9), range('a', 'z'));
  4.         $key = "";
  5.         for($i=0; $i < $length; $i++) {
  6.             $key .= $keys[mt_rand(0, count($keys) - 1)];
  7.         }
  8.         return $key;
  9.     }
  10.  
  11.     function server_source_query($ip)
  12.     {
  13.         $cut = explode(":", $ip);
  14.         $HL2_address = $cut[0];
  15.         $HL2_port = $cut[1];
  16.         $HL2_stats = "";
  17.  
  18.         $HL2_command = "\xFF\xFF\xFF\xFFTSource Engine Query\x00";
  19.         $HL2_socket = @fsockopen("udp://".$HL2_address, $HL2_port, $errno, $errstr, 3);
  20.         fwrite($HL2_socket, $HL2_command); $JunkHead = fread($HL2_socket, 4);
  21.         $CheckStatus = socket_get_status($HL2_socket);
  22.  
  23.         if($CheckStatus["unread_bytes"] == 0)
  24.         {
  25.             return 0;
  26.         }
  27.  
  28.         $do = 1;
  29.         while($do)
  30.         {
  31.             $str = fread($HL2_socket, 1);
  32.             $HL2_stats .= $str;
  33.             $status = socket_get_status($HL2_socket);
  34.             if($status["unread_bytes"] == 0)
  35.             {
  36.                 $do = 0;
  37.             }
  38.         }
  39.         fclose($HL2_socket);
  40.  
  41.         $x = 0; $result = "";
  42.         while ($x <= strlen($HL2_stats))
  43.         {
  44.             $x++;
  45.             $result .= substr($HL2_stats, $x, 1);
  46.         }
  47.         $result = urlencode($result); // the output
  48.         return $result;
  49.     }
  50.  
  51.     function server_read_query($string)
  52.     {
  53.         $string = str_replace('%07','',$string);
  54.         $string = str_replace("%00","|||",$string);
  55.         $sinfo = urldecode($string);
  56.         $sinfo = explode('|||', $sinfo);
  57.         $info['hostname'] = $sinfo[0];
  58.         $info['map'] = $sinfo[1];
  59.         $info['game'] = $sinfo[3];
  60.         return $info;
  61.     }
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement