]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/commands/cmd_whowas.h
Don't filter mass-messages sent by server operators.
[user/henk/code/inspircd.git] / include / commands / cmd_whowas.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
11  *
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.
15  *
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
19  * details.
20  *
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/>.
23  */
24
25
26 #pragma once
27
28 #include "modules.h"
29
30 namespace WhoWas
31 {
32         /** One entry for a nick. There may be multiple entries for a nick.
33          */
34         struct Entry
35         {
36                 /** Real host
37                  */
38                 const std::string host;
39
40                 /** Displayed host
41                  */
42                 const std::string dhost;
43
44                 /** Ident
45                  */
46                 const std::string ident;
47
48                 /** Server name
49                  */
50                 const std::string server;
51
52                 /** Real name
53                  */
54                 const std::string real;
55
56                 /** Signon time
57                  */
58                 const time_t signon;
59
60                 /** Initialize this Entry with a user
61                  */
62                 Entry(User* user);
63         };
64
65         /** Everything known about one nick
66          */
67         struct Nick : public insp::intrusive_list_node<Nick>
68         {
69                 /** A group of users related by nickname
70                  */
71                 typedef std::deque<Entry*> List;
72
73                 /** Container where each element has information about one occurrence of this nick
74                  */
75                 List entries;
76
77                 /** Time this nick was added to the database
78                  */
79                 const time_t addtime;
80
81                 /** Nickname whose information is stored in this class
82                  */
83                 const std::string nick;
84
85                 /** Constructor to initialize fields
86                  */
87                 Nick(const std::string& nickname);
88
89                 /** Destructor, deallocates all elements in the entries container
90                  */
91                 ~Nick();
92         };
93
94         class Manager
95         {
96          public:
97                 struct Stats
98                 {
99                         /** Number of currently existing WhoWas::Entry objects
100                          */
101                         size_t entrycount;
102                 };
103
104                 /** Add a user to the whowas database. Called when a user quits.
105                  * @param user The user to add to the database
106                  */
107                 void Add(User* user);
108
109                 /** Retrieves statistics about the whowas database
110                  * @return Whowas statistics as a WhoWas::Manager::Stats struct
111                  */
112                 Stats GetStats() const;
113
114                 /** Expires old entries
115                  */
116                 void Maintain();
117
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
124                  */
125                 void UpdateConfig(unsigned int NewGroupSize, unsigned int NewMaxGroups, unsigned int NewMaxKeep);
126
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
130                  */
131                 const Nick* FindNick(const std::string& nick) const;
132
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
135                  */
136                 bool IsEnabled() const;
137
138                 /** Constructor
139                  */
140                 Manager();
141
142                 /** Destructor
143                  */
144                 ~Manager();
145
146          private:
147                 /** Order in which the users were added into the map, used to remove oldest nick
148                  */
149                 typedef insp::intrusive_list_tail<Nick> FIFO;
150
151                 /** Sets of users in the whowas system
152                  */
153                 typedef TR1NS::unordered_map<std::string, WhoWas::Nick*, irc::insensitive, irc::StrHashComp> whowas_users;
154
155                 /** Primary container, links nicknames tracked by WHOWAS to a list of records
156                  */
157                 whowas_users whowas;
158
159                 /** List of nicknames in the order they were inserted into the map
160                  */
161                 FIFO whowas_fifo;
162
163                 /** Max number of WhoWas entries per user.
164                  */
165                 unsigned int GroupSize;
166
167                 /** Max number of cumulative user-entries in WhoWas.
168                  * When max reached and added to, push out oldest entry FIFO style.
169                  */
170                 unsigned int MaxGroups;
171
172                 /** Max seconds a user is kept in WhoWas before being pruned.
173                  */
174                 unsigned int MaxKeep;
175
176                 /** Shrink all data structures to honor the current settings
177                  */
178                 void Prune();
179
180                 /** Remove a nick (and all entries belonging to it) from the database
181                  * @param it Iterator to the nick to purge
182                  */
183                 void PurgeNick(whowas_users::iterator it);
184
185                 /** Remove a nick (and all entries belonging to it) from the database
186                  * @param nick Nick to purge
187                  */
188                 void PurgeNick(WhoWas::Nick* nick);
189         };
190 }
191
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
195  * may not.
196  */
197 class CommandWhowas : public Command
198 {
199   public:
200         /** Manager handling all whowas database related tasks
201          */
202         WhoWas::Manager manager;
203
204         CommandWhowas(Module* parent);
205         /** Handle command.
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.
209          */
210         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
211 };