]> git.lizzy.rs Git - minetest.git/commitdiff
ClientInterface: add a function to verify (correctly) if user limit was reached ...
authorLoïc Blot <nerzhul@users.noreply.github.com>
Wed, 16 Aug 2017 21:48:29 +0000 (23:48 +0200)
committerSmallJoker <mk939@ymail.com>
Sun, 3 Jun 2018 15:31:59 +0000 (17:31 +0200)
* ClientInterface: add a function to verify (correctly) if user limit was reached

CS_HelloSent is a better indicator of active slots than CS_Created, which are session objects created after init packet reception

Switch existing checks to ClientInterface::isUserLimitReached()

Use range-based for loop for getClientIds() used function too

This will fix #6254 (not the memory overhead if init is flooded)

src/clientiface.cpp
src/clientiface.h
src/network/serverpackethandler.cpp

index 68bd4afe7986b07ab4bcb455684044064b626420..4753972799b2732dbdfe3e4b04201d02727c92f5 100644 (file)
@@ -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;
index d2299c8796910d3c020ae34d6d388c8e40aa7797..6e7429309eb4e2815e86ec2b04ccee32acb196e2 100644 (file)
@@ -449,6 +449,9 @@ class ClientInterface {
        /* 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 @@ class ClientInterface {
        }
 
        static std::string state2Name(ClientState state);
-
 protected:
        //TODO find way to avoid this functions
        void lock() { m_clients_mutex.lock(); }
index 5b026bbdb03dffb3d27fcdaf60866efe8b07fe94..22456f4871498803401d8ad0839f0423440358fe 100644 (file)
@@ -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") &&