diff --git a/src/pocketmine/network/AdvancedNetworkInterface.php b/src/pocketmine/network/AdvancedNetworkInterface.php index 1e54275b2..42c1ef62d 100644 --- a/src/pocketmine/network/AdvancedNetworkInterface.php +++ b/src/pocketmine/network/AdvancedNetworkInterface.php @@ -68,23 +68,4 @@ interface AdvancedNetworkInterface extends NetworkInterface{ * @param string $regex */ 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; } diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 654ff4070..a1e872cb3 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -49,6 +49,9 @@ class Network{ /** @var int[] */ private $bannedIps = []; + private $upload = 0; + private $download = 0; + /** @var string */ private $name; @@ -64,26 +67,22 @@ class Network{ $this->logger = $logger; } + public function addStatistics(float $upload, float $download) : void{ + $this->upload += $upload; + $this->download += $download; + } + public function getUpload() : float{ - $result = 0; - foreach($this->advancedInterfaces as $interface){ - $result += $interface->getBytesSent(); - } - return $result; + return $this->upload; } public function getDownload() : float{ - $result = 0; - foreach($this->advancedInterfaces as $interface){ - $result += $interface->getBytesReceived(); - } - return $result; + return $this->download; } public function resetStatistics() : void{ - foreach($this->advancedInterfaces as $interface){ - $interface->resetTrafficStats(); - } + $this->upload = 0; + $this->download = 0; } /** diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index 3565dc825..70b30033e 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -77,11 +77,6 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ /** @var SleeperNotifier */ private $sleeper; - /** @var int */ - private $sendBytes = 0; - /** @var int */ - private $receiveBytes = 0; - public function __construct(Server $server){ $this->server = $server; @@ -226,8 +221,7 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ public function handleOption(string $option, string $value) : void{ if($option === "bandwidth"){ $v = unserialize($value); - $this->sendBytes = $v["up"]; - $this->receiveBytes = $v["down"]; + $this->network->addStatistics($v["up"], $v["down"]); } } @@ -249,16 +243,4 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ $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; - } }