mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Added API to allow getting player latency
This commit is contained in:
parent
6ece799998
commit
fd0b07a0aa
@ -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
|
||||
*/
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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){
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit d6317312eb058402ee39e25e1d55bd08f5b35532
|
||||
Subproject commit 268a93c575c3ffa699e8a66b854834989245bb05
|
Loading…
x
Reference in New Issue
Block a user