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