Guest User

Untitled

a guest
May 20th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. function Query($ip, $port)
  2. {
  3.  $fp = fsockopen($ip, $port, $errno, $errstr, 10);
  4.  if(!$fp) {return 'hujnia ne servas bl';}
  5.  else
  6.  {
  7.  fputs($fp, "\xFE");
  8.  fflush($fp);
  9.  $out = "";
  10.  while(!feof($fp))
  11.    $out .= fgets($fp);
  12.  fclose($fp);
  13.  $out = preg_replace("/[^a-zA-Z0-9\/_|+ .-\xA7]/", "",$out);
  14.  $expo = explode("\xA7",$out);
  15.  //return print_r($expo);
  16.  return Array(
  17.    'HostName'   => $expo[0],
  18.    'Players'    => $expo[1],
  19.    'MaxPlayers' => $expo[2]
  20.   );
  21.   }
  22. }
  23. /*
  24.     function Query($IP, $Port)
  25.     {
  26.         $Socket = Socket_Create( AF_INET, SOCK_STREAM, SOL_TCP );
  27.         if( $Socket === FALSE || @Socket_Connect( $Socket, $IP, (int)$Port ) === FALSE )
  28.         {
  29.             return 'asd';
  30.         }
  31.        
  32.         Socket_Send( $Socket, "\xFE", 1, 0 );
  33.         $Len = Socket_Recv( $Socket, $Data, 256, 0 );
  34.         Socket_Close( $Socket );
  35.        
  36.         if( $Len < 4 || $Data[ 0 ] != "\xFF" )
  37.         {
  38.             return FALSE;
  39.         }
  40.        
  41.         $Data = SubStr( $Data, 3 );
  42.         $Data = iconv( 'UTF-16BE', 'UTF-8', $Data );
  43.         $Data = Explode( "\xA7", $Data );
  44.         return Array(
  45.             'HostName'   => SubStr( $Data[ 0 ], 0, -1 ),
  46.             'Players'    => isset( $Data[ 1 ] ) ? IntVal( $Data[ 1 ] ) : 0,
  47.             'MaxPlayers' => isset( $Data[ 2 ] ) ? IntVal( $Data[ 2 ] ) : 0
  48.         );
  49.     }
  50. */
Add Comment
Please, Sign In to add comment