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

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{