Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How can I get the online Players of an other Server?

Comments in 'Plugin Development' started by TheBison_, Jun 6, 2016.

  1. TheBison_
    Offline

    TheBison_ New Member

    Joined:
    Mar 31, 2014
    Posts:
    46
    Minecraft User:
    TheBisonXD_
    Please help me out ^^
  2. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Primus likes this.
  3. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    PHP:
    $server_IP "example.com";

    $server_port 19132;

    $MCAPI json_decode(file_get_contents("http://mcapi.ca/query/" $server_IP ":" $server_port .  "/mcpe"));

    $online_players $MCAPI->players->online;

    foreach(
    $online_players as $player)
    {

      
    // code here...

    }
    I suggest you not to run this on the main thread, as this WILL cause your server to stop for a few seconds.
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I don't suggest working with an API of someone else. What if this site is down? What if it gets shut down?

    Better create your own query or simply use MySQL.
    applqpak and SOFe like this.
  5. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    This is the way i do it (the doQuery function is not fully written by me though)
    And please note that this code is in a async task :)
    PHP:
      private function doQuery($ip$port){
         echo(
    "doQuery:\n");
          
    $sock = @fsockopen("udp://".$ip,$port);
          if(!
    $sock){return [-1NULL];}
          
    socket_set_timeout($sock0500000);
          if([email protected]
    fwrite($sock"\xFE\xFD\x09\x10\x20\x30\x40\xFF\xFF\xFF\x01")){return [0NULL];}
          
    $challenge fread($sock1400);
          if(!
    $challenge){return [0NULL];}
          
    $challenge substr(preg_replace("/[^0-9\-]/si"""$challenge ), 1);
          
    $query sprintf(
              
    "\xFE\xFD\x00\x10\x20\x30\x40%c%c%c%c\xFF\xFF\xFF\x01",
              (
    $challenge >> 24),
              (
    $challenge >> 16),
              (
    $challenge >> 8),
              (
    $challenge >> 0)
              );
          if([email protected]
    fwrite($sock$query)){return [0NULL];}
          
    $response = array();
          for(
    $x 0$x 2$x++){
              
    $response[] = @fread($sock,2048);
          }
         if(
    $this->debug){
             
    var_dump($response);#
          
    }
          
    $response implode($response);
          
    $response substr($response,16);
          
    $response explode("\0",$response);
         if(
    $this->debug){
             
    var_dump($response);#
         
    }
          
    array_pop($response);
          
    array_pop($response);
          
    array_pop($response);
          
    array_pop($response);
          
    $return = [];
          
    $type 0;
         if(
    $this->debug){
             
    var_dump($response);#
          
    }
          foreach (
    $response as $key){
              if (
    $type == 0$val $key;
              if (
    $type == 1$return[$val] = $key;
              
    $type == $type $type 0;
         }   
           return [
    1$return]; 
         echo(
    "DoQueryEnd\n");
      }
      public function 
    onRun(){
         echo(
    "DoCheckServer:\n");
         if(
    $this->debug){
             
    var_dump($this->doCheckServer);#
           
    }
         foreach(
    $this->doCheckServer as $server){
             
    $doCheck $server[1];
             if(
    $doCheck){
                 
    $ip $server[0];
                 
    $deParsedIP $ip[0];
                 
    $port $ip[1];
                 
    $return $this->doQuery($deParsedIP$port);
                 
    $returnState $return[0];
                 
    $queryResult $return[1];
                 
    $serverData = [];
                 echo(
    "returnState:\n");
                 
    var_dump($returnState);
                 switch(
    $returnState){
                     case -
    1;
                         
    $serverData[2] = false;
                     break;
                     case 
    0:
                         
    $serverData[2] = false;
                     break;
                     case 
    1:
                         
    $serverData[0] = [$queryResult['numplayers'], $queryResult['maxplayers']];
                         
    $serverData[1] = $queryResult['hostname'];
                         
    $serverData[2] = true;
                 }
                 
    $serverFINALdata[$deParsedIP.$port] = $serverData;
                 
    $this->setResult($serverFINALdata);
             }
         }
    Thunder33345 likes this.
  6. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    This thread is useless, because a normal PocketMine server stops, when you do that operations.
  7. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
  8. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    If you own the 2 Servers use mysql!
  9. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    WTF?
    If you mean it laggs use a AsyncTask!
    I almost posted the full code above -_-
    Last edited: Jun 7, 2016
  10. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Yes, it was just simple example ;) plus, you could just open a quick socket to the host to check if it's down.
  11. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    If you use multiple servers, MySQL isn't the best solution. Better write your own CGI.
    applqpak likes this.
  12. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Are you all simply ignoring the code i posted?
  13. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Nope. But your code is for "stranger" servers. I am talking about network servers.
  14. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    no also happens on @applqpak code
  15. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Every medicine, if abused, can be fatal.
    applqpak likes this.

Share This Page

Advertisement