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 * ---------------------------------------------------
17 #ifndef __CULLLIST_H__
18 #define __CULLLIST_H__
20 // include the common header files
33 /** The CullItem class holds a user and their quitmessage,
34 * and is used internally by the CullList class to compile
35 * a list of users which are to be culled when a long
36 * operation (such as a netsplit) has completed.
38 class CullItem : public classbase
41 /** Holds a pointer to the user,
42 * must be valid and can be a local or remote user.
45 /** Holds the quit reason to use for this user.
50 * Initializes the CullItem with a user pointer
51 * and their quit reason
52 * @param u The user to add
53 * @param r The quit reason of the added user
55 CullItem(userrec* u, std::string &r);
56 CullItem(userrec* u, const char* r);
60 /** Returns a pointer to the user
63 /** Returns the user's quit reason
65 std::string& GetReason();
68 /** The CullList class can be used by modules, and is used
69 * by the core, to compile large lists of users in preperation
70 * to quitting them all at once. This is faster than quitting
71 * them within the loop, as the loops become tighter with
72 * little or no comparisons within them. The CullList class
73 * operates by allowing the programmer to push users onto
74 * the list, each with a seperate quit reason, and then, once
75 * the list is complete, call a method to flush the list,
76 * quitting all the users upon it. A CullList may hold local
77 * or remote users, but it may only hold each user once. If
78 * you attempt to add the same user twice, then the second
79 * attempt will be ignored.
81 class CullList : public classbase
84 /** Creator of this CullList
86 InspIRCd* ServerInstance;
87 /** Holds a list of users being quit.
88 * See the information for CullItem for
91 std::vector<CullItem> list;
92 /** A list of users who have already been
93 * placed on the list, as a map for fast
94 * reference. When deleting an item, the
95 * time_t value stored here must match
96 * the one of the actual userrec, otherwise
97 * we don't delete it (its a different user)
99 std::map<userrec*,time_t> exempt;
101 /** Check if a user pointer is valid
102 * (e.g. it exists in the user hash)
104 bool IsValid(userrec* user);
107 * Clears the CullList::list and CullList::exempt
109 * @param Instance Creator of this CullList object
111 CullList(InspIRCd* Instance);
112 /** Adds a user to the cull list for later
114 * @param user The user to add
115 * @param reason The quit reason of the user being added
117 void AddItem(userrec* user, std::string &reason);
118 void AddItem(userrec* user, const char* reason);
119 /** Applies the cull list, quitting all the users
120 * on the list with their quit reasons all at once.
121 * This is a very fast operation compared to
122 * iterating the user list and comparing each one,
123 * especially if there are multiple comparisons
124 * to be done, or recursion.
125 * @returns The number of users removed from IRC.