]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/cull_list.h
Remove an unneeded forward declaration and typedef
[user/henk/code/inspircd.git] / include / cull_list.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __CULLLIST_H__
15 #define __CULLLIST_H__
16
17 // include the common header files
18
19 #include <string>
20 #include <deque>
21 #include <vector>
22
23 class InspIRCd;
24
25 /** The CullItem class holds a user and their quitmessage,
26  * and is used internally by the CullList class to compile
27  * a list of users which are to be culled when a long
28  * operation (such as a netsplit) has completed.
29  */
30 class CoreExport CullItem : public classbase
31 {
32  private:
33         /** Holds a pointer to the user,
34          * must be valid and can be a local or remote user.
35          */
36         User* user;
37         /** Holds the quit reason to use for this user.
38          */
39         std::string reason;
40         /** Holds the quit reason opers see, if different from users
41          */
42         std::string oper_reason;
43         /** Silent items dont generate an snotice.
44          */
45         bool silent;
46  public:
47         /** Constrcutor.
48         * Initializes the CullItem with a user pointer
49         * and their quit reason
50         * @param u The user to add
51         * @param r The quit reason of the added user
52         * @param ro The quit reason to show to opers only
53         */
54         CullItem(User* u, std::string &r, const char* ro = "");
55         /** Constrcutor.
56          * Initializes the CullItem with a user pointer
57          * and their quit reason
58          * @param u The user to add
59          * @param r The quit reason of the added user
60          * @param ro The quit reason to show to opers only
61          */
62         CullItem(User* u, const char* r, const char* ro = "");
63
64         /** Make the quit silent a module is dealing with
65          * displaying this users quit, so we shouldn't
66          * send anything out.
67          */
68         void MakeSilent();
69
70         /** Returns true if the quit for this user has been set
71          * to silent.
72          */
73         bool IsSilent();
74
75         /** Destructor
76          */
77         ~CullItem();
78
79         /** Returns a pointer to the user
80         */
81         User* GetUser();
82         /** Returns the user's quit reason
83         */
84         std::string& GetReason();
85         /** Returns oper reason
86          */
87         std::string& GetOperReason();
88 };
89
90 /** The CullList class can be used by modules, and is used
91  * by the core, to compile large lists of users in preperation
92  * to quitting them all at once. This is faster than quitting
93  * them within the loop, as the loops become tighter with
94  * little or no comparisons within them. The CullList class
95  * operates by allowing the programmer to push users onto
96  * the list, each with a seperate quit reason, and then, once
97  * the list is complete, call a method to flush the list,
98  * quitting all the users upon it. A CullList may hold local
99  * or remote users, but it may only hold each user once. If
100  * you attempt to add the same user twice, then the second
101  * attempt will be ignored.
102  */
103 class CoreExport CullList : public classbase
104 {
105  private:
106         /** Creator of this CullList
107          */
108         InspIRCd* ServerInstance;
109
110         /** Holds a list of users already added for quick lookup
111          */
112         std::map<User*, User*> exempt;
113
114         /** Holds a list of users being quit.
115          * See the information for CullItem for
116          * more information.
117          */
118         std::vector<CullItem> list;
119
120  public:
121         /** Constructor.
122          * Clears the CullList::list and CullList::exempt
123          * items.
124          * @param Instance Creator of this CullList object
125          */
126         CullList(InspIRCd* Instance);
127
128         /** Adds a user to the cull list for later
129          * removal via QUIT.
130          * @param user The user to add
131          * @param reason The quit reason of the user being added
132          * @param o_reason The quit reason to show only to opers
133          */
134         void AddItem(User* user, std::string &reason, const char* o_reason = "");
135
136         /** Adds a user to the cull list for later
137          * removal via QUIT.
138          * @param user The user to add
139          * @param reason The quit reason of the user being added
140          * @param o_reason The quit reason to show only to opers
141          */
142         void AddItem(User* user, const char* reason, const char* o_reason = "");
143
144         /* Turn an item into a silent item (don't send out QUIT for this user)
145          */
146         void MakeSilent(User* user);
147
148         /** Applies the cull list, quitting all the users
149          * on the list with their quit reasons all at once.
150          * This is a very fast operation compared to
151          * iterating the user list and comparing each one,
152          * especially if there are multiple comparisons
153          * to be done, or recursion.
154          * @returns The number of users removed from IRC.
155          */
156         int Apply();
157 };
158
159 #endif
160