From db7cc57f444a82df65f47b4f7058560e645e35cf Mon Sep 17 00:00:00 2001 From: danieldg Date: Wed, 2 Sep 2009 00:50:12 +0000 Subject: [PATCH] Move user quit logic out of cull list This changes the cull list from a list of User* that ran special cleanup to a list of classbase* that simply deletes the objects. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11636 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/cull_list.h | 52 +++---------- src/cull_list.cpp | 93 +---------------------- src/inspircd.cpp | 4 +- src/modules/m_spanningtree/treeserver.cpp | 2 +- src/usermanager.cpp | 67 +++++++++++++++- 5 files changed, 79 insertions(+), 139 deletions(-) diff --git a/include/cull_list.h b/include/cull_list.h index 2a0b895f2..8c3827642 100644 --- a/include/cull_list.h +++ b/include/cull_list.h @@ -14,58 +14,24 @@ #ifndef __CULLLIST_H__ #define __CULLLIST_H__ -/** The CullList class is used by the core to create lists of users - * prior to actually quitting (and deleting the objects) all at once. - * to quitting them all at once. This is faster than quitting - * them within the loop, as the loops become tighter with - * little or no comparisons within them. The CullList class - * operates by allowing the programmer to push users onto - * the list, each with a seperate quit reason, and then, once - * the list is complete, call a method to flush the list, - * quitting all the users upon it. A CullList may hold local - * or remote users, but it may only hold each user once. If - * you attempt to add the same user twice, then the second - * attempt will be ignored. - * - * NOTE: Don't use this outside core, use the QuitUser method like everyone else! +/** + * The CullList class is used to delete objects at the end of the main loop to + * avoid problems with references to deleted pointers if an object were deleted + * during execution. */ class CoreExport CullList : public classbase { private: - /** Creator of this CullList - */ - InspIRCd* ServerInstance; - - /** Holds a list of users being quit. - * See the information for CullItem for - * more information. - */ - std::vector list; + std::vector list; public: - /** Constructor. - * @param Instance Creator of this CullList object - */ - CullList(InspIRCd* Instance); - - /** Adds a user to the cull list for later - * removal via QUIT. - * @param user The user to add - * @param reason The quit reason of the user being added - * @param o_reason The quit reason to show only to opers - */ - void AddItem(User* user); + CullList() {} - /* Turn an item into a silent item (don't send out QUIT for this user) + /** Adds an item to the cull list */ - void MakeSilent(User* user); + void AddItem(classbase* item) { list.push_back(item); } - /** Applies the cull list, quitting all the users - * on the list with their quit reasons all at once. - * This is a very fast operation compared to - * iterating the user list and comparing each one, - * especially if there are multiple comparisons - * to be done, or recursion. + /** Applies the cull list (deletes the contents) */ void Apply(); }; diff --git a/src/cull_list.cpp b/src/cull_list.cpp index 07649ed81..79c077ead 100644 --- a/src/cull_list.cpp +++ b/src/cull_list.cpp @@ -16,99 +16,10 @@ #include "inspircd.h" #include "cull_list.h" -CullList::CullList(InspIRCd* Instance) : ServerInstance(Instance) -{ -} - -void CullList::AddItem(User* user) -{ - list.push_back(user); -} - -void CullList::MakeSilent(User* user) -{ - user->quietquit = true; - return; -} - void CullList::Apply() { - for(std::vector::iterator a = list.begin(); a != list.end(); a++) - { - User *u = *a; - // user has been moved onto their UID; that's why this isn't find(u->nick) - user_hash::iterator iter = ServerInstance->Users->clientlist->find(u->uuid); - - if (u->registered != REG_ALL) - if (ServerInstance->Users->unregistered_count) - ServerInstance->Users->unregistered_count--; - - if (IS_LOCAL(u)) - { - if (!u->sendq.empty()) - u->FlushWriteBuf(); - - if (u->GetIOHook()) - { - try - { - u->GetIOHook()->OnRawSocketClose(u->GetFd()); - } - catch (CoreException& modexcept) - { - ServerInstance->Logs->Log("CULLLIST",DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); - } - } - - ServerInstance->SE->DelFd(u); - u->CloseSocket(); - } - - /* - * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything - * if they were an oper with +sn +qQ. - */ - if (u->registered == REG_ALL) - { - if (IS_LOCAL(u)) - { - if (!u->quietquit) - { - ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]", u->nick.c_str(), u->ident.c_str(), u->host.c_str(), u->operquitmsg.c_str()); - } - } - else - { - if ((!ServerInstance->SilentULine(u->server)) && (!u->quietquit)) - { - ServerInstance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]", u->server, u->nick.c_str(), u->ident.c_str(), u->host.c_str(), u->operquitmsg.c_str()); - } - } - u->AddToWhoWas(); - } - - if (iter != ServerInstance->Users->clientlist->end()) - { - ServerInstance->Users->clientlist->erase(iter); - } - else - { - ServerInstance->Logs->Log("CULLLIST", DEBUG, "iter == clientlist->end, can't remove them from hash... problematic.."); - } - - if (IS_LOCAL(u)) - { - std::vector::iterator x = find(ServerInstance->Users->local_users.begin(),ServerInstance->Users->local_users.end(),u); - if (x != ServerInstance->Users->local_users.end()) - ServerInstance->Users->local_users.erase(x); - else - { - ServerInstance->Logs->Log("CULLLIST", DEBUG, "Failed to remove user from vector.."); - } - } - - delete u; - } + for(std::vector::iterator i = list.begin(); i != list.end(); i++) + delete *i; list.clear(); } diff --git a/src/inspircd.cpp b/src/inspircd.cpp index cc69374ec..94dd41da0 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -317,9 +317,7 @@ void InspIRCd::WritePID(const std::string &filename) } } -InspIRCd::InspIRCd(int argc, char** argv) - : GlobalCulls(this), - +InspIRCd::InspIRCd(int argc, char** argv) : /* Functor initialisation. Note that the ordering here is very important. * * THIS MUST MATCH ORDER OF DECLARATION OF THE HandleWhateverFunc classes diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index 97aab7266..6c8c6a33c 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -182,7 +182,7 @@ int TreeServer::QuitUsers(const std::string &reason) ServerInstance->Users->QuitUser(a, reason_s); if (this->Utils->quiet_bursts) - ServerInstance->GlobalCulls.MakeSilent(a); + a->quietquit = true; } } return time_to_die.size(); diff --git a/src/usermanager.cpp b/src/usermanager.cpp index a31ac086e..31ffad007 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -204,8 +204,73 @@ void UserManager::QuitUser(User *user, const std::string &quitreason, const char FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(user)); - // Move the user onto their UID, to allow nick to be reused immediately user->UpdateNickHash(user->uuid.c_str()); + + user_hash::iterator iter = this->clientlist->find(user->uuid); + + if (user->registered != REG_ALL) + if (ServerInstance->Users->unregistered_count) + ServerInstance->Users->unregistered_count--; + + if (IS_LOCAL(user)) + { + if (!user->sendq.empty()) + user->FlushWriteBuf(); + + if (user->GetIOHook()) + { + try + { + user->GetIOHook()->OnRawSocketClose(user->GetFd()); + } + catch (CoreException& modexcept) + { + ServerInstance->Logs->Log("USERS",DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); + } + } + + ServerInstance->SE->DelFd(user); + user->CloseSocket(); + } + + /* + * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything + * if they were an oper with +sn +qQ. + */ + if (user->registered == REG_ALL) + { + if (IS_LOCAL(user)) + { + if (!user->quietquit) + { + ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]", + user->nick.c_str(), user->ident.c_str(), user->host.c_str(), user->operquitmsg.c_str()); + } + } + else + { + if ((!ServerInstance->SilentULine(user->server)) && (!user->quietquit)) + { + ServerInstance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]", + user->server, user->nick.c_str(), user->ident.c_str(), user->host.c_str(), user->operquitmsg.c_str()); + } + } + user->AddToWhoWas(); + } + + if (iter != this->clientlist->end()) + this->clientlist->erase(iter); + else + ServerInstance->Logs->Log("USERS", DEBUG, "iter == clientlist->end, can't remove them from hash... problematic.."); + + if (IS_LOCAL(user)) + { + std::vector::iterator x = find(local_users.begin(),local_users.end(),user); + if (x != local_users.end()) + local_users.erase(x); + else + ServerInstance->Logs->Log("USERS", DEBUG, "Failed to remove user from vector"); + } } -- 2.39.5