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