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)
24 CullItem::CullItem(userrec* u, const char* r)
34 userrec* CullItem::GetUser()
39 std::string& CullItem::GetReason()
44 CullList::CullList(InspIRCd* Instance) : ServerInstance(Instance)
50 void CullList::AddItem(userrec* user, std::string &reason)
52 AddItem(user, reason.c_str());
56 void CullList::AddItem(userrec* user, const char* reason)
58 if (exempt.find(user) == exempt.end())
60 CullItem item(user,reason);
71 std::vector<CullItem>::iterator a = list.begin();
73 user_hash::iterator iter = ServerInstance->clientlist->find(a->GetUser()->nick);
74 std::map<userrec*, userrec*>::iterator exemptiter = exempt.find(a->GetUser());
75 std::string reason = a->GetReason();
77 if (reason.length() > MAXQUIT - 1)
78 reason.resize(MAXQUIT - 1);
80 if (a->GetUser()->registered != REG_ALL)
81 if (ServerInstance->unregistered_count)
82 ServerInstance->unregistered_count--;
84 if (IS_LOCAL(a->GetUser()))
86 a->GetUser()->Write("ERROR :Closing link (%s@%s) [%s]",a->GetUser()->ident,a->GetUser()->host,reason.c_str());
87 if ((!a->GetUser()->sendq.empty()) && (!(*a->GetUser()->GetWriteError())))
88 a->GetUser()->FlushWriteBuf();
91 if (a->GetUser()->registered == REG_ALL)
93 a->GetUser()->PurgeEmptyChannels();
94 a->GetUser()->WriteCommonExcept("QUIT :%s",reason.c_str());
95 FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(a->GetUser(),reason));
98 FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(a->GetUser()));
100 if (IS_LOCAL(a->GetUser()))
102 if (ServerInstance->Config->GetIOHook(a->GetUser()->GetPort()))
106 ServerInstance->Config->GetIOHook(a->GetUser()->GetPort())->OnRawSocketClose(a->GetUser()->GetFd());
108 catch (CoreException& modexcept)
110 ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
114 ServerInstance->SE->DelFd(a->GetUser());
115 a->GetUser()->CloseSocket();
119 * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
120 * if they were an oper with +sn +qQ.
122 if (a->GetUser()->registered == REG_ALL)
124 if (IS_LOCAL(a->GetUser()))
125 ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",a->GetUser()->nick,a->GetUser()->ident,a->GetUser()->host,reason.c_str());
127 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,reason.c_str());
128 a->GetUser()->AddToWhoWas();
131 if (iter != ServerInstance->clientlist->end())
133 if (IS_LOCAL(a->GetUser()))
135 std::vector<userrec*>::iterator x = find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),a->GetUser());
136 if (x != ServerInstance->local_users.end())
137 ServerInstance->local_users.erase(x);
139 ServerInstance->clientlist->erase(iter);
140 DELETE(a->GetUser());
143 list.erase(list.begin());
144 exempt.erase(exemptiter);