aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clientiface.cpp10
-rw-r--r--src/clientiface.h4
-rw-r--r--src/network/serverpackethandler.cpp4
3 files changed, 15 insertions, 3 deletions
diff --git a/src/clientiface.cpp b/src/clientiface.cpp
index 68bd4afe7..475397279 100644
--- a/src/clientiface.cpp
+++ b/src/clientiface.cpp
@@ -633,6 +633,16 @@ std::vector<u16> ClientInterface::getClientIDs(ClientState min_state)
return reply;
}
+/**
+ * Verify if user limit was reached.
+ * User limit count all clients from HelloSent state (MT protocol user) to Active state
+ * @return true if user limit was reached
+ */
+bool ClientInterface::isUserLimitReached()
+{
+ return getClientIDs(CS_HelloSent).size() >= g_settings->getU16("max_users");
+}
+
void ClientInterface::step(float dtime)
{
m_print_info_timer += dtime;
diff --git a/src/clientiface.h b/src/clientiface.h
index d2299c879..6e7429309 100644
--- a/src/clientiface.h
+++ b/src/clientiface.h
@@ -449,6 +449,9 @@ public:
/* get list of active client id's */
std::vector<u16> getClientIDs(ClientState min_state=CS_Active);
+ /* verify is server user limit was reached */
+ bool isUserLimitReached();
+
/* get list of client player names */
const std::vector<std::string> &getPlayerNames() const { return m_clients_names; }
@@ -493,7 +496,6 @@ public:
}
static std::string state2Name(ClientState state);
-
protected:
//TODO find way to avoid this functions
void lock() { m_clients_mutex.lock(); }
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index 5b026bbdb..22456f487 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -211,7 +211,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
// Enforce user limit.
// Don't enforce for users that have some admin right
- if (m_clients.getClientIDs(CS_Created).size() >= g_settings->getU16("max_users") &&
+ if (m_clients.isUserLimitReached() &&
!checkPriv(playername, "server") &&
!checkPriv(playername, "ban") &&
!checkPriv(playername, "privs") &&
@@ -520,7 +520,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
// Enforce user limit.
// Don't enforce for users that have some admin right
- if (m_clients.getClientIDs(CS_Created).size() >= g_settings->getU16("max_users") &&
+ if (m_clients.isUserLimitReached() >= g_settings->getU16("max_users") &&
!checkPriv(playername, "server") &&
!checkPriv(playername, "ban") &&
!checkPriv(playername, "privs") &&