From e7e19abe85a98d1c4b66a92e3b0ac574bde888ca Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 15 Mar 2023 17:17:56 +0000 Subject: [PATCH] IPv4 and IPv6 RakLibInterface instances now both use the same broadcaster and context fixes #5625 --- src/Server.php | 14 ++++++++++---- src/network/mcpe/raklib/RakLibInterface.php | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Server.php b/src/Server.php index e5f312f4e..43460e944 100644 --- a/src/Server.php +++ b/src/Server.php @@ -54,13 +54,16 @@ use pocketmine\network\mcpe\compression\CompressBatchPromise; use pocketmine\network\mcpe\compression\CompressBatchTask; use pocketmine\network\mcpe\compression\Compressor; use pocketmine\network\mcpe\compression\ZlibCompressor; +use pocketmine\network\mcpe\convert\GlobalItemTypeDictionary; use pocketmine\network\mcpe\encryption\EncryptionContext; use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\PacketBroadcaster; use pocketmine\network\mcpe\protocol\ClientboundPacket; use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\mcpe\protocol\serializer\PacketBatch; +use pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext; use pocketmine\network\mcpe\raklib\RakLibInterface; +use pocketmine\network\mcpe\StandardPacketBroadcaster; use pocketmine\network\Network; use pocketmine\network\NetworkInterfaceStartException; use pocketmine\network\query\DedicatedQueryNetworkInterface; @@ -1169,10 +1172,10 @@ class Server{ return !$anyWorldFailedToLoad; } - private function startupPrepareConnectableNetworkInterfaces(string $ip, int $port, bool $ipV6, bool $useQuery) : bool{ + private function startupPrepareConnectableNetworkInterfaces(string $ip, int $port, bool $ipV6, bool $useQuery, PacketBroadcaster $packetBroadcaster, PacketSerializerContext $packetSerializerContext) : bool{ $prettyIp = $ipV6 ? "[$ip]" : $ip; try{ - $rakLibRegistered = $this->network->registerInterface(new RakLibInterface($this, $ip, $port, $ipV6)); + $rakLibRegistered = $this->network->registerInterface(new RakLibInterface($this, $ip, $port, $ipV6, $packetBroadcaster, $packetSerializerContext)); }catch(NetworkInterfaceStartException $e){ $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_networkStartFailed( $ip, @@ -1198,11 +1201,14 @@ class Server{ private function startupPrepareNetworkInterfaces() : bool{ $useQuery = $this->configGroup->getConfigBool("enable-query", true); + $packetSerializerContext = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary()); + $broadcaster = new StandardPacketBroadcaster($this, $packetSerializerContext); + if( - !$this->startupPrepareConnectableNetworkInterfaces($this->getIp(), $this->getPort(), false, $useQuery) || + !$this->startupPrepareConnectableNetworkInterfaces($this->getIp(), $this->getPort(), false, $useQuery, $broadcaster, $packetSerializerContext) || ( $this->configGroup->getConfigBool("enable-ipv6", true) && - !$this->startupPrepareConnectableNetworkInterfaces($this->getIpV6(), $this->getPortV6(), true, $useQuery) + !$this->startupPrepareConnectableNetworkInterfaces($this->getIpV6(), $this->getPortV6(), true, $useQuery, $broadcaster, $packetSerializerContext) ) ){ return false; diff --git a/src/network/mcpe/raklib/RakLibInterface.php b/src/network/mcpe/raklib/RakLibInterface.php index 993566f85..1f7ae9767 100644 --- a/src/network/mcpe/raklib/RakLibInterface.php +++ b/src/network/mcpe/raklib/RakLibInterface.php @@ -83,8 +83,11 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{ private PacketBroadcaster $broadcaster; private PacketSerializerContext $packetSerializerContext; - public function __construct(Server $server, string $ip, int $port, bool $ipV6){ + public function __construct(Server $server, string $ip, int $port, bool $ipV6, PacketBroadcaster $packetBroadcaster, PacketSerializerContext $packetSerializerContext){ $this->server = $server; + $this->broadcaster = $packetBroadcaster; + $this->packetSerializerContext = $packetSerializerContext; + $this->rakServerId = mt_rand(0, PHP_INT_MAX); $this->sleeper = new SleeperNotifier(); @@ -108,9 +111,6 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{ $this->interface = new UserToRakLibThreadMessageSender( new PthreadsChannelWriter($mainToThreadBuffer) ); - - $this->packetSerializerContext = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary()); - $this->broadcaster = new StandardPacketBroadcaster($this->server, $this->packetSerializerContext); } public function start() : void{