mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-09 11:31:49 +00:00
Fixed unauthenticated sessions taking up player slots
This commit is contained in:
parent
5d2b0acfc8
commit
59be901efe
@ -80,6 +80,10 @@ class Network{
|
|||||||
return $this->sessionManager->getSessionCount();
|
return $this->sessionManager->getSessionCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getValidConnectionCount() : int{
|
||||||
|
return $this->sessionManager->getValidSessionCount();
|
||||||
|
}
|
||||||
|
|
||||||
public function tick() : void{
|
public function tick() : void{
|
||||||
foreach($this->interfaces as $interface){
|
foreach($this->interfaces as $interface){
|
||||||
$interface->tick();
|
$interface->tick();
|
||||||
|
@ -32,12 +32,25 @@ class NetworkSessionManager{
|
|||||||
/** @var NetworkSession[] */
|
/** @var NetworkSession[] */
|
||||||
private array $sessions = [];
|
private array $sessions = [];
|
||||||
|
|
||||||
|
/** @var NetworkSession[] */
|
||||||
|
private array $pendingLoginSessions = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a network session to the manager. This should only be called on session creation.
|
* Adds a network session to the manager. This should only be called on session creation.
|
||||||
*/
|
*/
|
||||||
public function add(NetworkSession $session) : void{
|
public function add(NetworkSession $session) : void{
|
||||||
$idx = spl_object_id($session);
|
$idx = spl_object_id($session);
|
||||||
$this->sessions[$idx] = $session;
|
$this->sessions[$idx] = $session;
|
||||||
|
$this->pendingLoginSessions[$idx] = $session;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks the session as having sent a login request. After this point, they are counted towards the total player
|
||||||
|
* count.
|
||||||
|
*/
|
||||||
|
public function markLoginReceived(NetworkSession $session) : void{
|
||||||
|
$idx = spl_object_id($session);
|
||||||
|
unset($this->pendingLoginSessions[$idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,15 +60,24 @@ class NetworkSessionManager{
|
|||||||
public function remove(NetworkSession $session) : void{
|
public function remove(NetworkSession $session) : void{
|
||||||
$idx = spl_object_id($session);
|
$idx = spl_object_id($session);
|
||||||
unset($this->sessions[$idx]);
|
unset($this->sessions[$idx]);
|
||||||
|
unset($this->pendingLoginSessions[$idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of known connected sessions.
|
* Returns the number of known connected sessions, including sessions which have not yet sent a login request.
|
||||||
*/
|
*/
|
||||||
public function getSessionCount() : int{
|
public function getSessionCount() : int{
|
||||||
return count($this->sessions);
|
return count($this->sessions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of connected sessions which have either sent a login request, or have already completed the
|
||||||
|
* login sequence.
|
||||||
|
*/
|
||||||
|
public function getValidSessionCount() : int{
|
||||||
|
return count($this->sessions) - count($this->pendingLoginSessions);
|
||||||
|
}
|
||||||
|
|
||||||
/** @return NetworkSession[] */
|
/** @return NetworkSession[] */
|
||||||
public function getSessions() : array{ return $this->sessions; }
|
public function getSessions() : array{ return $this->sessions; }
|
||||||
|
|
||||||
|
@ -229,6 +229,7 @@ class NetworkSession{
|
|||||||
$this->info = $info;
|
$this->info = $info;
|
||||||
$this->logger->info("Player: " . TextFormat::AQUA . $info->getUsername() . TextFormat::RESET);
|
$this->logger->info("Player: " . TextFormat::AQUA . $info->getUsername() . TextFormat::RESET);
|
||||||
$this->logger->setPrefix($this->getLogPrefix());
|
$this->logger->setPrefix($this->getLogPrefix());
|
||||||
|
$this->manager->markLoginReceived($this);
|
||||||
},
|
},
|
||||||
function(bool $isAuthenticated, bool $authRequired, ?string $error, ?string $clientPubKey) : void{
|
function(bool $isAuthenticated, bool $authRequired, ?string $error, ?string $clientPubKey) : void{
|
||||||
$this->setAuthenticationStatus($isAuthenticated, $authRequired, $error, $clientPubKey);
|
$this->setAuthenticationStatus($isAuthenticated, $authRequired, $error, $clientPubKey);
|
||||||
|
@ -123,7 +123,7 @@ class LoginPacketHandler extends PacketHandler{
|
|||||||
$this->session->getPort(),
|
$this->session->getPort(),
|
||||||
$this->server->requiresAuthentication()
|
$this->server->requiresAuthentication()
|
||||||
);
|
);
|
||||||
if($this->server->getNetwork()->getConnectionCount() > $this->server->getMaxPlayers()){
|
if($this->server->getNetwork()->getValidConnectionCount() > $this->server->getMaxPlayers()){
|
||||||
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_SERVER_FULL, KnownTranslationKeys::DISCONNECTIONSCREEN_SERVERFULL);
|
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_SERVER_FULL, KnownTranslationKeys::DISCONNECTIONSCREEN_SERVERFULL);
|
||||||
}
|
}
|
||||||
if(!$this->server->isWhitelisted($playerInfo->getUsername())){
|
if(!$this->server->isWhitelisted($playerInfo->getUsername())){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user