2012-04-19 20:58:29 +02:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
2008-01-13 02:59:06 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
|
2008-01-13 02:59:06 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This file is part of InspIRCd. InspIRCd is free software: you can
|
|
|
|
* redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.
|
2008-01-13 02:59:06 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-01-13 02:59:06 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-19 20:58:29 +02:00
|
|
|
|
2013-04-02 20:12:15 +01:00
|
|
|
#pragma once
|
2008-01-13 02:59:06 +00:00
|
|
|
|
2008-02-02 20:55:16 +00:00
|
|
|
#include <list>
|
|
|
|
|
2008-01-13 03:37:25 +00:00
|
|
|
/** A list of ip addresses cross referenced against clone counts */
|
2009-10-24 20:04:05 +00:00
|
|
|
typedef std::map<irc::sockets::cidr_mask, unsigned int> clonemap;
|
2008-01-13 03:37:25 +00:00
|
|
|
|
2009-10-18 16:18:44 +00:00
|
|
|
class CoreExport UserManager
|
2008-01-13 02:59:06 +00:00
|
|
|
{
|
|
|
|
private:
|
2008-01-13 03:37:25 +00:00
|
|
|
/** Map of local ip addresses for clone counting
|
|
|
|
*/
|
|
|
|
clonemap local_clones;
|
2013-06-06 03:15:50 +02:00
|
|
|
|
2008-01-13 02:59:06 +00:00
|
|
|
public:
|
2013-06-06 03:15:50 +02:00
|
|
|
/** Constructor, initializes variables and allocates the hashmaps
|
|
|
|
*/
|
2013-05-18 16:03:17 +02:00
|
|
|
UserManager();
|
|
|
|
|
2013-06-06 03:15:50 +02:00
|
|
|
/** Destructor, destroys all users in clientlist and then deallocates
|
|
|
|
* the hashmaps
|
|
|
|
*/
|
|
|
|
~UserManager();
|
2008-02-02 20:55:16 +00:00
|
|
|
|
|
|
|
/** Client list, a hash_map containing all clients, local and remote
|
|
|
|
*/
|
|
|
|
user_hash* clientlist;
|
|
|
|
|
|
|
|
/** Client list stored by UUID. Contains all clients, and is updated
|
|
|
|
* automatically by the constructor and destructor of User.
|
|
|
|
*/
|
2014-03-14 13:04:10 +01:00
|
|
|
user_hash uuidlist;
|
2008-02-02 20:55:16 +00:00
|
|
|
|
2012-11-21 00:53:57 +01:00
|
|
|
/** Local client list, a list containing only local clients
|
2008-02-02 20:55:16 +00:00
|
|
|
*/
|
2012-11-21 00:15:13 +01:00
|
|
|
LocalUserList local_users;
|
2008-02-02 20:55:16 +00:00
|
|
|
|
|
|
|
/** Oper list, a vector containing all local and remote opered users
|
|
|
|
*/
|
|
|
|
std::list<User*> all_opers;
|
|
|
|
|
|
|
|
/** Number of unregistered users online right now.
|
|
|
|
* (Unregistered means before USER/NICK/dns)
|
|
|
|
*/
|
2013-05-16 20:51:12 +02:00
|
|
|
unsigned int unregistered_count;
|
|
|
|
|
2008-01-13 03:37:25 +00:00
|
|
|
/** Map of global ip addresses for clone counting
|
|
|
|
* XXX - this should be private, but m_clones depends on it currently.
|
|
|
|
*/
|
|
|
|
clonemap global_clones;
|
|
|
|
|
2013-04-04 19:23:16 +02:00
|
|
|
/**
|
|
|
|
* Reset the already_sent IDs so we don't wrap it around and drop a message
|
|
|
|
* Also removes all expired invites
|
|
|
|
*/
|
|
|
|
void GarbageCollect();
|
|
|
|
|
2013-06-06 03:13:55 +02:00
|
|
|
/** Perform background user events such as PING checks
|
|
|
|
*/
|
|
|
|
void DoBackgroundUserStuff();
|
|
|
|
|
|
|
|
/** Returns true when all modules have done pre-registration checks on a user
|
|
|
|
* @param user The user to verify
|
|
|
|
* @return True if all modules have finished checking this user
|
|
|
|
*/
|
|
|
|
bool AllModulesReportReady(LocalUser* user);
|
|
|
|
|
2008-01-13 03:51:04 +00:00
|
|
|
/** Add a client to the system.
|
|
|
|
* This will create a new User, insert it into the user_hash,
|
|
|
|
* initialize it as not yet registered, and add it to the socket engine.
|
|
|
|
* @param socket The socket id (file descriptor) this user is on
|
2009-09-02 00:48:23 +00:00
|
|
|
* @param via The socket that this user connected using
|
2009-09-01 15:07:36 +00:00
|
|
|
* @param client The IP address and client port of the user
|
|
|
|
* @param server The server IP address and port used by the user
|
2008-01-13 03:51:04 +00:00
|
|
|
* @return This function has no return value, but a call to AddClient may remove the user.
|
|
|
|
*/
|
2009-10-21 23:46:33 +00:00
|
|
|
void AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
|
2008-01-13 03:51:04 +00:00
|
|
|
|
2008-04-09 15:34:54 +00:00
|
|
|
/** Disconnect a user gracefully
|
2009-09-02 00:48:02 +00:00
|
|
|
* @param user The user to remove
|
2012-07-05 21:00:35 +01:00
|
|
|
* @param quitreason The quit reason to show to normal users
|
2014-01-05 14:17:12 +01:00
|
|
|
* @param operreason The quit reason to show to opers, can be NULL if same as quitreason
|
2009-09-02 00:48:02 +00:00
|
|
|
* @return Although this function has no return type, on exit the user provided will no longer exist.
|
2008-04-09 15:34:54 +00:00
|
|
|
*/
|
2014-01-05 14:17:12 +01:00
|
|
|
void QuitUser(User* user, const std::string& quitreason, const std::string* operreason = NULL);
|
2008-04-09 15:34:54 +00:00
|
|
|
|
2008-01-13 03:37:25 +00:00
|
|
|
/** Add a user to the local clone map
|
|
|
|
* @param user The user to add
|
|
|
|
*/
|
|
|
|
void AddLocalClone(User *user);
|
|
|
|
|
|
|
|
/** Add a user to the global clone map
|
|
|
|
* @param user The user to add
|
|
|
|
*/
|
|
|
|
void AddGlobalClone(User *user);
|
|
|
|
|
|
|
|
/** Remove all clone counts from the user, you should
|
2009-02-14 21:14:36 +00:00
|
|
|
* use this if you change the user's IP address
|
2008-01-13 03:37:25 +00:00
|
|
|
* after they have registered.
|
|
|
|
* @param user The user to remove
|
|
|
|
*/
|
|
|
|
void RemoveCloneCounts(User *user);
|
|
|
|
|
|
|
|
/** Return the number of global clones of this user
|
|
|
|
* @param user The user to get a count for
|
|
|
|
* @return The global clone count of this user
|
|
|
|
*/
|
|
|
|
unsigned long GlobalCloneCount(User *user);
|
|
|
|
|
|
|
|
/** Return the number of local clones of this user
|
|
|
|
* @param user The user to get a count for
|
|
|
|
* @return The local clone count of this user
|
|
|
|
*/
|
|
|
|
unsigned long LocalCloneCount(User *user);
|
|
|
|
|
2013-06-06 03:15:50 +02:00
|
|
|
/** Return a count of all global users, unknown and known connections
|
|
|
|
* @return The number of users on the network, including local unregistered users
|
2008-01-17 12:17:09 +00:00
|
|
|
*/
|
2013-06-06 03:15:50 +02:00
|
|
|
unsigned int UserCount() const { return this->clientlist->size(); }
|
2008-01-17 12:17:09 +00:00
|
|
|
|
2013-06-06 03:15:50 +02:00
|
|
|
/** Return a count of fully registered connections on the network
|
|
|
|
* @return The number of registered users on the network
|
2008-01-17 12:17:09 +00:00
|
|
|
*/
|
2013-06-06 03:15:50 +02:00
|
|
|
unsigned int RegisteredUserCount() { return this->clientlist->size() - this->UnregisteredUserCount(); }
|
2008-01-13 03:37:25 +00:00
|
|
|
|
2013-06-06 03:15:50 +02:00
|
|
|
/** Return a count of opered (umode +o) users on the network
|
|
|
|
* @return The number of opers on the network
|
2008-01-17 12:17:09 +00:00
|
|
|
*/
|
2013-06-06 03:15:50 +02:00
|
|
|
unsigned int OperCount() const { return this->all_opers.size(); }
|
2008-01-13 03:37:25 +00:00
|
|
|
|
2013-06-06 03:15:50 +02:00
|
|
|
/** Return a count of local unregistered (before NICK/USER) users
|
|
|
|
* @return The number of local unregistered (unknown) connections
|
2008-01-17 12:17:09 +00:00
|
|
|
*/
|
2013-06-06 03:15:50 +02:00
|
|
|
unsigned int UnregisteredUserCount() const { return this->unregistered_count; }
|
2008-01-13 03:37:25 +00:00
|
|
|
|
2013-06-06 03:15:50 +02:00
|
|
|
/** Return a count of local registered users
|
|
|
|
* @return The number of registered local users
|
2008-01-17 12:17:09 +00:00
|
|
|
*/
|
2014-01-24 13:08:13 +01:00
|
|
|
unsigned int LocalUserCount() const { return (this->local_users.size() - this->UnregisteredUserCount()); }
|
2008-02-02 20:55:16 +00:00
|
|
|
|
2014-03-15 15:21:18 +01:00
|
|
|
/** Get a hash map containing all users, keyed by their nickname
|
|
|
|
* @return A hash map mapping nicknames to User pointers
|
|
|
|
*/
|
|
|
|
user_hash& GetUsers() { return *clientlist; }
|
|
|
|
|
2008-02-02 20:55:16 +00:00
|
|
|
/** Send a server notice to all local users
|
|
|
|
* @param text The text format string to send
|
|
|
|
* @param ... The format arguments
|
|
|
|
*/
|
2008-03-30 02:48:54 +00:00
|
|
|
void ServerNoticeAll(const char* text, ...) CUSTOM_PRINTF(2, 3);
|
2008-01-13 02:59:06 +00:00
|
|
|
};
|