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 const char* preset_reason = a->GetUser()->GetOperQuit();
91 std::string reason = a->GetReason();
92 std::string oper_reason = *preset_reason ? preset_reason : a->GetOperReason();
94 if (reason.length() > MAXQUIT - 1)
95 reason.resize(MAXQUIT - 1);
96 if (oper_reason.length() > MAXQUIT - 1)
97 oper_reason.resize(MAXQUIT - 1);
99 if (a->GetUser()->registered != REG_ALL)
100 if (ServerInstance->unregistered_count)
101 ServerInstance->unregistered_count--;
103 if (IS_LOCAL(a->GetUser()))
105 a->GetUser()->Write("ERROR :Closing link (%s@%s) [%s]", a->GetUser()->ident, a->GetUser()->host, oper_reason.c_str());
106 if ((!a->GetUser()->sendq.empty()) && (!(*a->GetUser()->GetWriteError())))
107 a->GetUser()->FlushWriteBuf();
110 if (a->GetUser()->registered == REG_ALL)
112 a->GetUser()->PurgeEmptyChannels();
113 a->GetUser()->WriteCommonQuit(reason, oper_reason);
114 FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(a->GetUser(), reason, oper_reason));
117 FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(a->GetUser()));
119 if (IS_LOCAL(a->GetUser()))
121 if (ServerInstance->Config->GetIOHook(a->GetUser()->GetPort()))
125 ServerInstance->Config->GetIOHook(a->GetUser()->GetPort())->OnRawSocketClose(a->GetUser()->GetFd());
127 catch (CoreException& modexcept)
129 ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
133 ServerInstance->SE->DelFd(a->GetUser());
134 a->GetUser()->CloseSocket();
138 * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
139 * if they were an oper with +sn +qQ.
141 if (a->GetUser()->registered == REG_ALL)
143 if (IS_LOCAL(a->GetUser()))
144 ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",a->GetUser()->nick,a->GetUser()->ident,a->GetUser()->host,oper_reason.c_str());
147 if (!ServerInstance->SilentULine(a->GetUser()->server))
148 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());
150 a->GetUser()->AddToWhoWas();
153 if (iter != ServerInstance->clientlist->end())
155 if (IS_LOCAL(a->GetUser()))
157 std::vector<userrec*>::iterator x = find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),a->GetUser());
158 if (x != ServerInstance->local_users.end())
159 ServerInstance->local_users.erase(x);
161 ServerInstance->clientlist->erase(iter);
162 DELETE(a->GetUser());
165 list.erase(list.begin());
166 exempt.erase(exemptiter);