2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 /** One entry for a nick. There may be multiple entries for a nick.
34 const std::string host;
38 const std::string dhost;
42 const std::string ident;
46 const std::string server;
50 const std::string gecos;
56 /** Initialize this Entry with a user
61 /** Everything known about one nick
63 struct Nick : public insp::intrusive_list_node<Nick>
65 /** A group of users related by nickname
67 typedef std::deque<Entry*> List;
69 /** Container where each element has information about one occurrence of this nick
73 /** Time this nick was added to the database
77 /** Nickname whose information is stored in this class
79 const std::string nick;
81 /** Constructor to initialize fields
83 Nick(const std::string& nickname);
85 /** Destructor, deallocates all elements in the entries container
95 /** Number of currently existing WhoWas::Entry objects
100 /** Add a user to the whowas database. Called when a user quits.
101 * @param user The user to add to the database
103 void Add(User* user);
105 /** Retrieves statistics about the whowas database
106 * @return Whowas statistics as a WhoWas::Manager::Stats struct
108 Stats GetStats() const;
110 /** Expires old entries
114 /** Updates the current configuration which may result in the database being pruned if the
115 * new values are lower than the current ones.
116 * @param NewGroupSize Maximum number of nicks allowed in the database. In case there are this many nicks
117 * in the database and one more is added, the oldest one is removed (FIFO).
118 * @param NewMaxGroups Maximum number of entries per nick
119 * @param NewMaxKeep Seconds how long each nick should be kept
121 void UpdateConfig(unsigned int NewGroupSize, unsigned int NewMaxGroups, unsigned int NewMaxKeep);
123 /** Retrieves all data known about a given nick
124 * @param nick Nickname to find, case insensitive (IRC casemapping)
125 * @return A pointer to a WhoWas::Nick if the nick was found, NULL otherwise
127 const Nick* FindNick(const std::string& nick) const;
129 /** Returns true if WHOWAS is enabled according to the current configuration
130 * @return True if WHOWAS is enabled according to the configuration, false if WHOWAS is disabled
132 bool IsEnabled() const;
143 /** Order in which the users were added into the map, used to remove oldest nick
145 typedef insp::intrusive_list_tail<Nick> FIFO;
147 /** Sets of users in the whowas system
149 typedef TR1NS::unordered_map<std::string, WhoWas::Nick*, irc::insensitive, irc::StrHashComp> whowas_users;
151 /** Primary container, links nicknames tracked by WHOWAS to a list of records
155 /** List of nicknames in the order they were inserted into the map
159 /** Max number of WhoWas entries per user.
161 unsigned int GroupSize;
163 /** Max number of cumulative user-entries in WhoWas.
164 * When max reached and added to, push out oldest entry FIFO style.
166 unsigned int MaxGroups;
168 /** Max seconds a user is kept in WhoWas before being pruned.
170 unsigned int MaxKeep;
172 /** Shrink all data structures to honor the current settings
176 /** Remove a nick (and all entries belonging to it) from the database
177 * @param it Iterator to the nick to purge
179 void PurgeNick(whowas_users::iterator it);
181 /** Remove a nick (and all entries belonging to it) from the database
182 * @param nick Nick to purge
184 void PurgeNick(WhoWas::Nick* nick);
188 /** Handle /WHOWAS. These command handlers can be reloaded by the core,
189 * and handle basic RFC1459 commands. Commands within modules work
190 * the same way, however, they can be fully unloaded, where these
193 class CommandWhowas : public Command
196 /** Manager handling all whowas database related tasks
198 WhoWas::Manager manager;
200 CommandWhowas(Module* parent);
202 * @param parameters The parameters to the comamnd
203 * @param user The user issuing the command
204 * @return A value from CmdResult to indicate command success or failure.
206 CmdResult Handle(const std::vector<std::string>& parameters, User *user);