]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cull_list.cpp
Fix CullList to not use O(n^2) version of vector clear
[user/henk/code/inspircd.git] / src / cull_list.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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 /* $Core */
15
16 #include "inspircd.h"
17 #include "cull_list.h"
18
19 CullList::CullList(InspIRCd* Instance) : ServerInstance(Instance)
20 {
21 }
22
23 void CullList::AddItem(User* user)
24 {
25         list.push_back(user);
26 }
27
28 void CullList::MakeSilent(User* user)
29 {
30         user->quietquit = true;
31         return;
32 }
33
34 void CullList::Apply()
35 {
36         for(std::vector<User *>::iterator a = list.begin(); a != list.end(); a++)
37         {
38                 User *u = *a;
39                 // user has been moved onto their UID; that's why this isn't find(u->nick)
40                 user_hash::iterator iter = ServerInstance->Users->clientlist->find(u->uuid);
41
42                 if (u->registered != REG_ALL)
43                         if (ServerInstance->Users->unregistered_count)
44                                 ServerInstance->Users->unregistered_count--;
45
46                 if (IS_LOCAL(u))
47                 {
48                         if (!u->sendq.empty())
49                                 u->FlushWriteBuf();
50
51                         if (u->GetIOHook())
52                         {
53                                 try
54                                 {
55                                         u->GetIOHook()->OnRawSocketClose(u->GetFd());
56                                 }
57                                 catch (CoreException& modexcept)
58                                 {
59                                         ServerInstance->Logs->Log("CULLLIST",DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
60                                 }
61                         }
62
63                         ServerInstance->SE->DelFd(u);
64                         u->CloseSocket();
65                 }
66
67                 /*
68                  * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
69                  * if they were an oper with +sn +qQ.
70                  */
71                 if (u->registered == REG_ALL)
72                 {
73                         if (IS_LOCAL(u))
74                         {
75                                 if (!u->quietquit)
76                                 {
77                                         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());
78                                 }
79                         }
80                         else
81                         {
82                                 if ((!ServerInstance->SilentULine(u->server)) && (!u->quietquit))
83                                 {
84                                         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());
85                                 }
86                         }
87                         u->AddToWhoWas();
88                 }
89
90                 if (iter != ServerInstance->Users->clientlist->end())
91                 {
92                         ServerInstance->Users->clientlist->erase(iter);
93                 }
94                 else
95                 {
96                         ServerInstance->Logs->Log("CULLLIST", DEBUG, "iter == clientlist->end, can't remove them from hash... problematic..");
97                 }
98
99                 if (IS_LOCAL(u))
100                 {
101                         std::vector<User*>::iterator x = find(ServerInstance->Users->local_users.begin(),ServerInstance->Users->local_users.end(),u);
102                         if (x != ServerInstance->Users->local_users.end())
103                                 ServerInstance->Users->local_users.erase(x);
104                         else
105                         {
106                                 ServerInstance->Logs->Log("CULLLIST", DEBUG, "Failed to remove user from vector..");
107                         }
108                 }
109
110                 delete u;
111         }
112         list.clear();
113 }
114