Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie data #229

Open
wants to merge 35 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3e2e59e
Cookie added
ismaileke Jul 28, 2024
963c533
Cookie added 2
ismaileke Jul 28, 2024
c22a7d1
Update OpenConnectionRequest2.php
ismaileke Jul 28, 2024
7425ec5
extra byte
ismaileke Jul 28, 2024
80e89f0
some fixes
ismaileke Jul 29, 2024
c58e264
updated unconnected message handler
ismaileke Jul 29, 2024
967555e
oops
ismaileke Jul 29, 2024
78f5cf5
Update OpenConnectionRequest2.php
ismaileke Jul 29, 2024
3cdf46e
Cookie Class
ismaileke Jul 30, 2024
1c94a8c
againagainagain
ismaileke Jul 30, 2024
440196c
Update Cookie.php
ismaileke Jul 30, 2024
1287f4c
Update Cookie.php
ismaileke Jul 30, 2024
3764e4b
for now
ismaileke Aug 3, 2024
312e11e
fix
ismaileke Aug 3, 2024
9078818
some fixes
ismaileke Aug 3, 2024
9c11bb4
okay
ismaileke Aug 3, 2024
ba4c754
is it right to add that lol
ismaileke Aug 3, 2024
9555243
client supports security
ismaileke Aug 7, 2024
ec8532b
added static function
ismaileke Aug 8, 2024
884bbff
non-static funcs
ismaileke Aug 9, 2024
b6c85e7
fix nullable
ismaileke Aug 9, 2024
15d1b13
use method
ismaileke Aug 9, 2024
75e8526
i forgot
ismaileke Aug 9, 2024
ff2a37e
fix but not finished
ismaileke Aug 9, 2024
8e6c677
uhhh
ismaileke Aug 9, 2024
f8250af
short usage
ismaileke Aug 10, 2024
df75ce4
Update src/protocol/OpenConnectionReply1.php
ismaileke Aug 10, 2024
64cb140
some fixes are not yet complete
ismaileke Aug 13, 2024
b9bb269
random_int
ismaileke Aug 13, 2024
65e2da8
Limits
ismaileke Aug 13, 2024
0e8b732
new name CookieCache
ismaileke Aug 13, 2024
bd80d49
delete the cookie when player log out
ismaileke Sep 20, 2024
cb35ab3
CookieCache::check() fix?
ismaileke Sep 20, 2024
41ac282
snake case :|
ismaileke Sep 20, 2024
7d1586f
pls gimme blue tick
ismaileke Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/protocol/OpenConnectionReply1.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ class OpenConnectionReply1 extends OfflineMessage{
public static $ID = MessageIdentifiers::ID_OPEN_CONNECTION_REPLY_1;

public int $serverID;
public bool $serverSecurity = false;
public bool $serverSecurity;
ismaileke marked this conversation as resolved.
Show resolved Hide resolved
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{
ismaileke marked this conversation as resolved.
Show resolved Hide resolved
$result = new self;
$result->serverID = $serverId;
$result->serverSecurity = $serverSecurity;
$result->cookie = $cookie;
$result->mtuSize = $mtuSize;
return $result;
}
Expand All @@ -35,13 +37,19 @@ protected function encodePayload(PacketSerializer $out) : void{
$this->writeMagic($out);
$out->putLong($this->serverID);
$out->putByte($this->serverSecurity ? 1 : 0);
if ($this->serverSecurity) {
$out->putInt($this->cookie);
}
$out->putShort($this->mtuSize);
}

protected function decodePayload(PacketSerializer $in) : void{
$this->readMagic($in);
$this->serverID = $in->getLong();
$this->serverSecurity = $in->getByte() !== 0;
if ($this->serverSecurity) {
$this->cookie = $in->getInt();
}
ismaileke marked this conversation as resolved.
Show resolved Hide resolved
$this->mtuSize = $in->getShort();
}
}
10 changes: 10 additions & 0 deletions src/protocol/OpenConnectionRequest2.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,29 @@
class OpenConnectionRequest2 extends OfflineMessage{
public static $ID = MessageIdentifiers::ID_OPEN_CONNECTION_REQUEST_2;

public bool $serverSecurity = false;
public int $cookie = 0;
public int $clientID;
public InternetAddress $serverAddress;
public int $mtuSize;

protected function encodePayload(PacketSerializer $out) : void{
$this->writeMagic($out);
if ($this->serverSecurity) {
$out->putInt($this->cookie);
$out->putByte(0); // WHY MOJANG?
ismaileke marked this conversation as resolved.
Show resolved Hide resolved
}
$out->putAddress($this->serverAddress);
$out->putShort($this->mtuSize);
$out->putLong($this->clientID);
}

protected function decodePayload(PacketSerializer $in) : void{
$this->readMagic($in);
if ($this->serverSecurity) {
$this->cookie = $in->getInt();
$in->getByte(); // JUST 5 BYTES AND THERE IS WEIRD EXTRA BYTE
ismaileke marked this conversation as resolved.
Show resolved Hide resolved
}
$this->serverAddress = $in->getAddress();
$this->mtuSize = $in->getShort();
$this->clientID = $in->getLong();
Expand Down
8 changes: 7 additions & 1 deletion src/server/UnconnectedMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace raklib\server;

use pocketmine\utils\BinaryDataException;
use pocketmine\utils\Binary;
use raklib\generic\Session;
use raklib\protocol\IncompatibleProtocolVersion;
use raklib\protocol\MessageIdentifiers;
Expand Down Expand Up @@ -81,8 +82,13 @@
$this->server->sendPacket(IncompatibleProtocolVersion::create($this->protocolAcceptor->getPrimaryVersion(), $this->server->getID()), $address);
$this->server->getLogger()->notice("Refused connection from $address due to incompatible RakNet protocol version (version $packet->protocol)");
}else{
$serverHasSecurity = false; // then relocate it ve make it available
$cookie = 0;
if ($serverHasSecurity) {

Check failure on line 87 in src/server/UnconnectedMessageHandler.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

If condition is always false.
$cookie = crc32(Binary::writeLInt(mt_rand(0, 0xFFFFFFFF)) . Binary::writeLShort($address->getPort()) . $address->getIp());
ismaileke marked this conversation as resolved.
Show resolved Hide resolved
}
//IP header size (20 bytes) + UDP header size (8 bytes)
$this->server->sendPacket(OpenConnectionReply1::create($this->server->getID(), false, $packet->mtuSize + 28), $address);
$this->server->sendPacket(OpenConnectionReply1::create($this->server->getID(), $serverHasSecurity, $cookie, $packet->mtuSize + 28), $address);
}
}elseif($packet instanceof OpenConnectionRequest2){
if($packet->serverAddress->getPort() === $this->server->getPort() or !$this->server->portChecking){
Expand Down
Loading