2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
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.
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
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/>.
24 class CoreExport UserManager : public fakederef<UserManager>
31 CloneCounts() : global(0), local(0) { }
34 /** Container that maps IP addresses to clone counts
36 typedef std::map<irc::sockets::cidr_mask, CloneCounts> CloneMap;
38 /** Sequence container in which each element is a User*
40 typedef std::vector<User*> OperList;
42 /** A list holding local users
44 typedef insp::intrusive_list<LocalUser> LocalList;
47 /** Map of IP addresses for clone counting
51 /** A CloneCounts that contains zero for both local and global
53 const CloneCounts zeroclonecounts;
55 /** Local client list, a list containing only local clients
57 LocalList local_users;
59 /** Last used already sent id, used when sending messages to neighbors to help determine whether the message has
60 * been sent to a particular user or not. See User::ForEachNeighbor() for more info.
62 already_sent_t already_sent_id;
65 /** Constructor, initializes variables
69 /** Destructor, destroys all users in clientlist
73 /** Client list, a hash_map containing all clients, local and remote
77 /** Client list stored by UUID. Contains all clients, and is updated
78 * automatically by the constructor and destructor of User.
82 /** Oper list, a vector containing all local and remote opered users
86 /** Number of unregistered users online right now.
87 * (Unregistered means before USER/NICK/dns)
89 unsigned int unregistered_count;
92 * Reset the already_sent IDs so we don't wrap it around and drop a message
94 void GarbageCollect();
96 /** Perform background user events such as PING checks
98 void DoBackgroundUserStuff();
100 /** Returns true when all modules have done pre-registration checks on a user
101 * @param user The user to verify
102 * @return True if all modules have finished checking this user
104 bool AllModulesReportReady(LocalUser* user);
106 /** Add a client to the system.
107 * This will create a new User, insert it into the user_hash,
108 * initialize it as not yet registered, and add it to the socket engine.
109 * @param socket The socket id (file descriptor) this user is on
110 * @param via The socket that this user connected using
111 * @param client The IP address and client port of the user
112 * @param server The server IP address and port used by the user
113 * @return This function has no return value, but a call to AddClient may remove the user.
115 void AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
117 /** Disconnect a user gracefully
118 * @param user The user to remove
119 * @param quitreason The quit reason to show to normal users
120 * @param operreason The quit reason to show to opers, can be NULL if same as quitreason
121 * @return Although this function has no return type, on exit the user provided will no longer exist.
123 void QuitUser(User* user, const std::string& quitreason, const std::string* operreason = NULL);
125 /** Add a user to the clone map
126 * @param user The user to add
128 void AddClone(User* user);
130 /** Remove all clone counts from the user, you should
131 * use this if you change the user's IP address
132 * after they have registered.
133 * @param user The user to remove
135 void RemoveCloneCounts(User *user);
137 /** Rebuild clone counts
139 void RehashCloneCounts();
141 /** Return the number of local and global clones of this user
142 * @param user The user to get the clone counts for
143 * @return The clone counts of this user. The returned reference is volatile - you
144 * must assume that it becomes invalid as soon as you call any function other than
147 const CloneCounts& GetCloneCounts(User* user) const;
149 /** Return a map containg IP addresses and their clone counts
150 * @return The clone count map
152 const CloneMap& GetCloneMap() const { return clonemap; }
154 /** Return a count of all global users, unknown and known connections
155 * @return The number of users on the network, including local unregistered users
157 unsigned int UserCount() const { return this->clientlist.size(); }
159 /** Return a count of fully registered connections on the network
160 * @return The number of registered users on the network
162 unsigned int RegisteredUserCount() { return this->clientlist.size() - this->UnregisteredUserCount(); }
164 /** Return a count of opered (umode +o) users on the network
165 * @return The number of opers on the network
167 unsigned int OperCount() const { return this->all_opers.size(); }
169 /** Return a count of local unregistered (before NICK/USER) users
170 * @return The number of local unregistered (unknown) connections
172 unsigned int UnregisteredUserCount() const { return this->unregistered_count; }
174 /** Return a count of local registered users
175 * @return The number of registered local users
177 unsigned int LocalUserCount() const { return (this->local_users.size() - this->UnregisteredUserCount()); }
179 /** Get a hash map containing all users, keyed by their nickname
180 * @return A hash map mapping nicknames to User pointers
182 user_hash& GetUsers() { return clientlist; }
184 /** Get a list containing all local users
185 * @return A const list of local users
187 const LocalList& GetLocalUsers() const { return local_users; }
189 /** Send a server notice to all local users
190 * @param text The text format string to send
191 * @param ... The format arguments
193 void ServerNoticeAll(const char* text, ...) CUSTOM_PRINTF(2, 3);
195 /** Retrieves the next already sent id, guaranteed to be not equal to any user's already_sent field
196 * @return Next already_sent id
198 already_sent_t NextAlreadySentId();