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 * ---------------------------------------------------
16 #include "cull_list.h"
18 CullItem::CullItem(userrec* u, std::string &r, const char* o_reason)
23 /* Seperate oper reason not set, use the user reason */
25 this->oper_reason = o_reason;
27 this->oper_reason = r;
30 CullItem::CullItem(userrec* u, const char* r, const char* o_reason)
35 /* Seperate oper reason not set, use the user reason */
37 this->oper_reason = o_reason;
39 this->oper_reason = r;
42 void CullItem::MakeSilent()
47 bool CullItem::IsSilent()
56 userrec* CullItem::GetUser()
61 std::string& CullItem::GetReason()
66 std::string& CullItem::GetOperReason()
68 return this->oper_reason;
71 CullList::CullList(InspIRCd* Instance) : ServerInstance(Instance)
77 void CullList::AddItem(userrec* user, std::string &reason, const char* o_reason)
79 AddItem(user, reason.c_str(), o_reason);
83 void CullList::AddItem(userrec* user, const char* reason, const char* o_reason)
85 if (exempt.find(user) == exempt.end())
87 CullItem item(user, reason, o_reason);
93 void CullList::MakeSilent(userrec* user)
95 for (std::vector<CullItem>::iterator a = list.begin(); a != list.end(); ++a)
97 if (a->GetUser() == user)
106 int CullList::Apply()
111 std::vector<CullItem>::iterator a = list.begin();
113 user_hash::iterator iter = ServerInstance->clientlist->find(a->GetUser()->nick);
114 std::map<userrec*, userrec*>::iterator exemptiter = exempt.find(a->GetUser());
115 const char* preset_reason = a->GetUser()->GetOperQuit();
116 std::string reason = a->GetReason();
117 std::string oper_reason = *preset_reason ? preset_reason : a->GetOperReason();
119 if (reason.length() > MAXQUIT - 1)
120 reason.resize(MAXQUIT - 1);
121 if (oper_reason.length() > MAXQUIT - 1)
122 oper_reason.resize(MAXQUIT - 1);
124 if (a->GetUser()->registered != REG_ALL)
125 if (ServerInstance->unregistered_count)
126 ServerInstance->unregistered_count--;
128 if (IS_LOCAL(a->GetUser()))
130 a->GetUser()->Write("ERROR :Closing link (%s@%s) [%s]", a->GetUser()->ident, a->GetUser()->host, oper_reason.c_str());
131 if ((!a->GetUser()->sendq.empty()) && (!(*a->GetUser()->GetWriteError())))
132 a->GetUser()->FlushWriteBuf();
135 if (a->GetUser()->registered == REG_ALL)
137 FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(a->GetUser(), reason, oper_reason));
138 a->GetUser()->PurgeEmptyChannels();
139 a->GetUser()->WriteCommonQuit(reason, oper_reason);
142 FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(a->GetUser()));
144 if (IS_LOCAL(a->GetUser()))
146 if (ServerInstance->Config->GetIOHook(a->GetUser()->GetPort()))
150 ServerInstance->Config->GetIOHook(a->GetUser()->GetPort())->OnRawSocketClose(a->GetUser()->GetFd());
152 catch (CoreException& modexcept)
154 ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
158 ServerInstance->SE->DelFd(a->GetUser());
159 a->GetUser()->CloseSocket();
163 * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
164 * if they were an oper with +sn +qQ.
166 if (a->GetUser()->registered == REG_ALL)
168 if (IS_LOCAL(a->GetUser()))
170 ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",a->GetUser()->nick,a->GetUser()->ident,a->GetUser()->host,oper_reason.c_str());
173 if (!ServerInstance->SilentULine(a->GetUser()->server))
175 ServerInstance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]",a->GetUser()->server,a->GetUser()->nick,a->GetUser()->ident,a->GetUser()->host,oper_reason.c_str());
177 a->GetUser()->AddToWhoWas();
180 if (iter != ServerInstance->clientlist->end())
182 if (IS_LOCAL(a->GetUser()))
184 std::vector<userrec*>::iterator x = find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),a->GetUser());
185 if (x != ServerInstance->local_users.end())
186 ServerInstance->local_users.erase(x);
188 ServerInstance->clientlist->erase(iter);
189 DELETE(a->GetUser());
192 list.erase(list.begin());
193 exempt.erase(exemptiter);