This commit is contained in:
Dylan K. Taylor 2020-07-21 16:18:14 +01:00
parent ff54eae4b2
commit 92afad5e6f
2 changed files with 17 additions and 12 deletions

8
composer.lock generated
View File

@ -623,12 +623,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/pmmp/RakLib.git", "url": "https://github.com/pmmp/RakLib.git",
"reference": "31e2b2259404399cac7f50ae4a9bbdfdd8c1035e" "reference": "6fbccdb6a7cf47ebcb411803aa023cf688aae8c7"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/pmmp/RakLib/zipball/31e2b2259404399cac7f50ae4a9bbdfdd8c1035e", "url": "https://api.github.com/repos/pmmp/RakLib/zipball/6fbccdb6a7cf47ebcb411803aa023cf688aae8c7",
"reference": "31e2b2259404399cac7f50ae4a9bbdfdd8c1035e", "reference": "6fbccdb6a7cf47ebcb411803aa023cf688aae8c7",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -654,7 +654,7 @@
"GPL-3.0" "GPL-3.0"
], ],
"description": "A RakNet server implementation written in PHP", "description": "A RakNet server implementation written in PHP",
"time": "2020-06-17T12:01:42+00:00" "time": "2020-07-21T12:33:41+00:00"
}, },
{ {
"name": "pocketmine/snooze", "name": "pocketmine/snooze",

View File

@ -43,6 +43,7 @@ use raklib\utils\InternetAddress;
use function addcslashes; use function addcslashes;
use function bin2hex; use function bin2hex;
use function implode; use function implode;
use function microtime;
use function mt_rand; use function mt_rand;
use function random_bytes; use function random_bytes;
use function rtrim; use function rtrim;
@ -82,9 +83,13 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
/** @var SleeperNotifier */ /** @var SleeperNotifier */
private $sleeper; private $sleeper;
/** @var float */
private $lastBandwidthReport;
public function __construct(Server $server){ public function __construct(Server $server){
$this->server = $server; $this->server = $server;
$this->rakServerId = mt_rand(0, PHP_INT_MAX); $this->rakServerId = mt_rand(0, PHP_INT_MAX);
$this->lastBandwidthReport = microtime(true);
$this->sleeper = new SleeperNotifier(); $this->sleeper = new SleeperNotifier();
@ -221,7 +226,7 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
public function setName(string $name) : void{ public function setName(string $name) : void{
$info = $this->server->getQueryInformation(); $info = $this->server->getQueryInformation();
$this->interface->setOption("name", implode(";", $this->interface->setName(implode(";",
[ [
"MCPE", "MCPE",
rtrim(addcslashes($name, ";"), '\\'), rtrim(addcslashes($name, ";"), '\\'),
@ -237,18 +242,18 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
} }
public function setPortCheck(bool $name) : void{ public function setPortCheck(bool $name) : void{
$this->interface->setOption("portChecking", $name); $this->interface->setPortCheck($name);
} }
public function setPacketLimit(int $limit) : void{ public function setPacketLimit(int $limit) : void{
$this->interface->setOption("packetLimit", $limit); $this->interface->setPacketsPerTickLimit($limit);
} }
public function handleOption(string $option, string $value) : void{ public function handleBandwidthStats(int $bytesSentDiff, int $bytesReceivedDiff) : void{
if($option === "bandwidth"){ $now = microtime(true);
$v = unserialize($value); $diff = $now - $this->lastBandwidthReport;
$this->network->addStatistics($v["up"], $v["down"]); $this->lastBandwidthReport = $now;
} $this->network->addStatistics($bytesSentDiff / $diff, $bytesReceivedDiff / $diff);
} }
public function putPacket(int $sessionId, string $payload, bool $immediate = true) : void{ public function putPacket(int $sessionId, string $payload, bool $immediate = true) : void{