]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cull_list.cpp
365cca2319d9c2cdfb1c8e65b4a7158440955515
[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: libIRCDcull_list */
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         if (user->quitting)
27                 return;
28
29         list.push_back(user);
30 }
31
32 void CullList::MakeSilent(User* user)
33 {
34         user->quietquit = true;
35         return;
36 }
37
38 int CullList::Apply()
39 {
40         int n = list.size();
41         int i = 0;
42
43         while (list.size() && i++ != 100)
44         {
45                 std::vector<User *>::iterator a = list.begin();
46
47                 User *u = (*a);
48                 user_hash::iterator iter = ServerInstance->clientlist->find(u->nick);
49                 const char* preset_reason = u->GetOperQuit();
50                 std::string reason = u->operquitmsg;
51                 std::string oper_reason = *preset_reason ? preset_reason : u->operquitmsg;
52
53                 if (reason.length() > MAXQUIT - 1)
54                         reason.resize(MAXQUIT - 1);
55                 if (oper_reason.length() > MAXQUIT - 1)
56                         oper_reason.resize(MAXQUIT - 1);
57
58                 if (u->registered != REG_ALL)
59                         if (ServerInstance->unregistered_count)
60                                 ServerInstance->unregistered_count--;
61
62                 if (IS_LOCAL(u))
63                 {
64                         if ((!u->sendq.empty()) && (!(*u->GetWriteError())))
65                                 u->FlushWriteBuf();
66                 }
67
68                 if (u->registered == REG_ALL)
69                 {
70                         FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(u, reason, oper_reason));
71                         u->PurgeEmptyChannels();
72                         u->WriteCommonQuit(reason, oper_reason);
73                 }
74
75                 FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(u));
76
77                 if (IS_LOCAL(u))
78                 {
79                         if (ServerInstance->Config->GetIOHook(u->GetPort()))
80                         {
81                                 try
82                                 {
83                                         ServerInstance->Config->GetIOHook(u->GetPort())->OnRawSocketClose(u->GetFd());
84                                 }
85                                 catch (CoreException& modexcept)
86                                 {
87                                         ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
88                                 }
89                         }
90
91                         ServerInstance->SE->DelFd(u);
92                         u->CloseSocket();
93                 }
94
95                 /*
96                  * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
97                  * if they were an oper with +sn +qQ.
98                  */
99                 if (u->registered == REG_ALL)
100                 {
101                         if (IS_LOCAL(u))
102                         {
103                                 if (!u->quietquit)
104                                 {
105                                         ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",u->nick,u->ident,u->host,oper_reason.c_str());
106                                 }
107                         }
108                         else
109                         {
110                                 if ((!ServerInstance->SilentULine(u->server)) && (!u->quietquit))
111                                 {
112                                         ServerInstance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]",u->server,u->nick,u->ident,u->host,oper_reason.c_str());
113                                 }
114                         }
115                         u->AddToWhoWas();
116                 }
117
118                 if (iter != ServerInstance->clientlist->end())
119                 {
120                         if (IS_LOCAL(u))
121                         {
122                                 std::vector<User*>::iterator x = find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),u);
123                                 if (x != ServerInstance->local_users.end())
124                                         ServerInstance->local_users.erase(x);
125                         }
126                         ServerInstance->clientlist->erase(iter);
127                 }
128
129                 delete u;
130                 list.erase(list.begin());
131         }
132
133         return n;
134 }
135