]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/commands/cmd_whowas.h
core_whowas Store the nickname in WhoWas::Nick
[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 namespace WhoWas
34 {
35         /** Everything known about one nick
36          */
37         struct Nick
38         {
39                 /** Container where each element has information about one occurrence of this nick
40                  */
41                 whowas_set entries;
42
43                 /** Time this nick was added to the database
44                  */
45                 const time_t addtime;
46
47                 /** Nickname whose information is stored in this class
48                  */
49                 const irc::string nick;
50
51                 /** Constructor to initialize fields
52                  */
53                 Nick(const irc::string& nickname);
54
55                 /** Destructor, deallocates all elements in the entries container
56                  */
57                 ~Nick();
58         };
59 }
60
61 /** Sets of users in the whowas system
62  */
63 typedef std::map<irc::string, WhoWas::Nick*> whowas_users;
64
65 /** Sets of time and users in whowas list
66  */
67 typedef std::deque<std::pair<time_t,irc::string> > whowas_users_fifo;
68
69 /** Handle /WHOWAS. These command handlers can be reloaded by the core,
70  * and handle basic RFC1459 commands. Commands within modules work
71  * the same way, however, they can be fully unloaded, where these
72  * may not.
73  */
74 class CommandWhowas : public Command
75 {
76   private:
77         /** Primary container, links nicknames tracked by WHOWAS to a list of records
78          */
79         whowas_users whowas;
80
81         /** List of nicknames in the order they were inserted into the map
82          */
83         whowas_users_fifo whowas_fifo;
84
85   public:
86         /** Max number of WhoWas entries per user.
87          */
88         unsigned int GroupSize;
89
90         /** Max number of cumulative user-entries in WhoWas.
91          *  When max reached and added to, push out oldest entry FIFO style.
92          */
93         unsigned int MaxGroups;
94
95         /** Max seconds a user is kept in WhoWas before being pruned.
96          */
97         unsigned int MaxKeep;
98
99         CommandWhowas(Module* parent);
100         /** Handle command.
101          * @param parameters The parameters to the comamnd
102          * @param pcnt The number of parameters passed to teh command
103          * @param user The user issuing the command
104          * @return A value from CmdResult to indicate command success or failure.
105          */
106         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
107         void AddToWhoWas(User* user);
108         std::string GetStats();
109         void Prune();
110         void Maintain();
111         ~CommandWhowas();
112 };
113
114 /** Used to hold WHOWAS information
115  */
116 class WhoWasGroup
117 {
118  public:
119         /** Real host
120          */
121         std::string host;
122         /** Displayed host
123          */
124         std::string dhost;
125         /** Ident
126          */
127         std::string ident;
128         /** Server name
129          */
130         std::string server;
131         /** Fullname (GECOS)
132          */
133         std::string gecos;
134         /** Signon time
135          */
136         time_t signon;
137
138         /** Initialize this WhoWasFroup with a user
139          */
140         WhoWasGroup(User* user);
141 };