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

get Ping in ms

Comments in 'Plugin Development' started by Bluplayz, Feb 7, 2016.

  1. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    how i can get the Ping from a player?
  2. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    I don't think that's possible.
  3. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    hmm sure? i think the Plugin "PingKick" had it , but i found this->

    PHP:
    public function join($data$event){
      switch(
    $event){
      case 
    "player.spawn":
      
    $this->api->schedule(20, array($this"join"), array(), true);
      
    $ping round($data->getLag(), 2);
      if(
    $this->pingcheck !== 0){
      if(
    $this->enabled == "true"){
      if(
    $this->pingkick $ping){
      
    $this->server->api->ban->kick($data->username"Ping was too high");
      }else{
      break;
      }  
    }else{  
    break;
    //this function looks like a jet fighter lol :P  }  }else{  break;  }  }  }

    but dont know what $data is, here is the full "plugin" , its only one php file

    https://github.com/ZacHack/PingKick/blob/master/PingKick.php
  4. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4

    Oh, I never have seen getLag function...
  5. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    me too but i think he mean it so:
    PHP:
    $data = new Data($this"blabla");
    and then he wants to use there own function -> Data::getLag();
  6. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Theoretically as you can obtain the Player IP Adress you can handle the ping yourself
  7. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    What an IP is? An IP is an "license plate".
    You can know how many kilometers have a car by his license plate?
  8. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    No, but you can send ping requests to that IP:port...
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    fsocketopen I believe.
    PocketKiller and applqpak like this.
  10. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Exactly.

    Example:
    PHP:
    $tB microtime(true);
    $socket fSockOpen($player->getAddress(), 80$errno$errstr10);
    if(!(
    $socket)) {
      
    $this->getServer()->getLogger()->info($player->getAddress() . " was uncreachable.");
    }
    $tA microtime(true);
    $ping round((($tA $tB) * 1000), 0);
    $this->getServer()->getLogger()->info("Ping of " $player->getAddress() . " was: " $ping ".ms");
    PocketKiller and Vaivez66 like this.
  11. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    That would ping the port 80
  12. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    dont forget to consider some host ignore ping and some are firewalled
  13. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Yeah, you need to ping on port 80 for website/home connections..... Duh.
  14. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I would take the port of the mcpe client...
  15. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    but what if the thing on 80 have slow response
    and why dont see what the function $this->getlag() does?
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    As of PocketMine 1.4 onwards, ping is a value only known by RakLib. PocketMine and its plugins cannot know its value.
    Using `ping` on an IP address may not always succeed. Some routers simply reject your attempts to ping it.
    This will block the main thread for a period of time. This will lag the server.
    This is something from PocketMine 1.3
    https://github.com/PocketMine/Pocke...55a4f03e6de084967c971cd7/src/Player.php#L1061 Alpha_1.3 stuff
    https://github.com/PocketMine/Pocke...55a4f03e6de084967c971cd7/src/Player.php#L1054
    Last edited: Feb 8, 2016
  17. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    so?
    extend RakLib or make a ping function?
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    So it is not possible.

    Moreover, the value returned from `ping` doesn't return the exact latency between server and the client.
    Last edited: Feb 8, 2016
    Thunder33345 likes this.

Share This Page

Advertisement