]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/usermanager.h
Change storage of UserManager::all_opers to be a vector
[user/henk/code/inspircd.git] / include / usermanager.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #pragma once
21
22 #include <list>
23
24 class CoreExport UserManager
25 {
26  public:
27         struct CloneCounts
28         {
29                 unsigned int global;
30                 unsigned int local;
31                 CloneCounts() : global(0), local(0) { }
32         };
33
34         /** Container that maps IP addresses to clone counts
35          */
36         typedef std::map<irc::sockets::cidr_mask, CloneCounts> CloneMap;
37
38         /** Sequence container in which each element is a User*
39          */
40         typedef std::vector<User*> OperList;
41
42  private:
43         /** Map of IP addresses for clone counting
44          */
45         CloneMap clonemap;
46
47         /** A CloneCounts that contains zero for both local and global
48          */
49         const CloneCounts zeroclonecounts;
50
51  public:
52         /** Constructor, initializes variables
53          */
54         UserManager();
55
56         /** Destructor, destroys all users in clientlist
57          */
58         ~UserManager();
59
60         /** Client list, a hash_map containing all clients, local and remote
61          */
62         user_hash clientlist;
63
64         /** Client list stored by UUID. Contains all clients, and is updated
65          * automatically by the constructor and destructor of User.
66          */
67         user_hash uuidlist;
68
69         /** Local client list, a list containing only local clients
70          */
71         LocalUserList local_users;
72
73         /** Oper list, a vector containing all local and remote opered users
74          */
75         OperList all_opers;
76
77         /** Number of unregistered users online right now.
78          * (Unregistered means before USER/NICK/dns)
79          */
80         unsigned int unregistered_count;
81
82         /**
83          * Reset the already_sent IDs so we don't wrap it around and drop a message
84          * Also removes all expired invites
85      */
86         void GarbageCollect();
87
88         /** Perform background user events such as PING checks
89          */
90         void DoBackgroundUserStuff();
91
92         /** Returns true when all modules have done pre-registration checks on a user
93          * @param user The user to verify
94          * @return True if all modules have finished checking this user
95          */
96         bool AllModulesReportReady(LocalUser* user);
97
98         /** Add a client to the system.
99          * This will create a new User, insert it into the user_hash,
100          * initialize it as not yet registered, and add it to the socket engine.
101          * @param socket The socket id (file descriptor) this user is on
102          * @param via The socket that this user connected using
103          * @param client The IP address and client port of the user
104          * @param server The server IP address and port used by the user
105          * @return This function has no return value, but a call to AddClient may remove the user.
106          */
107         void AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
108
109         /** Disconnect a user gracefully
110          * @param user The user to remove
111          * @param quitreason The quit reason to show to normal users
112          * @param operreason The quit reason to show to opers, can be NULL if same as quitreason
113          * @return Although this function has no return type, on exit the user provided will no longer exist.
114          */
115         void QuitUser(User* user, const std::string& quitreason, const std::string* operreason = NULL);
116
117         /** Add a user to the clone map
118          * @param user The user to add
119          */
120         void AddClone(User* user);
121
122         /** Remove all clone counts from the user, you should
123          * use this if you change the user's IP address
124          * after they have registered.
125          * @param user The user to remove
126          */
127         void RemoveCloneCounts(User *user);
128
129         /** Return the number of local and global clones of this user
130          * @param user The user to get the clone counts for
131          * @return The clone counts of this user. The returned reference is volatile - you
132          * must assume that it becomes invalid as soon as you call any function other than
133          * your own.
134          */
135         const CloneCounts& GetCloneCounts(User* user) const;
136
137         /** Return a map containg IP addresses and their clone counts
138          * @return The clone count map
139          */
140         const CloneMap& GetCloneMap() const { return clonemap; }
141
142         /** Return a count of all global users, unknown and known connections
143          * @return The number of users on the network, including local unregistered users
144          */
145         unsigned int UserCount() const { return this->clientlist.size(); }
146
147         /** Return a count of fully registered connections on the network
148          * @return The number of registered users on the network
149          */
150         unsigned int RegisteredUserCount() { return this->clientlist.size() - this->UnregisteredUserCount(); }
151
152         /** Return a count of opered (umode +o) users on the network
153          * @return The number of opers on the network
154          */
155         unsigned int OperCount() const { return this->all_opers.size(); }
156
157         /** Return a count of local unregistered (before NICK/USER) users
158          * @return The number of local unregistered (unknown) connections
159          */
160         unsigned int UnregisteredUserCount() const { return this->unregistered_count; }
161
162         /** Return a count of local registered users
163          * @return The number of registered local users
164          */
165         unsigned int LocalUserCount() const { return (this->local_users.size() - this->UnregisteredUserCount()); }
166
167         /** Get a hash map containing all users, keyed by their nickname
168          * @return A hash map mapping nicknames to User pointers
169          */
170         user_hash& GetUsers() { return clientlist; }
171
172         /** Send a server notice to all local users
173          * @param text The text format string to send
174          * @param ... The format arguments
175          */
176         void ServerNoticeAll(const char* text, ...) CUSTOM_PRINTF(2, 3);
177 };