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)
22 /* Seperate oper reason not set, use the user reason */
24 this->oper_reason = o_reason;
26 this->oper_reason = r;
29 CullItem::CullItem(userrec* u, const char* r, const char* o_reason)
33 /* Seperate oper reason not set, use the user reason */
35 this->oper_reason = o_reason;
37 this->oper_reason = r;
44 userrec* CullItem::GetUser()
49 std::string& CullItem::GetReason()
54 std::string& CullItem::GetOperReason()
56 return this->oper_reason;
59 CullList::CullList(InspIRCd* Instance) : ServerInstance(Instance)
65 void CullList::AddItem(userrec* user, std::string &reason, const char* o_reason)
67 AddItem(user, reason.c_str(), o_reason);
71 void CullList::AddItem(userrec* user, const char* reason, const char* o_reason)
73 if (exempt.find(user) == exempt.end())
75 CullItem item(user, reason, o_reason);
86 std::vector<CullItem>::iterator a = list.begin();
88 user_hash::iterator iter = ServerInstance->clientlist->find(a->GetUser()->nick);
89 std::map<userrec*, userrec*>::iterator exemptiter = exempt.find(a->GetUser());
90 std::string reason = a->GetReason();
91 std::string oper_reason = a->GetOperReason();
93 if (reason.length() > MAXQUIT - 1)
94 reason.resize(MAXQUIT - 1);
95 if (oper_reason.length() > MAXQUIT - 1)
96 oper_reason.resize(MAXQUIT - 1);
98 if (a->GetUser()->registered != REG_ALL)
99 if (ServerInstance->unregistered_count)
100 ServerInstance->unregistered_count--;
102 if (IS_LOCAL(a->GetUser()))
104 a->GetUser()->Write("ERROR :Closing link (%s@%s) [%s]", a->GetUser()->ident, a->GetUser()->host, oper_reason.c_str());
105 if ((!a->GetUser()->sendq.empty()) && (!(*a->GetUser()->GetWriteError())))
106 a->GetUser()->FlushWriteBuf();
109 if (a->GetUser()->registered == REG_ALL)
111 a->GetUser()->PurgeEmptyChannels();
112 a->GetUser()->WriteCommonQuit(reason, oper_reason);
113 FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(a->GetUser(), reason));
116 FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(a->GetUser()));
118 if (IS_LOCAL(a->GetUser()))
120 if (ServerInstance->Config->GetIOHook(a->GetUser()->GetPort()))
124 ServerInstance->Config->GetIOHook(a->GetUser()->GetPort())->OnRawSocketClose(a->GetUser()->GetFd());
126 catch (CoreException& modexcept)
128 ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
132 ServerInstance->SE->DelFd(a->GetUser());
133 a->GetUser()->CloseSocket();
137 * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
138 * if they were an oper with +sn +qQ.
140 if (a->GetUser()->registered == REG_ALL)
142 if (IS_LOCAL(a->GetUser()))
143 ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",a->GetUser()->nick,a->GetUser()->ident,a->GetUser()->host,oper_reason.c_str());
145 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());
146 a->GetUser()->AddToWhoWas();
149 if (iter != ServerInstance->clientlist->end())
151 if (IS_LOCAL(a->GetUser()))
153 std::vector<userrec*>::iterator x = find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),a->GetUser());
154 if (x != ServerInstance->local_users.end())
155 ServerInstance->local_users.erase(x);
157 ServerInstance->clientlist->erase(iter);
158 DELETE(a->GetUser());
161 list.erase(list.begin());
162 exempt.erase(exemptiter);