]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/commands/cmd_whowas.h
Merge insp20
[user/henk/code/inspircd.git] / include / commands / cmd_whowas.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
7  *
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.
11  *
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
15  * details.
16  *
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/>.
19  */
20
21
22 #pragma once
23
24 #include "modules.h"
25
26 /* Forward ref for typedefs */
27 class WhoWasGroup;
28
29 /** A group of users related by nickname
30  */
31 typedef std::deque<WhoWasGroup*> whowas_set;
32
33 /** Sets of users in the whowas system
34  */
35 typedef std::map<irc::string,whowas_set*> whowas_users;
36
37 /** Sets of time and users in whowas list
38  */
39 typedef std::deque<std::pair<time_t,irc::string> > whowas_users_fifo;
40
41 /** Handle /WHOWAS. These command handlers can be reloaded by the core,
42  * and handle basic RFC1459 commands. Commands within modules work
43  * the same way, however, they can be fully unloaded, where these
44  * may not.
45  */
46 class CommandWhowas : public Command
47 {
48   private:
49         /** Primary container, links nicknames tracked by WHOWAS to a list of records
50          */
51         whowas_users whowas;
52
53         /** List of nicknames in the order they were inserted into the map
54          */
55         whowas_users_fifo whowas_fifo;
56
57   public:
58         /** Max number of WhoWas entries per user.
59          */
60         unsigned int GroupSize;
61
62         /** Max number of cumulative user-entries in WhoWas.
63          *  When max reached and added to, push out oldest entry FIFO style.
64          */
65         unsigned int MaxGroups;
66
67         /** Max seconds a user is kept in WhoWas before being pruned.
68          */
69         unsigned int MaxKeep;
70
71         CommandWhowas(Module* parent);
72         /** Handle command.
73          * @param parameters The parameters to the comamnd
74          * @param pcnt The number of parameters passed to teh command
75          * @param user The user issuing the command
76          * @return A value from CmdResult to indicate command success or failure.
77          */
78         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
79         void AddToWhoWas(User* user);
80         std::string GetStats();
81         void Prune();
82         void Maintain();
83         ~CommandWhowas();
84 };
85
86 /** Used to hold WHOWAS information
87  */
88 class WhoWasGroup
89 {
90  public:
91         /** Real host
92          */
93         std::string host;
94         /** Displayed host
95          */
96         std::string dhost;
97         /** Ident
98          */
99         std::string ident;
100         /** Server name
101          */
102         std::string server;
103         /** Fullname (GECOS)
104          */
105         std::string gecos;
106         /** Signon time
107          */
108         time_t signon;
109
110         /** Initialize this WhoWasFroup with a user
111          */
112         WhoWasGroup(User* user);
113 };