Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaileke authored Jul 29, 2024
1 parent 7425ec5 commit 80e89f0
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/protocol/OpenConnectionReply1.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ class OpenConnectionReply1 extends OfflineMessage{
public static $ID = MessageIdentifiers::ID_OPEN_CONNECTION_REPLY_1;

public int $serverID;
public bool $serverSecurity = false;
public int $cookie = 0;
public bool $serverSecurity;
public int $cookie;
public int $mtuSize;

public static function create(int $serverId, bool $serverSecurity, int $mtuSize) : self{
public static function create(int $serverId, bool $serverSecurity, int $cookie, int $mtuSize) : self{
$result = new self;
$result->serverID = $serverId;
$result->serverSecurity = $serverSecurity;
$result->cookie = $cookie;
$result->mtuSize = $mtuSize;
return $result;
}
Expand All @@ -37,7 +38,7 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putLong($this->serverID);
$out->putByte($this->serverSecurity ? 1 : 0);
if ($this->serverSecurity) {
$out->putInt($this->createCookie());
$out->putInt($this->cookie);
}
$out->putShort($this->mtuSize);
}
Expand All @@ -51,11 +52,4 @@ protected function decodePayload(PacketSerializer $in) : void{
}
$this->mtuSize = $in->getShort();
}

private function createCookie() : int {
$cookieSalt = mt_rand(0, 0xFFFFFFFF);
$cookie = Binary::writeLInt($cookieSalt) . Binary::writeLShort(Server::getInstance()->getPort()) . Server::getInstance()->getIp();
return crc32($cookie);
}
}

0 comments on commit 80e89f0

Please sign in to comment.