ProfesseurCraft

get info server minecraft

Oct 6th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. <?php
  2.  
  3. class Stats
  4. {
  5.     private $Host;
  6.     private $Socket;
  7.     private $Is_online;
  8.    
  9.     private $Data;
  10.    
  11.     private $Version;
  12.     private $Motd;
  13.     private $Players_online;
  14.     private $Slots;
  15.  
  16.     public function Connect($server){
  17.  
  18.             $this->Host = explode(':',$server);
  19.             $this->Socket = @fsockopen($this->Host[0], $this->Host[1], $errno, $errstr, 1);
  20.            
  21.                 //Stream_Set_Timeout( $this->Socket, $Timeout );
  22.                 //Stream_Set_Blocking( $this->Socket, true );
  23.                
  24.                 if( $errno || $this->Socket === false )
  25.                 {
  26.                     return false;
  27.                 }
  28.                 else{
  29.                     return true;
  30.                    
  31.                     fwrite($this->Socket, "\xFE\x01");
  32.              
  33.                     $this->Data = fread($this->Socket, 1024);
  34.                     if ($this->Data != false AND substr($this->Data, 0, 1) == "\xFF") {
  35.                         $this->Data = substr($this->Data, 3);
  36.                         $this->Data = mb_convert_encoding($this->Data, 'auto', 'UCS-2');
  37.                         $this->Data = explode("\x00", $this->Data);
  38.                         fclose($this->Socket);
  39.                     }
  40.                 }
  41.             }
  42.            
  43.             public function Version()
  44.             {
  45.                 return $this->Version = $this->Data[2];
  46.             }
  47.  
  48.             public function Motd()
  49.             {
  50.                 return $this->Motd = $this->Data[3];
  51.             }
  52.            
  53.             public function Players_online()
  54.             {
  55.                 return $this->Players_online = $this->Data[4];
  56.             }
  57.            
  58.             public function Slots()
  59.             {
  60.                 return $this->Slots = $this->Data[5];
  61.             }
  62.  
  63. }
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment