From 3626aeb9ce4798c73cf3a5621388406062c450f7 Mon Sep 17 00:00:00 2001 From: danieldg Date: Wed, 16 Sep 2009 13:45:46 +0000 Subject: Fix iteration of ServerInstance->Users->local_users now that QuitUser can modify the vector git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11732 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/inspircd.cpp | 10 ++++++---- src/modules/m_close.cpp | 10 ++++++---- src/xline.cpp | 5 +++-- 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/inspircd.cpp b/src/inspircd.cpp index ce3bbc06b..1b23bff02 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -105,10 +105,12 @@ void InspIRCd::Cleanup() } /* Close all client sockets, or the new process inherits them */ - for (std::vector::const_iterator i = this->Users->local_users.begin(); i != this->Users->local_users.end(); i++) + std::vector::reverse_iterator i = Users->local_users.rbegin(); + while (i != this->Users->local_users.rend()) { - this->Users->QuitUser((*i), "Server shutdown"); - (*i)->CloseSocket(); + User* u = *i++; + Users->QuitUser(u, "Server shutdown"); + u->CloseSocket(); } /* We do this more than once, so that any service providers get a @@ -117,7 +119,7 @@ void InspIRCd::Cleanup() * * XXX there may be a better way to do this with 1.2 */ - for (int tries = 0; tries < 3; tries++) + for (int tries = 0; tries < 4; tries++) { std::vector module_names = Modules->GetAllModuleNames(0); for (std::vector::iterator k = module_names.begin(); k != module_names.end(); ++k) diff --git a/src/modules/m_close.cpp b/src/modules/m_close.cpp index e81c29d20..009d50d46 100644 --- a/src/modules/m_close.cpp +++ b/src/modules/m_close.cpp @@ -37,12 +37,14 @@ class CommandClose : public Command { std::map closed; - for (std::vector::iterator u = ServerInstance->Users->local_users.begin(); u != ServerInstance->Users->local_users.end(); u++) + std::vector::reverse_iterator u = ServerInstance->Users->local_users.rbegin(); + while (u != ServerInstance->Users->local_users.rend()) { - if ((*u)->registered != REG_ALL) + User* user = *u++; + if (user->registered != REG_ALL) { - ServerInstance->Users->QuitUser(*u, "Closing all unknown connections per request"); - std::string key = ConvToStr((*u)->GetIPString())+"."+ConvToStr((*u)->GetServerPort()); + ServerInstance->Users->QuitUser(user, "Closing all unknown connections per request"); + std::string key = ConvToStr(user->GetIPString())+"."+ConvToStr(user->GetServerPort()); closed[key]++; } } diff --git a/src/xline.cpp b/src/xline.cpp index 33219b612..b15a7ce2b 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -338,9 +338,10 @@ void XLineManager::ExpireLine(ContainerIter container, LookupIter item) // applies lines, removing clients and changing nicks etc as applicable void XLineManager::ApplyLines() { - for (std::vector::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++) + std::vector::reverse_iterator u2 = ServerInstance->Users->local_users.rbegin(); + while (u2 != ServerInstance->Users->local_users.rend()) { - User* u = (User*)(*u2); + User* u = *u2++; // Don't ban people who are exempt. if (u->exempt) -- cgit v1.2.3