Jump to content

To175

Members
  • Posts

    86
  • Joined

  • Last visited

Posts posted by To175

  1. If I use this code, I have this error :

    Failed to receive challenge.

    CODE :

    <?php
       require __DIR__ . '/MinecraftQuery.class.php';
       $Query = new MinecraftQuery( );
       try
       {
        $Query->Connect( 'localhost', 25565 );
        print_r( $Query->GetInfo( ) );
        print_r( $Query->GetPlayers( ) );
       }
       catch( MinecraftQueryException $e )
       {
        echo $e->getMessage( );
       }
    ?>
    

    With this class :

    <?php
    class MinecraftQueryException extends Exception
    {
    // Exception thrown by MinecraftQuery class
    }
    class MinecraftQuery
    {
    /*
     * Class written by xPaw
     *
     * Website: http://xpaw.ru
     * GitHub: https://github.com/xPaw/PHP-Minecraft-Query
     */
    private $Socket;
    private $Challenge;
    private $Players;
    private $Info;
    public function Connect( $Ip = 'serveurmecraft.tk', $Port = 10252, $Timeout = 3 )
    {
     if( $this->Socket = FSockOpen( 'udp://' . $Ip, (int)$Port ) )
     {
      Socket_Set_TimeOut( $this->Socket, $Timeout );
      if( !$this->GetChallenge( ) )
      {
       FClose( $this->Socket );
       throw new MinecraftQueryException( "Failed to receive challenge." );
      }
      if( !$this->GetStatus( ) )
      {
       FClose( $this->Socket );
       throw new MinecraftQueryException( "Failed to receive status." );
      }
      FClose( $this->Socket );
     }
     else
     {
      throw new MinecraftQueryException( "Can't open connection." );
     }
    }
    public function GetInfo( )
    {
     return isset( $this->Info ) ? $this->Info : false;
    }
    public function GetPlayers( )
    {
     return isset( $this->Players ) ? $this->Players : false;
    }
    private function GetChallenge( )
    {
     $Data = $this->WriteData( "\x09" );
     if( !$Data )
     {
      return false;
     }
     $this->Challenge = Pack( 'N', $Data );
     return true;
    }
    private function GetStatus( )
    {
     $Data = $this->WriteData( "\x00", $this->Challenge . "\x01\x02\x03\x04" );
     if( !$Data )
     {
      return false;
     }
     $Last = "";
     $Info = Array( );
     $Data    = SubStr( $Data, 11 ); // splitnum + 2 int
     $Data    = Explode( "\x00\x00\x01player_\x00\x00", $Data );
     $Players = SubStr( $Data[ 1 ], 0, -2 );
     $Data    = Explode( "\x00", $Data[ 0 ] );
     // Array with known keys in order to validate the result
     // It can happen that server sends custom strings containing bad things (who can know!)
     $Keys = Array(
      'hostname'   => 'HostName',
      'gametype'   => 'GameType',
      'version'    => 'Version',
      'map'	    => 'Map',
      'numplayers' => 'Players',
      'maxplayers' => 'MaxPlayers',
      'hostport'   => 'HostPort',
      'hostip'	 => 'HostIp'
     );
     foreach( $Data as $Key => $Value )
     {
      if( ~$Key & 1 )
      {
       if( !Array_Key_Exists( $Value, $Keys ) )
       {
     $Last = false;
     continue;
       }
       $Last = $Keys[ $Value ];
       $Info[ $Last ] = "";
      }
      else if( $Last != false )
      {
       $Info[ $Last ] = $Value;
      }
     }
     // Ints
     $Info[ 'Players' ]    = IntVal( $Info[ 'Players' ] );
     $Info[ 'MaxPlayers' ] = IntVal( $Info[ 'MaxPlayers' ] );
     $Info[ 'HostPort' ]   = IntVal( $Info[ 'HostPort' ] );
     // Parse "plugins", if any
     if( $Info[ 'Plugins' ] )
     {
      $Data = Explode( ": ", $Info[ 'Plugins' ], 2 );
      $Info[ 'RawPlugins' ] = $Info[ 'Plugins' ];
      $Info[ 'Software' ]   = $Data[ 0 ];
      if( Count( $Data ) == 2 )
      {
       $Info[ 'Plugins' ] = Explode( "; ", $Data[ 1 ] );
      }
     }
     else
     {
      $Info[ 'Software' ] = 'Vanilla';
     }
     $this->Info = $Info;
     if( $Players )
     {
      $this->Players = Explode( "\x00", $Players );
     }
     return true;
    }
    private function WriteData( $Command, $Append = "" )
    {
     $Command = "\xFE\xFD" . $Command . "\x01\x02\x03\x04" . $Append;
     $Length  = StrLen( $Command );
     if( $Length !== FWrite( $this->Socket, $Command, $Length ) )
     {
      return false;
     }
     $Data = FRead( $this->Socket, 1440 );
     if( StrLen( $Data ) < 5 || $Data[ 0 ] != $Command[ 2 ] )
     {
      return false;
     }
     return SubStr( $Data, 5 );
    }
    }
    

  2. Hoookey boy ! yOU are fantastic !! I'm really not handy with thoses codes...

    Hum in better proper english, may I have your entire script please ?!

     

    => my server is Mecraft.omgcraft.fr:10252 and I CAN'T change this port.

     

    <?php
    $ip = 'mecraft.omgcraft.fr';
    $port = 10252;
    $onlinePlayers = 0;
    $maxPlayers = 0;
    $serverMotd = 'TESTTT';
    $serverSock = @stream_socket_client('tcp://'.$ip.':'.$port, $empty, $empty, 1);
    
    if($serverSock !== FALSE)
    {
       fwrite($serverSock, "\xfe");
      
       $response = fread($serverSock, 2048);
       $response = str_replace("\x00", '', $response);
       $response = substr($response, 2);
      
       $data = explode("\xa7", $response);
      
       unset($response);
       fclose($serverSock);
       if(sizeof($data) == 3)
       {
        $serverMotd = $data[0];
        $onlinePlayers = (int) $data[1];
        $maxPlayers = (int) $data[2];
       
        echo $serverMotd.'<br/>';
        echo $onlinePlayers.'/'.$maxPlayers.' player(s) online.';
       }else{
        echo 'Could not connect.';
       }
    }else{
       echo 'Server is offline.';
    }
    ?>
    

     

    This code just display "server is offline" :'(

     

    in my server.proprieties

    query.port=10252

    rcon.port=40729

    server-port=10252

  3. Thank,

    But this is not the question :s

    I have tested all codes I could, I dont have them anymore...

    I though the problem is because of the port but I don't think so now.

    I really don't want to use a plugin in my server to do that !

     

    Ok, for example This doesn't work for me

    http://www.webmaster-source.com/2012/07/05/checking-the-status-of-a-minecraft-server-with-php/

    I used my server : Mecraft.omgcraft.fr with port 10252

     

    Help please :(

  4. What do you need three ports for?
    Since you didn't really answer this question I'll ask it in a different way. Why can't you just use one port?

    I need 3 because the autors of the plugin said that JSONAPI takes the "first" port and the 2 other ports following...

    I'm a little afraid because the moderators said I can't have those ports ? :(/&--#62;

  5. Hi, thanks you very much for your answer and to spend so much time for us !

     

    I have a minecraft server : 3 years paid ! So I am making a support website (http://sciences.webfrag.tk/minecraft)

     

    That is why I need to interact site/server. There is a plugin called JSONAPI and it need 3 ports, consecutive ports.

    My minecraft host can't open other ports than : 1 88.191.242.16 40086

    2 88.191.242.16 40087

    3 88.191.242.16 40088

    4 88.191.242.16 40089

    5 88.191.242.16 40090

    So if you can open 40086 or 40086 or 40088 and the 2 ports following (3 in all) it will be great :)

     

     

     

    Thanks you

  6. Hi, I need to use JSONAPI for my minecraft server. I want to user varients of my server for my site !

    I use the port 40088 on my server.

    I use this code to connect to my server :

    <?php
    require 'JSONAPI.php';
    $api = new JSONAPI("88.191.242.16", 40088, "to175", "password", "salt");
    var_dump($api->call("getPlayerLimit"));
    ?>
    

     

    But I see on the page : "NULL"

    The minecraft hoster said that it can have for origine my site, because of the port which cannot be open?

     

    So why I see NULL on my page? I can't use 40088 ?

     

     

    Thanks

×
×
  • Create New...