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": {
"type": "git",
"url": "https://github.com/pmmp/RakLib.git",
"reference": "31e2b2259404399cac7f50ae4a9bbdfdd8c1035e"
"reference": "6fbccdb6a7cf47ebcb411803aa023cf688aae8c7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/RakLib/zipball/31e2b2259404399cac7f50ae4a9bbdfdd8c1035e",
"reference": "31e2b2259404399cac7f50ae4a9bbdfdd8c1035e",
"url": "https://api.github.com/repos/pmmp/RakLib/zipball/6fbccdb6a7cf47ebcb411803aa023cf688aae8c7",
"reference": "6fbccdb6a7cf47ebcb411803aa023cf688aae8c7",
"shasum": ""
},
"require": {
@ -654,7 +654,7 @@
"GPL-3.0"
],
"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",

View File

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