Updated to latest bleeding-edge RakLib

This commit is contained in:
Dylan K. Taylor 2020-03-29 23:53:00 +01:00
parent abd1ed7352
commit 927872ce08
4 changed files with 25 additions and 18 deletions

8
composer.lock generated
View File

@ -529,12 +529,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/pmmp/RakLib.git", "url": "https://github.com/pmmp/RakLib.git",
"reference": "b049d56a3ef5c87e545882737f8e1a8e965fec1d" "reference": "45378244744328ceda76f95f2636a4f2d6e365c7"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/pmmp/RakLib/zipball/b049d56a3ef5c87e545882737f8e1a8e965fec1d", "url": "https://api.github.com/repos/pmmp/RakLib/zipball/45378244744328ceda76f95f2636a4f2d6e365c7",
"reference": "b049d56a3ef5c87e545882737f8e1a8e965fec1d", "reference": "45378244744328ceda76f95f2636a4f2d6e365c7",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -563,7 +563,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-03-29T17:01:59+00:00" "time": "2020-03-29T22:42:27+00:00"
}, },
{ {
"name": "pocketmine/snooze", "name": "pocketmine/snooze",

View File

@ -37,8 +37,9 @@ use raklib\protocol\PacketReliability;
use raklib\RakLib; use raklib\RakLib;
use raklib\server\InterThreadChannelReader; use raklib\server\InterThreadChannelReader;
use raklib\server\InterThreadChannelWriter; use raklib\server\InterThreadChannelWriter;
use raklib\server\ServerHandler; use raklib\server\RakLibToUserThreadMessageReceiver;
use raklib\server\ServerInstance; use raklib\server\ServerEventListener;
use raklib\server\UserToRakLibThreadMessageSender;
use raklib\utils\InternetAddress; use raklib\utils\InternetAddress;
use function addcslashes; use function addcslashes;
use function bin2hex; use function bin2hex;
@ -50,7 +51,7 @@ use function substr;
use function unserialize; use function unserialize;
use const PTHREADS_INHERIT_CONSTANTS; use const PTHREADS_INHERIT_CONSTANTS;
class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
/** /**
* Sometimes this gets changed when the MCPE-layer protocol gets broken to the point where old and new can't * Sometimes this gets changed when the MCPE-layer protocol gets broken to the point where old and new can't
* communicate. It's important that we check this to avoid catastrophes. * communicate. It's important that we check this to avoid catastrophes.
@ -74,7 +75,9 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
/** @var NetworkSession[] */ /** @var NetworkSession[] */
private $sessions = []; private $sessions = [];
/** @var ServerHandler */ /** @var RakLibToUserThreadMessageReceiver */
private $eventReceiver;
/** @var UserToRakLibThreadMessageSender */
private $interface; private $interface;
/** @var SleeperNotifier */ /** @var SleeperNotifier */
@ -99,16 +102,18 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
self::MCPE_RAKNET_PROTOCOL_VERSION, self::MCPE_RAKNET_PROTOCOL_VERSION,
$this->sleeper $this->sleeper
); );
$this->interface = new ServerHandler( $this->eventReceiver = new RakLibToUserThreadMessageReceiver(
$this, $this,
new InterThreadChannelReader($threadToMainBuffer), new InterThreadChannelReader($threadToMainBuffer)
);
$this->interface = new UserToRakLibThreadMessageSender(
new InterThreadChannelWriter($mainToThreadBuffer) new InterThreadChannelWriter($mainToThreadBuffer)
); );
} }
public function start() : void{ public function start() : void{
$this->server->getTickSleeper()->addNotifier($this->sleeper, function() : void{ $this->server->getTickSleeper()->addNotifier($this->sleeper, function() : void{
while($this->interface->handlePacket()); while($this->eventReceiver->handle());
}); });
$this->server->getLogger()->debug("Waiting for RakLib to start..."); $this->server->getLogger()->debug("Waiting for RakLib to start...");
$this->rakLib->startAndWait(PTHREADS_INHERIT_CONSTANTS); //HACK: MainLogger needs constants for exception logging $this->rakLib->startAndWait(PTHREADS_INHERIT_CONSTANTS); //HACK: MainLogger needs constants for exception logging
@ -137,10 +142,10 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
} }
} }
public function close(int $sessionId, string $reason = "unknown reason") : void{ public function close(int $sessionId) : void{
if(isset($this->sessions[$sessionId])){ if(isset($this->sessions[$sessionId])){
unset($this->sessions[$sessionId]); unset($this->sessions[$sessionId]);
$this->interface->closeSession($sessionId, $reason); $this->interface->closeSession($sessionId);
} }
} }
@ -210,7 +215,7 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
public function setName(string $name) : void{ public function setName(string $name) : void{
$info = $this->server->getQueryInformation(); $info = $this->server->getQueryInformation();
$this->interface->sendOption("name", implode(";", $this->interface->setOption("name", implode(";",
[ [
"MCPE", "MCPE",
rtrim(addcslashes($name, ";"), '\\'), rtrim(addcslashes($name, ";"), '\\'),
@ -226,7 +231,7 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
} }
public function setPortCheck(bool $name) : void{ public function setPortCheck(bool $name) : void{
$this->interface->sendOption("portChecking", $name); $this->interface->setOption("portChecking", $name);
} }
public function handleOption(string $option, string $value) : void{ public function handleOption(string $option, string $value) : void{

View File

@ -49,7 +49,7 @@ class RakLibPacketSender implements PacketSender{
public function close(string $reason = "unknown reason") : void{ public function close(string $reason = "unknown reason") : void{
if(!$this->closed){ if(!$this->closed){
$this->closed = true; $this->closed = true;
$this->handler->close($this->sessionId, $reason); $this->handler->close($this->sessionId);
} }
} }
} }

View File

@ -29,7 +29,9 @@ use raklib\generic\Socket;
use raklib\RakLib; use raklib\RakLib;
use raklib\server\InterThreadChannelReader; use raklib\server\InterThreadChannelReader;
use raklib\server\InterThreadChannelWriter; use raklib\server\InterThreadChannelWriter;
use raklib\server\RakLibToUserThreadMessageSender;
use raklib\server\SessionManager; use raklib\server\SessionManager;
use raklib\server\UserToRakLibThreadMessageReceiver;
use raklib\utils\ExceptionTraceCleaner; use raklib\utils\ExceptionTraceCleaner;
use raklib\utils\InternetAddress; use raklib\utils\InternetAddress;
use function error_get_last; use function error_get_last;
@ -159,8 +161,8 @@ class RakLibServer extends Thread{
$socket, $socket,
$this->maxMtuSize, $this->maxMtuSize,
$this->protocolVersion, $this->protocolVersion,
new InterThreadChannelReader($this->mainToThreadBuffer), new UserToRakLibThreadMessageReceiver(new InterThreadChannelReader($this->mainToThreadBuffer)),
new InterThreadChannelWriter($this->threadToMainBuffer, $this->mainThreadNotifier), new RakLibToUserThreadMessageSender(new InterThreadChannelWriter($this->threadToMainBuffer, $this->mainThreadNotifier)),
new ExceptionTraceCleaner($this->mainPath) new ExceptionTraceCleaner($this->mainPath)
); );
$this->synchronized(function() : void{ $this->synchronized(function() : void{