2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012, 2014-2015 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
8 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
10 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 /** One entry for a nick. There may be multiple entries for a nick.
38 const std::string host;
42 const std::string dhost;
46 const std::string ident;
50 const std::string server;
54 const std::string real;
60 /** Initialize this Entry with a user
65 /** Everything known about one nick
67 struct Nick : public insp::intrusive_list_node<Nick>
69 /** A group of users related by nickname
71 typedef std::deque<Entry*> List;
73 /** Container where each element has information about one occurrence of this nick
77 /** Time this nick was added to the database
81 /** Nickname whose information is stored in this class
83 const std::string nick;
85 /** Constructor to initialize fields
87 Nick(const std::string& nickname);
89 /** Destructor, deallocates all elements in the entries container
99 /** Number of currently existing WhoWas::Entry objects
104 /** Add a user to the whowas database. Called when a user quits.
105 * @param user The user to add to the database
107 void Add(User* user);
109 /** Retrieves statistics about the whowas database
110 * @return Whowas statistics as a WhoWas::Manager::Stats struct
112 Stats GetStats() const;
114 /** Expires old entries
118 /** Updates the current configuration which may result in the database being pruned if the
119 * new values are lower than the current ones.
120 * @param NewGroupSize Maximum number of nicks allowed in the database. In case there are this many nicks
121 * in the database and one more is added, the oldest one is removed (FIFO).
122 * @param NewMaxGroups Maximum number of entries per nick
123 * @param NewMaxKeep Seconds how long each nick should be kept
125 void UpdateConfig(unsigned int NewGroupSize, unsigned int NewMaxGroups, unsigned int NewMaxKeep);
127 /** Retrieves all data known about a given nick
128 * @param nick Nickname to find, case insensitive (IRC casemapping)
129 * @return A pointer to a WhoWas::Nick if the nick was found, NULL otherwise
131 const Nick* FindNick(const std::string& nick) const;
133 /** Returns true if WHOWAS is enabled according to the current configuration
134 * @return True if WHOWAS is enabled according to the configuration, false if WHOWAS is disabled
136 bool IsEnabled() const;
147 /** Order in which the users were added into the map, used to remove oldest nick
149 typedef insp::intrusive_list_tail<Nick> FIFO;
151 /** Sets of users in the whowas system
153 typedef TR1NS::unordered_map<std::string, WhoWas::Nick*, irc::insensitive, irc::StrHashComp> whowas_users;
155 /** Primary container, links nicknames tracked by WHOWAS to a list of records
159 /** List of nicknames in the order they were inserted into the map
163 /** Max number of WhoWas entries per user.
165 unsigned int GroupSize;
167 /** Max number of cumulative user-entries in WhoWas.
168 * When max reached and added to, push out oldest entry FIFO style.
170 unsigned int MaxGroups;
172 /** Max seconds a user is kept in WhoWas before being pruned.
174 unsigned int MaxKeep;
176 /** Shrink all data structures to honor the current settings
180 /** Remove a nick (and all entries belonging to it) from the database
181 * @param it Iterator to the nick to purge
183 void PurgeNick(whowas_users::iterator it);
185 /** Remove a nick (and all entries belonging to it) from the database
186 * @param nick Nick to purge
188 void PurgeNick(WhoWas::Nick* nick);
192 /** Handle /WHOWAS. These command handlers can be reloaded by the core,
193 * and handle basic RFC1459 commands. Commands within modules work
194 * the same way, however, they can be fully unloaded, where these
197 class CommandWhowas : public Command
200 /** Manager handling all whowas database related tasks
202 WhoWas::Manager manager;
204 CommandWhowas(Module* parent);
206 * @param parameters The parameters to the comamnd
207 * @param user The user issuing the command
208 * @return A value from CmdResult to indicate command success or failure.
210 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;