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