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"
21 #include "inspircd_io.h"
24 #include <sys/errno.h>
28 #include <ext/hash_map>
45 #include "inspstring.h"
47 #include "helperfuncs.h"
50 #include "cull_list.h"
52 extern InspIRCd* ServerInstance;
53 extern user_hash clientlist;
56 * In current implementation of CullList, this isn't used. It did odd things with a lot of sockets.
58 bool CullList::IsValid(userrec* user)
61 std::map<userrec*,time_t>::iterator es = exempt.find(user);
62 if (es != exempt.end())
65 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
70 * Because there is an undetermined period of time between a user existing,
71 * and this function being called, we have to check for the following condition:
73 * Between CullList::AddItem(u) being called, and CullList::IsValid(u) being called,
74 * the user with the pointer u has quit, but only to be REPLACED WITH A NEW USER WHO
75 * BECAUSE OF ALLOCATION RULES, HAS THE SAME MEMORY ADDRESS! To prevent this, we
76 * cross reference each pointer to the user's signon time, and if the signon times
77 * do not match, we return false here to indicate this user is NOT valid as it
78 * seems to differ from the pointer snapshot we got a few seconds earlier. Should
79 * prevent a few random crashes during netsplits.
81 if (user == u->second)
82 return (u->second->signon == esignon);
87 CullItem::CullItem(userrec* u, std::string &r)
93 CullItem::CullItem(userrec* u, const char* r)
103 userrec* CullItem::GetUser()
108 std::string& CullItem::GetReason()
119 void CullList::AddItem(userrec* user, std::string &reason)
121 if (exempt.find(user) == exempt.end())
123 CullItem item(user,reason);
124 list.push_back(item);
125 exempt[user] = user->signon;
129 void CullList::AddItem(userrec* user, const char* reason)
131 if (exempt.find(user) == exempt.end())
133 CullItem item(user,reason);
134 list.push_back(item);
135 exempt[user] = user->signon;
139 int CullList::Apply()
144 std::vector<CullItem>::iterator a = list.begin();
146 kill_link(a->GetUser(), a->GetReason().c_str());
147 list.erase(list.begin());