mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Max players check now works properly
This now includes all connected sessions, whether they are considered online or not.
This commit is contained in:
parent
41676cb4d4
commit
38cf8d157d
@ -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)){
|
||||
|
@ -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) .
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user