]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cull_list.cpp
Fix recursion in QuitUser
[user/henk/code/inspircd.git] / src / cull_list.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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_hash::iterator iter = ServerInstance->Users->clientlist->find(u->nick);
46                 const std::string& preset_reason = u->GetOperQuit();
47                 std::string reason;
48                 std::string oper_reason;
49
50                 reason.assign(u->quitmsg, 0, ServerInstance->Config->Limits.MaxQuit);
51                 oper_reason.assign(preset_reason.empty() ? preset_reason : u->operquitmsg, 0, ServerInstance->Config->Limits.MaxQuit);
52
53                 if (u->registered != REG_ALL)
54                         if (ServerInstance->Users->unregistered_count)
55                                 ServerInstance->Users->unregistered_count--;
56
57                 if (IS_LOCAL(u))
58                 {
59                         if (!u->sendq.empty())
60                                 u->FlushWriteBuf();
61                 }
62
63                 if (u->registered == REG_ALL)
64                 {
65                         FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(u, reason, oper_reason));
66                         u->PurgeEmptyChannels();
67                         u->WriteCommonQuit(reason, oper_reason);
68                 }
69
70                 FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(u));
71
72                 if (IS_LOCAL(u))
73                 {
74                         if (u->GetIOHook())
75                         {
76                                 try
77                                 {
78                                         u->GetIOHook()->OnRawSocketClose(u->GetFd());
79                                 }
80                                 catch (CoreException& modexcept)
81                                 {
82                                         ServerInstance->Logs->Log("CULLLIST",DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
83                                 }
84                         }
85
86                         ServerInstance->SE->DelFd(u);
87                         u->CloseSocket();
88                 }
89
90                 /*
91                  * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
92                  * if they were an oper with +sn +qQ.
93                  */
94                 if (u->registered == REG_ALL)
95                 {
96                         if (IS_LOCAL(u))
97                         {
98                                 if (!u->quietquit)
99                                 {
100                                         ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]", u->nick.c_str(), u->ident.c_str(), u->host.c_str(), oper_reason.c_str());
101                                 }
102                         }
103                         else
104                         {
105                                 if ((!ServerInstance->SilentULine(u->server)) && (!u->quietquit))
106                                 {
107                                         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(), oper_reason.c_str());
108                                 }
109                         }
110                         u->AddToWhoWas();
111                 }
112
113                 if (iter != ServerInstance->Users->clientlist->end())
114                 {
115                         ServerInstance->Users->clientlist->erase(iter);
116                 }
117                 else
118                 {
119                         ServerInstance->Logs->Log("CULLLIST", DEBUG, "iter == clientlist->end, can't remove them from hash... problematic..");
120                 }
121
122                 if (IS_LOCAL(u))
123                 {
124                         std::vector<User*>::iterator x = find(ServerInstance->Users->local_users.begin(),ServerInstance->Users->local_users.end(),u);
125                         if (x != ServerInstance->Users->local_users.end())
126                                 ServerInstance->Users->local_users.erase(x);
127                         else
128                         {
129                                 ServerInstance->Logs->Log("CULLLIST", DEBUG, "Failed to remove user from vector..");
130                         }
131                 }
132
133                 delete u;
134                 list.erase(list.begin());
135         }
136
137         return n;
138 }
139