diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-08-16 23:48:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-16 23:48:29 +0200 |
commit | 1d8d01074fdb52946f81110bebf1d001185b394b (patch) | |
tree | 64cbf6f73bc0f18cbf8333247cd71ab1856ed4c2 /src/clientiface.cpp | |
parent | 85511a642f851100d0d856f4ecbe7fea7a7bb049 (diff) | |
download | minetest-1d8d01074fdb52946f81110bebf1d001185b394b.tar.gz minetest-1d8d01074fdb52946f81110bebf1d001185b394b.tar.bz2 minetest-1d8d01074fdb52946f81110bebf1d001185b394b.zip |
ClientInterface: add a function to verify (correctly) if user limit was reached (#6258)
* 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)
Diffstat (limited to 'src/clientiface.cpp')
-rw-r--r-- | src/clientiface.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/clientiface.cpp b/src/clientiface.cpp index cdb64e192..f07f02012 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -622,15 +622,24 @@ std::vector<u16> ClientInterface::getClientIDs(ClientState min_state) std::vector<u16> reply; MutexAutoLock clientslock(m_clients_mutex); - for (RemoteClientMap::iterator i = m_clients.begin(); - i != m_clients.end(); ++i) { - if (i->second->getState() >= min_state) - reply.push_back(i->second->peer_id); + for (const auto &m_client : m_clients) { + if (m_client.second->getState() >= min_state) + reply.push_back(m_client.second->peer_id); } 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; |