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/>.
26 /* Forward ref for typedefs */
31 /** Everything known about one nick
33 struct Nick : public intrusive_list_node<Nick>
35 /** A group of users related by nickname
37 typedef std::deque<WhoWasGroup*> List;
39 /** Container where each element has information about one occurrence of this nick
43 /** Time this nick was added to the database
47 /** Nickname whose information is stored in this class
49 const std::string nick;
51 /** Constructor to initialize fields
53 Nick(const std::string& nickname);
55 /** Destructor, deallocates all elements in the entries container
65 /** Number of currently existing WhoWasGroup objects
70 /** Add a user to the whowas database. Called when a user quits.
71 * @param user The user to add to the database
75 /** Retrieves statistics about the whowas database
76 * @return Whowas statistics as a WhoWas::Manager::Stats struct
78 Stats GetStats() const;
80 /** Expires old entries
84 /** Updates the current configuration which may result in the database being pruned if the
85 * new values are lower than the current ones.
86 * @param NewGroupSize Maximum number of nicks allowed in the database. In case there are this many nicks
87 * in the database and one more is added, the oldest one is removed (FIFO).
88 * @param NewMaxGroups Maximum number of entries per nick
89 * @param NewMaxKeep Seconds how long each nick should be kept
91 void UpdateConfig(unsigned int NewGroupSize, unsigned int NewMaxGroups, unsigned int NewMaxKeep);
93 /** Retrieves all data known about a given nick
94 * @param nick Nickname to find, case insensitive (IRC casemapping)
95 * @return A pointer to a WhoWas::Nick if the nick was found, NULL otherwise
97 const Nick* FindNick(const std::string& nick) const;
99 /** Returns true if WHOWAS is enabled according to the current configuration
100 * @return True if WHOWAS is enabled according to the configuration, false if WHOWAS is disabled
102 bool IsEnabled() const;
113 /** Order in which the users were added into the map, used to remove oldest nick
115 typedef intrusive_list_tail<Nick> FIFO;
117 /** Sets of users in the whowas system
119 typedef TR1NS::unordered_map<std::string, WhoWas::Nick*, irc::insensitive, irc::StrHashComp> whowas_users;
121 /** Primary container, links nicknames tracked by WHOWAS to a list of records
125 /** List of nicknames in the order they were inserted into the map
129 /** Max number of WhoWas entries per user.
131 unsigned int GroupSize;
133 /** Max number of cumulative user-entries in WhoWas.
134 * When max reached and added to, push out oldest entry FIFO style.
136 unsigned int MaxGroups;
138 /** Max seconds a user is kept in WhoWas before being pruned.
140 unsigned int MaxKeep;
142 /** Shrink all data structures to honor the current settings
148 /** Handle /WHOWAS. These command handlers can be reloaded by the core,
149 * and handle basic RFC1459 commands. Commands within modules work
150 * the same way, however, they can be fully unloaded, where these
153 class CommandWhowas : public Command
156 /** Manager handling all whowas database related tasks
158 WhoWas::Manager manager;
160 CommandWhowas(Module* parent);
162 * @param parameters The parameters to the comamnd
163 * @param pcnt The number of parameters passed to teh command
164 * @param user The user issuing the command
165 * @return A value from CmdResult to indicate command success or failure.
167 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
170 /** Used to hold WHOWAS information
194 /** Initialize this WhoWasFroup with a user
196 WhoWasGroup(User* user);