mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 14:35:35 +00:00
Revert "Network: Each interface now keeps its own statistics"
This reverts commit 7720a0534e3c4f0dcc70cf3fbc12699de6f04374.
This commit is contained in:
parent
7720a0534e
commit
86cc151e60
@ -68,23 +68,4 @@ interface AdvancedNetworkInterface extends NetworkInterface{
|
|||||||
* @param string $regex
|
* @param string $regex
|
||||||
*/
|
*/
|
||||||
public function addRawPacketFilter(string $regex) : void;
|
public function addRawPacketFilter(string $regex) : void;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of bytes sent on this network interface since the last statistics reset.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getBytesSent() : int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of bytes received on this network interface since the last statistics reset.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getBytesReceived() : int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resets the upload/download statistics to zero.
|
|
||||||
*/
|
|
||||||
public function resetTrafficStats() : void;
|
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,9 @@ class Network{
|
|||||||
/** @var int[] */
|
/** @var int[] */
|
||||||
private $bannedIps = [];
|
private $bannedIps = [];
|
||||||
|
|
||||||
|
private $upload = 0;
|
||||||
|
private $download = 0;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $name;
|
private $name;
|
||||||
|
|
||||||
@ -64,26 +67,22 @@ class Network{
|
|||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addStatistics(float $upload, float $download) : void{
|
||||||
|
$this->upload += $upload;
|
||||||
|
$this->download += $download;
|
||||||
|
}
|
||||||
|
|
||||||
public function getUpload() : float{
|
public function getUpload() : float{
|
||||||
$result = 0;
|
return $this->upload;
|
||||||
foreach($this->advancedInterfaces as $interface){
|
|
||||||
$result += $interface->getBytesSent();
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDownload() : float{
|
public function getDownload() : float{
|
||||||
$result = 0;
|
return $this->download;
|
||||||
foreach($this->advancedInterfaces as $interface){
|
|
||||||
$result += $interface->getBytesReceived();
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resetStatistics() : void{
|
public function resetStatistics() : void{
|
||||||
foreach($this->advancedInterfaces as $interface){
|
$this->upload = 0;
|
||||||
$interface->resetTrafficStats();
|
$this->download = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,11 +77,6 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
|
|||||||
/** @var SleeperNotifier */
|
/** @var SleeperNotifier */
|
||||||
private $sleeper;
|
private $sleeper;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
private $sendBytes = 0;
|
|
||||||
/** @var int */
|
|
||||||
private $receiveBytes = 0;
|
|
||||||
|
|
||||||
public function __construct(Server $server){
|
public function __construct(Server $server){
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
|
|
||||||
@ -226,8 +221,7 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
|
|||||||
public function handleOption(string $option, string $value) : void{
|
public function handleOption(string $option, string $value) : void{
|
||||||
if($option === "bandwidth"){
|
if($option === "bandwidth"){
|
||||||
$v = unserialize($value);
|
$v = unserialize($value);
|
||||||
$this->sendBytes = $v["up"];
|
$this->network->addStatistics($v["up"], $v["down"]);
|
||||||
$this->receiveBytes = $v["down"];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,16 +243,4 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
|
|||||||
$this->sessions[$sessionId]->updatePing($pingMS);
|
$this->sessions[$sessionId]->updatePing($pingMS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBytesSent() : int{
|
|
||||||
return $this->sendBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBytesReceived() : int{
|
|
||||||
return $this->receiveBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function resetTrafficStats() : void{
|
|
||||||
$this->sendBytes = $this->receiveBytes = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user