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