Max players check now works properly

This now includes all connected sessions, whether they are considered online or not.
This commit is contained in:
Dylan K. Taylor 2019-01-17 21:40:10 +00:00
parent 41676cb4d4
commit 38cf8d157d
5 changed files with 26 additions and 2 deletions

View File

@ -1757,7 +1757,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->networkSession->getPort(),
$this->server->requiresAuthentication()
);
if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers()){
if($this->server->getNetwork()->getConnectionCount() > $this->server->getMaxPlayers()){
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_SERVER_FULL, "disconnectionScreen.serverFull");
}
if(!$this->server->isWhitelisted($this->username)){

View File

@ -2093,9 +2093,13 @@ class Server{
$u = Utils::getMemoryUsage(true);
$usage = sprintf("%g/%g/%g/%g MB @ %d threads", round(($u[0] / 1024) / 1024, 2), round(($d[0] / 1024) / 1024, 2), round(($u[1] / 1024) / 1024, 2), round(($u[2] / 1024) / 1024, 2), Utils::getThreadCount());
$online = count($this->playerList);
$connecting = $this->network->getConnectionCount() - $online;
echo "\x1b]0;" . $this->getName() . " " .
$this->getPocketMineVersion() .
" | Online " . count($this->players) . "/" . $this->getMaxPlayers() .
" | Online $online/" . $this->getMaxPlayers() .
($connecting > 0 ? " (+$connecting connecting)" : "") .
" | Memory " . $usage .
" | U " . round($this->network->getUpload() / 1024, 2) .
" D " . round($this->network->getDownload() / 1024, 2) .

View File

@ -77,6 +77,14 @@ class Network{
return $this->interfaces;
}
public function getConnectionCount() : int{
$count = 0;
foreach($this->interfaces as $interface){
$count += $interface->getConnectionCount();
}
return $count;
}
public function tick() : void{
foreach($this->interfaces as $interface){
$interface->tick();

View File

@ -38,6 +38,13 @@ interface NetworkInterface{
*/
public function start() : void;
/**
* Returns the number of connections on this interface.
*
* @return int
*/
public function getConnectionCount() : int;
/**
* Sends a packet to the interface, returns an unique identifier for the packet if $needACK is true
*

View File

@ -39,6 +39,7 @@ use raklib\server\ServerHandler;
use raklib\server\ServerInstance;
use raklib\utils\InternetAddress;
use function addcslashes;
use function count;
use function implode;
use function rtrim;
use function spl_object_hash;
@ -99,6 +100,10 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
$this->rakLib->start(PTHREADS_INHERIT_CONSTANTS); //HACK: MainLogger needs constants for exception logging
}
public function getConnectionCount() : int{
return count($this->sessions);
}
public function setNetwork(Network $network) : void{
$this->network = $network;
}