1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $Core: libIRCDcull_list */
17 #include "cull_list.h"
19 CullItem::CullItem(User* u, std::string &r, const char* o_reason)
24 /* Seperate oper reason not set, use the user reason */
26 this->oper_reason = o_reason;
28 this->oper_reason = r;
31 CullItem::CullItem(User* u, const char* r, const char* o_reason)
36 /* Seperate oper reason not set, use the user reason */
38 this->oper_reason = o_reason;
40 this->oper_reason = r;
43 void CullItem::MakeSilent()
48 bool CullItem::IsSilent()
57 User* CullItem::GetUser()
62 std::string& CullItem::GetReason()
67 std::string& CullItem::GetOperReason()
69 return this->oper_reason;
72 CullList::CullList(InspIRCd* Instance) : ServerInstance(Instance)
78 void CullList::AddItem(User* user, std::string &reason, const char* o_reason)
80 AddItem(user, reason.c_str(), o_reason);
84 void CullList::AddItem(User* user, const char* reason, const char* o_reason)
86 if (exempt.find(user) == exempt.end())
88 CullItem item(user, reason, o_reason);
94 void CullList::MakeSilent(User* user)
96 for (std::vector<CullItem>::iterator a = list.begin(); a != list.end(); ++a)
98 if (a->GetUser() == user)
107 int CullList::Apply()
112 std::vector<CullItem>::iterator a = list.begin();
114 User *u = a->GetUser();
115 user_hash::iterator iter = ServerInstance->clientlist->find(u->nick);
116 std::map<User*, User*>::iterator exemptiter = exempt.find(u);
117 const char* preset_reason = u->GetOperQuit();
118 std::string reason = a->GetReason();
119 std::string oper_reason = *preset_reason ? preset_reason : a->GetOperReason();
121 if (reason.length() > MAXQUIT - 1)
122 reason.resize(MAXQUIT - 1);
123 if (oper_reason.length() > MAXQUIT - 1)
124 oper_reason.resize(MAXQUIT - 1);
126 if (u->registered != REG_ALL)
127 if (ServerInstance->unregistered_count)
128 ServerInstance->unregistered_count--;
132 if ((!u->sendq.empty()) && (!(*u->GetWriteError())))
136 if (u->registered == REG_ALL)
138 FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(u, reason, oper_reason));
139 u->PurgeEmptyChannels();
140 u->WriteCommonQuit(reason, oper_reason);
143 FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(u));
147 if (ServerInstance->Config->GetIOHook(u->GetPort()))
151 ServerInstance->Config->GetIOHook(u->GetPort())->OnRawSocketClose(u->GetFd());
153 catch (CoreException& modexcept)
155 ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
159 ServerInstance->SE->DelFd(u);
164 * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
165 * if they were an oper with +sn +qQ.
167 if (u->registered == REG_ALL)
173 ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",u->nick,u->ident,u->host,oper_reason.c_str());
178 if ((!ServerInstance->SilentULine(u->server)) && (!a->IsSilent()))
180 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());
186 if (iter != ServerInstance->clientlist->end())
190 std::vector<User*>::iterator x = find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),u);
191 if (x != ServerInstance->local_users.end())
192 ServerInstance->local_users.erase(x);
194 ServerInstance->clientlist->erase(iter);
198 list.erase(list.begin());
199 exempt.erase(exemptiter);