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 /** A list of ip addresses cross referenced against clone counts */
25 typedef std::map<irc::sockets::cidr_mask, unsigned int> clonemap;
27 class CoreExport UserManager
30 /** Map of local ip addresses for clone counting
32 clonemap local_clones;
35 /** Constructor, initializes variables and allocates the hashmaps
39 /** Destructor, destroys all users in clientlist and then deallocates
44 /** Client list, a hash_map containing all clients, local and remote
46 user_hash* clientlist;
48 /** Client list stored by UUID. Contains all clients, and is updated
49 * automatically by the constructor and destructor of User.
53 /** Local client list, a list containing only local clients
55 LocalUserList local_users;
57 /** Oper list, a vector containing all local and remote opered users
59 std::list<User*> all_opers;
61 /** Number of unregistered users online right now.
62 * (Unregistered means before USER/NICK/dns)
64 unsigned int unregistered_count;
66 /** Map of global ip addresses for clone counting
67 * XXX - this should be private, but m_clones depends on it currently.
69 clonemap global_clones;
72 * Reset the already_sent IDs so we don't wrap it around and drop a message
73 * Also removes all expired invites
75 void GarbageCollect();
77 /** Perform background user events such as PING checks
79 void DoBackgroundUserStuff();
81 /** Returns true when all modules have done pre-registration checks on a user
82 * @param user The user to verify
83 * @return True if all modules have finished checking this user
85 bool AllModulesReportReady(LocalUser* user);
87 /** Add a client to the system.
88 * This will create a new User, insert it into the user_hash,
89 * initialize it as not yet registered, and add it to the socket engine.
90 * @param socket The socket id (file descriptor) this user is on
91 * @param via The socket that this user connected using
92 * @param client The IP address and client port of the user
93 * @param server The server IP address and port used by the user
94 * @return This function has no return value, but a call to AddClient may remove the user.
96 void AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
98 /** Disconnect a user gracefully
99 * @param user The user to remove
100 * @param quitreason The quit reason to show to normal users
101 * @param operreason The quit reason to show to opers, can be NULL if same as quitreason
102 * @return Although this function has no return type, on exit the user provided will no longer exist.
104 void QuitUser(User* user, const std::string& quitreason, const std::string* operreason = NULL);
106 /** Add a user to the local clone map
107 * @param user The user to add
109 void AddLocalClone(User *user);
111 /** Add a user to the global clone map
112 * @param user The user to add
114 void AddGlobalClone(User *user);
116 /** Remove all clone counts from the user, you should
117 * use this if you change the user's IP address
118 * after they have registered.
119 * @param user The user to remove
121 void RemoveCloneCounts(User *user);
123 /** Return the number of global clones of this user
124 * @param user The user to get a count for
125 * @return The global clone count of this user
127 unsigned long GlobalCloneCount(User *user);
129 /** Return the number of local clones of this user
130 * @param user The user to get a count for
131 * @return The local clone count of this user
133 unsigned long LocalCloneCount(User *user);
135 /** Return a count of all global users, unknown and known connections
136 * @return The number of users on the network, including local unregistered users
138 unsigned int UserCount() const { return this->clientlist->size(); }
140 /** Return a count of fully registered connections on the network
141 * @return The number of registered users on the network
143 unsigned int RegisteredUserCount() { return this->clientlist->size() - this->UnregisteredUserCount(); }
145 /** Return a count of opered (umode +o) users on the network
146 * @return The number of opers on the network
148 unsigned int OperCount() const { return this->all_opers.size(); }
150 /** Return a count of local unregistered (before NICK/USER) users
151 * @return The number of local unregistered (unknown) connections
153 unsigned int UnregisteredUserCount() const { return this->unregistered_count; }
155 /** Return a count of local registered users
156 * @return The number of registered local users
158 unsigned int LocalUserCount() const { return (this->local_users.size() - this->UnregisteredUserCount()); }
160 /** Send a server notice to all local users
161 * @param text The text format string to send
162 * @param ... The format arguments
164 void ServerNoticeAll(const char* text, ...) CUSTOM_PRINTF(2, 3);