Advertisement
Guest User

serverlist base

a guest
Dec 19th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.05 KB | None | 0 0
  1. /* SrcSrv.CLASS.php */
  2. <?php
  3. class BinHelp {
  4.     function __construct($binstring) {
  5.         $this->binstring = $binstring;
  6.         $this->position = 0;
  7.         $this->length = strlen($this->binstring);
  8.     }
  9.    
  10.     function subbin($bytes) {
  11.         if($this->position + $bytes <= $this->length) {
  12.             $sub = substr($this->binstring, $this->position, $bytes);
  13.             $this->position += $bytes;
  14.             return $sub;       
  15.         } else { return false; }
  16.                     }
  17.    
  18.     function remaining() { return $this->length - $this->position; }
  19.    
  20.     function int8() { if($sub = $this->subbin(1)) return ord($sub); else return false; }   
  21.     function int16() { if($sub = $this->subbin(2)) { $subsub = unpack("v", $sub); return $subsub[1]; } else return false; }
  22.     function int32() { if($sub = $this->subbin(4)) { $subsub = unpack("V", $sub); return $subsub[1]; } else return false; }
  23.     function float32() { if($sub = $this->subbin(4)) { $subsub = unpack("f", $sub); return $subsub[1]; } else return false; }
  24.     function zstring() {
  25.         if($zterm = strpos($this->binstring, "\0", $this->position)) {
  26.             $sub = $this->subbin($zterm - $this->position);
  27.             $this->position++;
  28.             return $sub;
  29.         }
  30.     }
  31. }
  32.  
  33. class SrcSrv {
  34.     function __construct($server) {
  35.         $this->sock = stream_socket_client("udp://$server");
  36.         stream_set_timeout($this->sock, 2);
  37.         $this->Challenge();
  38.     }
  39.    
  40.     function Challenge() {
  41.         fwrite($this->sock, "\xff\xff\xff\xffU\xFF\xFF\xFF\xFF");
  42.         $resp = fread($this->sock, 1500);
  43.        
  44.         if($resp && $resp[4] == "A") {
  45.             $hb = new BinHelp($resp);
  46.             $hb->subbin(5);
  47.             $this->Challenge = $hb->subbin(4);
  48.             return true;
  49.         }
  50.         return false;
  51.     }
  52.    
  53.     function Info() {
  54.         fwrite($this->sock, "\xff\xff\xff\xffTSource Engine Query\0");
  55.         $resp = fread($this->sock, 1500);
  56.    
  57.         if($resp && $resp[4] == "I") {
  58.             $bh = new BinHelp($resp);
  59.             $bh->subbin(6);
  60.             $retn["name"] = $bh->zstring();
  61.             $retn["map"] = $bh->zstring();
  62.             $retn["gamedir"] = $bh->zstring();
  63.             $retn["desc"] = $bh->zstring();
  64.             $retn["appid"] = $bh->int16();
  65.             $retn["players"] = $bh->int8();
  66.             $retn["max"] = $bh->int8();
  67.             $retn["bots"] = $bh->int8();
  68.             $retn["dedi"] = $bh->subbin(1);
  69.             $retn["os"] = $bh->subbin(1);
  70.             $retn["password"] = (bool)$bh->int8();
  71.             $retn["vac"] = (bool)$bh->int8();
  72.             $retn["version"] = $bh->zstring();
  73.  
  74.             if($edf = $bh->int8()) {
  75.                 if($edf & 0x80)
  76.                     $retn["port"] = $bh->int16();
  77.                 if($edf & 0x20)
  78.                     $retn["tags"] = $bh->zstring();
  79.             }
  80.        
  81.             return $retn;
  82.         }
  83.    
  84.         return false;
  85.     }
  86.    
  87.     function Players() {
  88.         fwrite($this->sock, "\xff\xff\xff\xffU" . $this->Challenge);
  89.         $resp = fread($this->sock, 1500);
  90.        
  91.         if($resp && $resp[4] == "D") {
  92.             $hb = new BinHelp($resp);
  93.             $hb->subbin(6-1); // -1 fixed this.
  94.             $players = $hb->int8();
  95.             while($hb->remaining() > 0) {
  96.                 $hb->int8();
  97.                 $retn[] = array("name" => $hb->zstring(), "score" => $hb->int32(), "time" => $hb->float32()/60 );
  98.             }
  99.             return $retn;
  100.         }
  101.        
  102.         return false;
  103.     }
  104. }
  105. ?>
  106.  
  107.  
  108. <?php
  109. /* setup */
  110.  
  111. $server = new SrcSrv("ip:port");
  112. $info = $server->Info(); // $info['name'] ['map'] ['players'] ['max'] , you get the point
  113. $players = $server->Players(); // $players['name'] ['score'] ['time']
  114. $checkin = $time + 60*5;
  115. $time = file_get_contents("time.cache");
  116.  
  117. /* remove this line after running it once */
  118.  
  119. file_put_contents("time.cache", time());
  120.  
  121. /* this stores data */
  122.  
  123. if ($checkin >= $time + 60*5)
  124. {
  125.     /* these two for every server lol, kind of drawlin, but it cut load time down for me */
  126.     file_put_contents("info.cache", $info);
  127.     file_put_contents("players.cache", $players);
  128.     /* these two for every server lol, kind of drawlin, but it cut load time down for me */
  129.     file_put_contents("time.cache", time());
  130. }
  131.  
  132. /* the echo code */
  133.  
  134. $info1 = file("info.cache");
  135. $players1 = file("players.cache");
  136.  
  137. echo "<table><tbody>
  138.     <tr>
  139.     <td> GMOD_ICON_HERE </td>
  140.     <td> Server Name </td>
  141.     <td>".$info1['map']."</td>
  142.     <td>".$info1['gamedir']."</td>
  143.     <td>".$info1['players']." / ".$info1['max']."</td></tr>";
  144.  
  145. echo "<tr><td>NextServerStuff, copy/paste/edit, gg";
  146.  
  147.  
  148. /* end the table */
  149. echo "</tbody></table>";
  150.  
  151. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement