diff --git a/src/protocol/OpenConnectionReply1.php b/src/protocol/OpenConnectionReply1.php index 1024c16..4adf23f 100644 --- a/src/protocol/OpenConnectionReply1.php +++ b/src/protocol/OpenConnectionReply1.php @@ -23,10 +23,10 @@ class OpenConnectionReply1 extends OfflineMessage{ public int $serverID; public bool $serverSecurity; - public int|null $cookie; + public ?int $cookie; public int $mtuSize; - public static function create(int $serverId, bool $serverSecurity, int $cookie = null, int $mtuSize) : self{ + public static function create(int $serverId, bool $serverSecurity, ?int $cookie = null, int $mtuSize) : self{ $result = new self; $result->serverID = $serverId; $result->serverSecurity = $serverSecurity; diff --git a/src/protocol/OpenConnectionRequest2.php b/src/protocol/OpenConnectionRequest2.php index 8c783f5..bd7f7d8 100644 --- a/src/protocol/OpenConnectionRequest2.php +++ b/src/protocol/OpenConnectionRequest2.php @@ -30,7 +30,7 @@ class OpenConnectionRequest2 extends OfflineMessage{ protected function encodePayload(PacketSerializer $out) : void{ $this->writeMagic($out); - if (Cookie::$serverHasSecurity) { + if (Cookie::hasServerSecurity()) { $out->putInt($this->cookie); $out->putBool($this->clientSupportsSecurity); } @@ -41,7 +41,7 @@ protected function encodePayload(PacketSerializer $out) : void{ protected function decodePayload(PacketSerializer $in) : void{ $this->readMagic($in); - if (Cookie::$serverHasSecurity) { + if (Cookie::hasServerSecurity()) { $this->cookie = $in->getInt(); $this->clientSupportsSecurity = $in->getBool(); } diff --git a/src/server/UnconnectedMessageHandler.php b/src/server/UnconnectedMessageHandler.php index d9df66d..5cee0f0 100644 --- a/src/server/UnconnectedMessageHandler.php +++ b/src/server/UnconnectedMessageHandler.php @@ -83,12 +83,12 @@ private function handle(OfflineMessage $packet, InternetAddress $address) : bool $this->server->getLogger()->notice("Refused connection from $address due to incompatible RakNet protocol version (version $packet->protocol)"); }else{ $cookie = null; - if (Cookie::$serverHasSecurity) { + if (Cookie::hasServerSecurity()) { Cookie::add($address); $cookie = Cookie::get($address); } //IP header size (20 bytes) + UDP header size (8 bytes) - $this->server->sendPacket(OpenConnectionReply1::create($this->server->getID(), Cookie::$serverHasSecurity, $cookie, $packet->mtuSize + 28), $address); + $this->server->sendPacket(OpenConnectionReply1::create($this->server->getID(), Cookie::hasServerSecurity(), $cookie, $packet->mtuSize + 28), $address); } }elseif($packet instanceof OpenConnectionRequest2){ // The client may not send such data even though serverSecurity is enabled, and if we try to decode this, we may encounter an error @@ -104,7 +104,7 @@ private function handle(OfflineMessage $packet, InternetAddress $address) : bool $this->server->getLogger()->debug("Not creating session for $address due to session already opened"); return true; } - if (Cookie::$serverHasSecurity) { + if (Cookie::hasServerSecurity()) { if (!Cookie::check($address, $packet->cookie)) { // Disconnect if OpenConnectionReply1 and the cookie in the OpenCnnectionRequest2 packet do not match $this->server->getLogger()->debug("Not creating session for $address due to session mismatched cookies"); diff --git a/src/utils/Cookie.php b/src/utils/Cookie.php index 5c5ca97..56daac0 100644 --- a/src/utils/Cookie.php +++ b/src/utils/Cookie.php @@ -37,6 +37,10 @@ public static function get(InternetAddress $address) : int{ return 0; } + public static function hasServerSecurity () : bool { + return self::$serverHasSecurity; + } + public static function check(InternetAddress $address, int $cookie) : bool{ $addressStr = $address->toString();