Skip to content

Commit

Permalink
delete the cookie when player log out
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaileke committed Sep 20, 2024
1 parent 0e8b732 commit bd80d49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ private function tick() : void{
foreach($this->sessions as $session){
$session->update($time);
if($session->isFullyDisconnected()){
if ($this->getCookie() instanceof CookieCache) {
$this->getCookie()->remove($session->getAddress());
}
$this->removeSessionInternal($session);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/utils/CookieCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public function add(InternetAddress $address) : int{
return $cookie;
}

public function remove(InternetAddress $address) : void{
$addressStr = $address->toString();
if (isset($this->cookies[$addressStr])) {
unset($this->cookies[$addressStr]);
}
}

private function generate(InternetAddress $address) : int{
return random_int(0, Limits::UINT32_MAX);
}
Expand Down

0 comments on commit bd80d49

Please sign in to comment.