From b477cc1c3439faa8f50a46a0c5f3dd9082007bec Mon Sep 17 00:00:00 2001 From: brain Date: Tue, 28 Feb 2006 12:07:03 +0000 Subject: Made it safe to quits and nickchanges git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3379 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/cull_list.cpp | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/cull_list.cpp b/src/cull_list.cpp index f1dd5b4d9..b06b80f7f 100644 --- a/src/cull_list.cpp +++ b/src/cull_list.cpp @@ -51,6 +51,17 @@ using namespace std; extern InspIRCd* ServerInstance; +bool CullList::IsValid(userrec* user) +{ + for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++) + { + userrec* u2 = (userrec*)*u; + if (user == u2) + return true; + } + return false; +} + CullItem::CullItem(userrec* u, std::string r) { this->user = u; @@ -79,6 +90,7 @@ void CullList::AddItem(userrec* user, std::string reason) { CullItem item(user,reason); list.push_back(item); + names.push_back(user->nick); exempt[user] = 1; } } @@ -90,17 +102,27 @@ int CullList::Apply() { std::vector::iterator a = list.begin(); userrec* u = a->GetUser(); - kill_link(u,a->GetReason().c_str()); - list.erase(list.begin()); - /* So that huge numbers of quits dont block, - * we yield back to our mainloop every 15 - * iterations. - * The DoOneIteration call basically acts - * like a software threading mechanism. + /* Because ServerInstance->DoOneIteration can + * take the user away from us in the middle of + * our operation, we should check to see if this + * pointer is still valid by iterating the hash. + * It's expensive, yes, but the DoOneIteration + * call stops it being horrendously bad. */ - if ((n++ % 15) == 0) + if (IsValid(u)) { - ServerInstance->DoOneIteration(false); + kill_link(u,a->GetReason().c_str()); + list.erase(list.begin()); + /* So that huge numbers of quits dont block, + * we yield back to our mainloop every 15 + * iterations. + * The DoOneIteration call basically acts + * like a software threading mechanism. + */ + if (((n++) % 15) == 0) + { + ServerInstance->DoOneIteration(false); + } } } return n; -- cgit v1.2.3