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