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 1 commit
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
4 changes: 2 additions & 2 deletions src/protocol/OpenConnectionReply1.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class OpenConnectionReply1 extends OfflineMessage{

public int $serverID;
public bool $serverSecurity;
ismaileke marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/OpenConnectionRequest2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions src/server/UnconnectedMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions src/utils/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public static function get(InternetAddress $address) : int{
return 0;
}

public static function hasServerSecurity () : bool {
return self::$serverHasSecurity;
ismaileke marked this conversation as resolved.
Show resolved Hide resolved
}

public static function check(InternetAddress $address, int $cookie) : bool{
$addressStr = $address->toString();

Expand Down
Loading