1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
19 #include "inspircd_config.h"
34 #include "inspstring.h"
36 #include "helperfuncs.h"
39 #include "cull_list.h"
41 extern InspIRCd* ServerInstance;
44 * In current implementation of CullList, this isn't used. It did odd things with a lot of sockets.
46 bool CullList::IsValid(userrec* user)
49 std::map<userrec*,time_t>::iterator es = exempt.find(user);
50 if (es != exempt.end())
53 for (user_hash::iterator u = ServerInstance->clientlist.begin(); u != ServerInstance->clientlist.end(); u++)
58 * Because there is an undetermined period of time between a user existing,
59 * and this function being called, we have to check for the following condition:
61 * Between CullList::AddItem(u) being called, and CullList::IsValid(u) being called,
62 * the user with the pointer u has quit, but only to be REPLACED WITH A NEW USER WHO
63 * BECAUSE OF ALLOCATION RULES, HAS THE SAME MEMORY ADDRESS! To prevent this, we
64 * cross reference each pointer to the user's signon time, and if the signon times
65 * do not match, we return false here to indicate this user is NOT valid as it
66 * seems to differ from the pointer snapshot we got a few seconds earlier. Should
67 * prevent a few random crashes during netsplits.
69 if (user == u->second)
70 return (u->second->signon == esignon);
75 CullItem::CullItem(userrec* u, std::string &r)
81 CullItem::CullItem(userrec* u, const char* r)
91 userrec* CullItem::GetUser()
96 std::string& CullItem::GetReason()
107 void CullList::AddItem(userrec* user, std::string &reason)
109 if (exempt.find(user) == exempt.end())
111 CullItem item(user,reason);
112 list.push_back(item);
113 exempt[user] = user->signon;
117 void CullList::AddItem(userrec* user, const char* reason)
119 if (exempt.find(user) == exempt.end())
121 CullItem item(user,reason);
122 list.push_back(item);
123 exempt[user] = user->signon;
127 int CullList::Apply()
132 std::vector<CullItem>::iterator a = list.begin();
134 userrec::QuitUser(ServerInstance, a->GetUser(), a->GetReason().c_str());
135 list.erase(list.begin());