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 * ---------------------------------------------------
14 #ifndef __CULLLIST_H__
15 #define __CULLLIST_H__
17 // include the common header files
27 /** The CullItem class holds a user and their quitmessage,
28 * and is used internally by the CullList class to compile
29 * a list of users which are to be culled when a long
30 * operation (such as a netsplit) has completed.
32 class CoreExport CullItem : public classbase
35 /** Holds a pointer to the user,
36 * must be valid and can be a local or remote user.
39 /** Holds the quit reason to use for this user.
42 /** Holds the quit reason opers see, if different from users
44 std::string oper_reason;
45 /** Silent items dont generate an snotice.
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, const char* ro = "");
56 CullItem(userrec* u, const char* r, const char* ro = "");
63 /** Returns a pointer to the user
66 /** Returns the user's quit reason
68 std::string& GetReason();
69 /** Returns oper reason
71 std::string& GetOperReason();
74 /** The CullList class can be used by modules, and is used
75 * by the core, to compile large lists of users in preperation
76 * to quitting them all at once. This is faster than quitting
77 * them within the loop, as the loops become tighter with
78 * little or no comparisons within them. The CullList class
79 * operates by allowing the programmer to push users onto
80 * the list, each with a seperate quit reason, and then, once
81 * the list is complete, call a method to flush the list,
82 * quitting all the users upon it. A CullList may hold local
83 * or remote users, but it may only hold each user once. If
84 * you attempt to add the same user twice, then the second
85 * attempt will be ignored.
87 class CoreExport CullList : public classbase
90 /** Creator of this CullList
92 InspIRCd* ServerInstance;
94 /** Holds a list of users already added for quick lookup
96 std::map<userrec*, userrec*> exempt;
98 /** Holds a list of users being quit.
99 * See the information for CullItem for
102 std::vector<CullItem> list;
106 * Clears the CullList::list and CullList::exempt
108 * @param Instance Creator of this CullList object
110 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, const char* o_reason = "");
118 void AddItem(userrec* user, const char* reason, const char* o_reason = "");
120 /* Turn an item into a silent item
122 void MakeSilent(userrec* user);
124 /** Applies the cull list, quitting all the users
125 * on the list with their quit reasons all at once.
126 * This is a very fast operation compared to
127 * iterating the user list and comparing each one,
128 * especially if there are multiple comparisons
129 * to be done, or recursion.
130 * @returns The number of users removed from IRC.