diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index c67d21511..ce6744d24 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -300,6 +300,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** @var string */ protected $locale = "en_US"; + /** + * @var int + * Last measurement of player's latency in milliseconds. + */ + protected $lastPingMeasure = 1; + /** * @return TranslationContainer|string */ @@ -802,6 +808,27 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return $this->port; } + /** + * Returns the last measured latency for this player, in milliseconds. This is measured automatically and reported + * back by the network interface. + * + * @return int + */ + public function getPing() : int{ + return $this->lastPingMeasure; + } + + /** + * Updates the player's last ping measurement. + * + * @internal Plugins should not use this method. + * + * @param int $pingMS + */ + public function updatePing(int $pingMS){ + $this->lastPingMeasure = $pingMS; + } + /** * @return Position */ diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 8c10cf69f..5c28a70b1 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -167,8 +167,8 @@ namespace pocketmine { exit(1); } - if(version_compare(RakLib::VERSION, "0.8.1") < 0){ - echo "[CRITICAL] RakLib version 0.8.1 is required, while you have version " . RakLib::VERSION . "." . PHP_EOL; + if(version_compare(RakLib::VERSION, "0.8.2") < 0){ + echo "[CRITICAL] RakLib version 0.8.2 is required, while you have version " . RakLib::VERSION . "." . PHP_EOL; echo "[CRITICAL] Please update your submodules or use provided builds." . PHP_EOL; exit(1); } diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index 2d595b8aa..7d888b448 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -237,6 +237,12 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ return null; } + public function updatePing(string $identifier, int $pingMS){ + if(isset($this->players[$identifier])){ + $this->players[$identifier]->updatePing($pingMS); + } + } + private function getPacket($buffer){ $pid = ord($buffer{0}); if(($data = PacketPool::getPacketById($pid)) === null){ diff --git a/src/raklib b/src/raklib index d6317312e..268a93c57 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit d6317312eb058402ee39e25e1d55bd08f5b35532 +Subproject commit 268a93c575c3ffa699e8a66b854834989245bb05