]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/usermanager.h
Update copyright headers.
[user/henk/code/inspircd.git] / include / usermanager.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2015 Adam <Adam@anope.org>
5  *   Copyright (C) 2013-2016 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012-2013, 2017, 2019 Sadie Powell <sadie@witchery.services>
7  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
9  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
11  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
12  *
13  * This file is part of InspIRCd.  InspIRCd is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation, version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26
27 #pragma once
28
29 #include <list>
30
31 class CoreExport UserManager : public fakederef<UserManager>
32 {
33  public:
34         struct CloneCounts
35         {
36                 unsigned int global;
37                 unsigned int local;
38                 CloneCounts() : global(0), local(0) { }
39         };
40
41         /** Container that maps IP addresses to clone counts
42          */
43         typedef std::map<irc::sockets::cidr_mask, CloneCounts> CloneMap;
44
45         /** Sequence container in which each element is a User*
46          */
47         typedef std::vector<User*> OperList;
48
49         /** A list holding local users
50         */
51         typedef insp::intrusive_list<LocalUser> LocalList;
52
53  private:
54         /** Map of IP addresses for clone counting
55          */
56         CloneMap clonemap;
57
58         /** A CloneCounts that contains zero for both local and global
59          */
60         const CloneCounts zeroclonecounts;
61
62         /** Local client list, a list containing only local clients
63          */
64         LocalList local_users;
65
66         /** Last used already sent id, used when sending messages to neighbors to help determine whether the message has
67          * been sent to a particular user or not. See User::ForEachNeighbor() for more info.
68          */
69         already_sent_t already_sent_id;
70
71  public:
72         /** Constructor, initializes variables
73          */
74         UserManager();
75
76         /** Destructor, destroys all users in clientlist
77          */
78         ~UserManager();
79
80         /** Nickname string -> User* map. Contains all users, including unregistered ones.
81          */
82         user_hash clientlist;
83
84         /** UUID -> User* map. Contains all users, including unregistered ones.
85          */
86         user_hash uuidlist;
87
88         /** Oper list, a vector containing all local and remote opered users
89          */
90         OperList all_opers;
91
92         /** Number of unregistered users online right now.
93          * (Unregistered means before USER/NICK/dns)
94          */
95         unsigned int unregistered_count;
96
97         /** The number of users on U-lined servers. */
98         unsigned int uline_count;
99
100         /** Perform background user events for all local users such as PING checks, registration timeouts,
101          * penalty management and recvq processing for users who have data in their recvq due to throttling.
102          */
103         void DoBackgroundUserStuff();
104
105         /** Handle a client connection.
106          * Creates a new LocalUser object, inserts it into the appropriate containers,
107          * initializes it as not yet registered, and adds it to the socket engine.
108          *
109          * The new user may immediately be quit after being created, for example if the user limit
110          * is reached or if the user is banned.
111          * @param socket File descriptor of the connection
112          * @param via Listener socket that this user connected to
113          * @param client The IP address and client port of the user
114          * @param server The server IP address and port used by the user
115          */
116         void AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
117
118         /** Disconnect a user gracefully.
119          * When this method returns the user provided will be quit, but the User object will continue to be valid and will be deleted at the end of the current main loop iteration.
120          * @param user The user to remove
121          * @param quitreason The quit reason to show to normal users
122          * @param operreason The quit reason to show to opers, can be NULL if same as quitreason
123          */
124         void QuitUser(User* user, const std::string& quitreason, const std::string* operreason = NULL);
125
126         /** Add a user to the clone map
127          * @param user The user to add
128          */
129         void AddClone(User* user);
130
131         /** Remove all clone counts from the user, you should
132          * use this if you change the user's IP address
133          * after they have registered.
134          * @param user The user to remove
135          */
136         void RemoveCloneCounts(User *user);
137
138         /** Rebuild clone counts. Required when \<cidr> settings change.
139          */
140         void RehashCloneCounts();
141
142         /** Return the number of local and global clones of this user
143          * @param user The user to get the clone counts for
144          * @return The clone counts of this user. The returned reference is volatile - you
145          * must assume that it becomes invalid as soon as you call any function other than
146          * your own.
147          */
148         const CloneCounts& GetCloneCounts(User* user) const;
149
150         /** Return a map containg IP addresses and their clone counts
151          * @return The clone count map
152          */
153         const CloneMap& GetCloneMap() const { return clonemap; }
154
155         /** Return a count of all global users, unknown and known connections
156          * @return The number of users on the network, including local unregistered users
157          */
158         unsigned int UserCount() const { return this->clientlist.size(); }
159
160         /** Return a count of fully registered connections on the network
161          * @return The number of registered users on the network
162          */
163         unsigned int RegisteredUserCount() { return this->clientlist.size() - this->UnregisteredUserCount() - this->ULineCount(); }
164
165         /** Return a count of opered (umode +o) users on the network
166          * @return The number of opers on the network
167          */
168         unsigned int OperCount() const { return this->all_opers.size(); }
169
170         /** Return a count of local unregistered (before NICK/USER) users
171          * @return The number of local unregistered (unknown) connections
172          */
173         unsigned int UnregisteredUserCount() const { return this->unregistered_count; }
174
175         /** Return a count of users on a u-lined servers.
176          * @return The number of users on u-lined servers.
177          */
178         unsigned int ULineCount() const { return this->uline_count; }
179
180         /** Return a count of local registered users
181          * @return The number of registered local users
182          */
183         unsigned int LocalUserCount() const { return (this->local_users.size() - this->UnregisteredUserCount()); }
184
185         /** Get a hash map containing all users, keyed by their nickname
186          * @return A hash map mapping nicknames to User pointers
187          */
188         user_hash& GetUsers() { return clientlist; }
189
190         /** Get a list containing all local users
191          * @return A const list of local users
192          */
193         const LocalList& GetLocalUsers() const { return local_users; }
194
195         /** Send a server notice to all local users
196          * @param text The text format string to send
197          * @param ... The format arguments
198          */
199         void ServerNoticeAll(const char* text, ...) CUSTOM_PRINTF(2, 3);
200
201         /** Retrieves the next already sent id, guaranteed to be not equal to any user's already_sent field
202          * @return Next already_sent id
203          */
204         already_sent_t NextAlreadySentId();
205 };