]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/cull_list.h
And now, just to force you to recompile the *whole* ircd.. updated headers on the...
[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 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  public:
43         /** Constrcutor.
44          * Initializes the CullItem with a user pointer
45          * and their quit reason
46          * @param u The user to add
47          * @param r The quit reason of the added user
48          */
49         CullItem(userrec* u, std::string &r);
50         CullItem(userrec* u, const char* r);
51
52         ~CullItem();
53
54         /** Returns a pointer to the user
55          */
56         userrec* GetUser();
57         /** Returns the user's quit reason
58          */
59         std::string& GetReason();
60 };
61
62 /** The CullList class can be used by modules, and is used
63  * by the core, to compile large lists of users in preperation
64  * to quitting them all at once. This is faster than quitting
65  * them within the loop, as the loops become tighter with
66  * little or no comparisons within them. The CullList class
67  * operates by allowing the programmer to push users onto
68  * the list, each with a seperate quit reason, and then, once
69  * the list is complete, call a method to flush the list,
70  * quitting all the users upon it. A CullList may hold local
71  * or remote users, but it may only hold each user once. If
72  * you attempt to add the same user twice, then the second
73  * attempt will be ignored.
74  */
75 class CullList : public classbase
76 {
77  private:
78          /** Creator of this CullList
79           */
80          InspIRCd* ServerInstance;
81          /** Holds a list of users being quit.
82           * See the information for CullItem for
83           * more information.
84           */
85          std::vector<CullItem> list;
86          /** A list of users who have already been
87           * placed on the list, as a map for fast
88           * reference. When deleting an item, the
89           * time_t value stored here must match
90           * the one of the actual userrec, otherwise
91           * we don't delete it (its a different user)
92           */
93          std::map<userrec*,time_t> exempt;
94          
95          /** Check if a user pointer is valid
96           * (e.g. it exists in the user hash)
97           */
98          bool IsValid(userrec* user);
99  public:
100          /** Constructor.
101           * Clears the CullList::list and CullList::exempt
102           * items.
103           * @param Instance Creator of this CullList object
104           */
105          CullList(InspIRCd* Instance);
106          /** Adds a user to the cull list for later
107           * removal via QUIT.
108           * @param user The user to add
109           * @param reason The quit reason of the user being added
110           */
111          void AddItem(userrec* user, std::string &reason);
112          void AddItem(userrec* user, const char* reason);
113          /** Applies the cull list, quitting all the users
114           * on the list with their quit reasons all at once.
115           * This is a very fast operation compared to
116           * iterating the user list and comparing each one,
117           * especially if there are multiple comparisons
118           * to be done, or recursion.
119           * @returns The number of users removed from IRC.
120           */
121          int Apply();
122 };
123
124 #endif