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