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 * ---------------------------------------------------
15 #include "cull_list.h"
17 CullItem::CullItem(User* u, std::string &r, const char* o_reason)
22 /* Seperate oper reason not set, use the user reason */
24 this->oper_reason = o_reason;
26 this->oper_reason = r;
29 CullItem::CullItem(User* u, const char* r, const char* o_reason)
34 /* Seperate oper reason not set, use the user reason */
36 this->oper_reason = o_reason;
38 this->oper_reason = r;
41 void CullItem::MakeSilent()
46 bool CullItem::IsSilent()
55 User* CullItem::GetUser()
60 std::string& CullItem::GetReason()
65 std::string& CullItem::GetOperReason()
67 return this->oper_reason;
70 CullList::CullList(InspIRCd* Instance) : ServerInstance(Instance)
76 void CullList::AddItem(User* user, std::string &reason, const char* o_reason)
78 AddItem(user, reason.c_str(), o_reason);
82 void CullList::AddItem(User* user, const char* reason, const char* o_reason)
84 if (exempt.find(user) == exempt.end())
86 CullItem item(user, reason, o_reason);
92 void CullList::MakeSilent(User* user)
94 for (std::vector<CullItem>::iterator a = list.begin(); a != list.end(); ++a)
96 if (a->GetUser() == user)
105 int CullList::Apply()
110 std::vector<CullItem>::iterator a = list.begin();
112 user_hash::iterator iter = ServerInstance->clientlist->find(a->GetUser()->nick);
113 std::map<User*, User*>::iterator exemptiter = exempt.find(a->GetUser());
114 const char* preset_reason = a->GetUser()->GetOperQuit();
115 std::string reason = a->GetReason();
116 std::string oper_reason = *preset_reason ? preset_reason : a->GetOperReason();
118 if (reason.length() > MAXQUIT - 1)
119 reason.resize(MAXQUIT - 1);
120 if (oper_reason.length() > MAXQUIT - 1)
121 oper_reason.resize(MAXQUIT - 1);
123 if (a->GetUser()->registered != REG_ALL)
124 if (ServerInstance->unregistered_count)
125 ServerInstance->unregistered_count--;
127 if (IS_LOCAL(a->GetUser()))
129 if ((!a->GetUser()->sendq.empty()) && (!(*a->GetUser()->GetWriteError())))
130 a->GetUser()->FlushWriteBuf();
133 if (a->GetUser()->registered == REG_ALL)
135 FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(a->GetUser(), reason, oper_reason));
136 a->GetUser()->PurgeEmptyChannels();
137 a->GetUser()->WriteCommonQuit(reason, oper_reason);
140 FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(a->GetUser()));
142 if (IS_LOCAL(a->GetUser()))
144 if (ServerInstance->Config->GetIOHook(a->GetUser()->GetPort()))
148 ServerInstance->Config->GetIOHook(a->GetUser()->GetPort())->OnRawSocketClose(a->GetUser()->GetFd());
150 catch (CoreException& modexcept)
152 ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
156 ServerInstance->SE->DelFd(a->GetUser());
157 a->GetUser()->CloseSocket();
161 * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
162 * if they were an oper with +sn +qQ.
164 if (a->GetUser()->registered == REG_ALL)
166 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());
175 if ((!ServerInstance->SilentULine(a->GetUser()->server)) && (!a->IsSilent()))
177 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());
180 a->GetUser()->AddToWhoWas();
183 if (iter != ServerInstance->clientlist->end())
185 if (IS_LOCAL(a->GetUser()))
187 std::vector<User*>::iterator x = find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),a->GetUser());
188 if (x != ServerInstance->local_users.end())
189 ServerInstance->local_users.erase(x);
191 ServerInstance->clientlist->erase(iter);
195 list.erase(list.begin());
196 exempt.erase(exemptiter);