]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/usermanager.h
c6745ace626d12f2347c6caeccbe881e3b351884
[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 /** A list of ip addresses cross referenced against clone counts */
25 typedef std::map<irc::sockets::cidr_mask, unsigned int> clonemap;
26
27 class CoreExport UserManager
28 {
29  private:
30         /** Map of local ip addresses for clone counting
31          */
32         clonemap local_clones;
33
34  public:
35         /** Constructor, initializes variables and allocates the hashmaps
36          */
37         UserManager();
38
39         /** Destructor, destroys all users in clientlist and then deallocates
40          * the hashmaps
41          */
42         ~UserManager();
43
44         /** Client list, a hash_map containing all clients, local and remote
45          */
46         user_hash* clientlist;
47
48         /** Client list stored by UUID. Contains all clients, and is updated
49          * automatically by the constructor and destructor of User.
50          */
51         user_hash* uuidlist;
52
53         /** Local client list, a list containing only local clients
54          */
55         LocalUserList local_users;
56
57         /** Oper list, a vector containing all local and remote opered users
58          */
59         std::list<User*> all_opers;
60
61         /** Number of unregistered users online right now.
62          * (Unregistered means before USER/NICK/dns)
63          */
64         unsigned int unregistered_count;
65
66         /** Number of elements in local_users
67          */
68         unsigned int local_count;
69
70         /** Map of global ip addresses for clone counting
71          * XXX - this should be private, but m_clones depends on it currently.
72          */
73         clonemap global_clones;
74
75         /**
76          * Reset the already_sent IDs so we don't wrap it around and drop a message
77          * Also removes all expired invites
78      */
79         void GarbageCollect();
80
81         /** Perform background user events such as PING checks
82          */
83         void DoBackgroundUserStuff();
84
85         /** Returns true when all modules have done pre-registration checks on a user
86          * @param user The user to verify
87          * @return True if all modules have finished checking this user
88          */
89         bool AllModulesReportReady(LocalUser* user);
90
91         /** Add a client to the system.
92          * This will create a new User, insert it into the user_hash,
93          * initialize it as not yet registered, and add it to the socket engine.
94          * @param socket The socket id (file descriptor) this user is on
95          * @param via The socket that this user connected using
96          * @param client The IP address and client port of the user
97          * @param server The server IP address and port used by the user
98          * @return This function has no return value, but a call to AddClient may remove the user.
99          */
100         void AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
101
102         /** Disconnect a user gracefully
103          * @param user The user to remove
104          * @param quitreason The quit reason to show to normal users
105          * @param operreason The quit reason to show to opers
106          * @return Although this function has no return type, on exit the user provided will no longer exist.
107          */
108         void QuitUser(User *user, const std::string &quitreason, const char* operreason = "");
109
110         /** Add a user to the local clone map
111          * @param user The user to add
112          */
113         void AddLocalClone(User *user);
114
115         /** Add a user to the global clone map
116          * @param user The user to add
117          */
118         void AddGlobalClone(User *user);
119
120         /** Remove all clone counts from the user, you should
121          * use this if you change the user's IP address
122          * after they have registered.
123          * @param user The user to remove
124          */
125         void RemoveCloneCounts(User *user);
126
127         /** Return the number of global clones of this user
128          * @param user The user to get a count for
129          * @return The global clone count of this user
130          */
131         unsigned long GlobalCloneCount(User *user);
132
133         /** Return the number of local clones of this user
134          * @param user The user to get a count for
135          * @return The local clone count of this user
136          */
137         unsigned long LocalCloneCount(User *user);
138
139         /** Return a count of all global users, unknown and known connections
140          * @return The number of users on the network, including local unregistered users
141          */
142         unsigned int UserCount() const { return this->clientlist->size(); }
143
144         /** Return a count of fully registered connections on the network
145          * @return The number of registered users on the network
146          */
147         unsigned int RegisteredUserCount() { return this->clientlist->size() - this->UnregisteredUserCount(); }
148
149         /** Return a count of opered (umode +o) users on the network
150          * @return The number of opers on the network
151          */
152         unsigned int OperCount() const { return this->all_opers.size(); }
153
154         /** Return a count of local unregistered (before NICK/USER) users
155          * @return The number of local unregistered (unknown) connections
156          */
157         unsigned int UnregisteredUserCount() const { return this->unregistered_count; }
158
159         /** Return a count of local registered users
160          * @return The number of registered local users
161          */
162         unsigned int LocalUserCount() const { return (this->local_count - this->UnregisteredUserCount()); }
163
164         /** Send a server notice to all local users
165          * @param text The text format string to send
166          * @param ... The format arguments
167          */
168         void ServerNoticeAll(const char* text, ...) CUSTOM_PRINTF(2, 3);
169 };