]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cull_list.cpp
Fix recursion of QuitUser in SendQ quits
[user/henk/code/inspircd.git] / src / cull_list.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include <typeinfo>
16
17 void CullList::Apply()
18 {
19         std::vector<LocalUser *> working;
20         while (!SQlist.empty())
21         {
22                 working.swap(SQlist);
23                 for(std::vector<LocalUser *>::iterator a = working.begin(); a != working.end(); a++)
24                 {
25                         LocalUser *u = *a;
26                         ServerInstance->SNO->WriteGlobalSno('a', "User %s SendQ exceeds connect class maximum of %lu",
27                                 u->nick.c_str(), u->MyClass->GetSendqHardMax());
28                         ServerInstance->Users->QuitUser(u, "SendQ exceeded");
29                 }
30                 working.clear();
31         }
32         std::set<classbase*> gone;
33         std::vector<classbase*> queue;
34         queue.reserve(list.size() + 32);
35         for(unsigned int i=0; i < list.size(); i++)
36         {
37                 classbase* c = list[i];
38                 if (gone.insert(c).second)
39                 {
40                         ServerInstance->Logs->Log("CULLLIST", DEBUG, "Deleting %s @%p", typeid(*c).name(),
41                                 (void*)c);
42                         c->cull();
43                         queue.push_back(c);
44                 }
45                 else
46                 {
47                         ServerInstance->Logs->Log("CULLLIST",DEBUG, "WARNING: Object @%p culled twice!",
48                                 (void*)c);
49                 }
50         }
51         list.clear();
52         for(unsigned int i=0; i < queue.size(); i++)
53         {
54                 classbase* c = queue[i];
55                 delete c;
56         }
57         if (list.size())
58         {
59                 ServerInstance->Logs->Log("CULLLIST",DEBUG, "WARNING: Objects added to cull list in a destructor");
60                 Apply();
61         }
62 }
63
64 void ActionList::Run()
65 {
66         for(unsigned int i=0; i < list.size(); i++)
67         {
68                 list[i]->Call();
69         }
70         list.clear();
71 }