mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 07:09:56 +00:00
Move responsibility for ping handling to NetworkSession
This commit is contained in:
parent
57e5b1309d
commit
ca1a0c8643
@ -168,13 +168,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
/** @var NetworkSession */
|
/** @var NetworkSession */
|
||||||
protected $networkSession;
|
protected $networkSession;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
* Last measurement of player's latency in milliseconds.
|
|
||||||
*/
|
|
||||||
protected $lastPingMeasure = 1;
|
|
||||||
|
|
||||||
|
|
||||||
/** @var float */
|
/** @var float */
|
||||||
public $creationTime = 0;
|
public $creationTime = 0;
|
||||||
|
|
||||||
@ -798,18 +791,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getPing() : int{
|
public function getPing() : int{
|
||||||
return $this->lastPingMeasure;
|
return $this->networkSession->getPing();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,6 +53,8 @@ class NetworkSession{
|
|||||||
private $ip;
|
private $ip;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $port;
|
private $port;
|
||||||
|
/** @var int */
|
||||||
|
private $ping;
|
||||||
|
|
||||||
/** @var SessionHandler */
|
/** @var SessionHandler */
|
||||||
private $handler;
|
private $handler;
|
||||||
@ -86,6 +88,24 @@ class NetworkSession{
|
|||||||
return $this->port;
|
return $this->port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the last recorded ping measurement for this session, in milliseconds.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getPing() : int{
|
||||||
|
return $this->ping;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal Called by the network interface to update last recorded ping measurements.
|
||||||
|
*
|
||||||
|
* @param int $ping
|
||||||
|
*/
|
||||||
|
public function updatePing(int $ping) : void{
|
||||||
|
$this->ping = $ping;
|
||||||
|
}
|
||||||
|
|
||||||
public function getHandler() : SessionHandler{
|
public function getHandler() : SessionHandler{
|
||||||
return $this->handler;
|
return $this->handler;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
|
|||||||
|
|
||||||
public function updatePing(string $identifier, int $pingMS) : void{
|
public function updatePing(string $identifier, int $pingMS) : void{
|
||||||
if(isset($this->players[$identifier])){
|
if(isset($this->players[$identifier])){
|
||||||
$this->players[$identifier]->updatePing($pingMS);
|
$this->players[$identifier]->getNetworkSession()->updatePing($pingMS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user