]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cull_list.cpp
Fix compile. Also remove write error stuff, as that was used prior to the goodness...
[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->Logs->Log("CULLLIST",DEBUG, "*** Warning *** - You tried to quit a user (%s) twice. Did your module call QuitUser twice?", user->nick.c_str());
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 std::string& preset_reason = u->GetOperQuit();
54                 std::string reason;
55                 std::string oper_reason;
56
57                 reason.assign(u->quitmsg, 0, ServerInstance->Config->Limits.MaxQuit);
58                 oper_reason.assign(preset_reason.empty() ? preset_reason : u->operquitmsg, 0, ServerInstance->Config->Limits.MaxQuit);
59
60                 if (u->registered != REG_ALL)
61                         if (ServerInstance->Users->unregistered_count)
62                                 ServerInstance->Users->unregistered_count--;
63
64                 if (IS_LOCAL(u))
65                 {
66                         if (!u->sendq.empty())
67                                 u->FlushWriteBuf();
68                 }
69
70                 if (u->registered == REG_ALL)
71                 {
72                         FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(u, reason, oper_reason));
73                         u->PurgeEmptyChannels();
74                         u->WriteCommonQuit(reason, oper_reason);
75                 }
76
77                 FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(u));
78
79                 if (IS_LOCAL(u))
80                 {
81                         if (u->io)
82                         {
83                                 try
84                                 {
85                                         u->io->OnRawSocketClose(u->GetFd());
86                                 }
87                                 catch (CoreException& modexcept)
88                                 {
89                                         ServerInstance->Logs->Log("CULLLIST",DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
90                                 }
91                         }
92
93                         ServerInstance->SE->DelFd(u);
94                         u->CloseSocket();
95                 }
96
97                 /*
98                  * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
99                  * if they were an oper with +sn +qQ.
100                  */
101                 if (u->registered == REG_ALL)
102                 {
103                         if (IS_LOCAL(u))
104                         {
105                                 if (!u->quietquit)
106                                 {
107                                         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());
108                                 }
109                         }
110                         else
111                         {
112                                 if ((!ServerInstance->SilentULine(u->server)) && (!u->quietquit))
113                                 {
114                                         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());
115                                 }
116                         }
117                         u->AddToWhoWas();
118                 }
119
120                 if (iter != ServerInstance->Users->clientlist->end())
121                 {
122                         ServerInstance->Users->clientlist->erase(iter);
123                 }
124                 else
125                 {
126                         ServerInstance->Logs->Log("CULLLIST", DEBUG, "iter == clientlist->end, can't remove them from hash... problematic..");
127                 }
128
129                 if (IS_LOCAL(u))
130                 {
131                         std::vector<User*>::iterator x = find(ServerInstance->Users->local_users.begin(),ServerInstance->Users->local_users.end(),u);
132                         if (x != ServerInstance->Users->local_users.end())
133                                 ServerInstance->Users->local_users.erase(x);
134                         else
135                         {
136                                 ServerInstance->Logs->Log("CULLLIST", DEBUG, "Failed to remove user from vector..");
137                         }
138                 }
139
140                 delete u;
141                 list.erase(list.begin());
142         }
143
144         return n;
145 }
146