]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/commands/cmd_whowas.h
Replace copyright headers with headers granting specific authors copyright
[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 #ifndef CMD_WHOWAS_H
23 #define CMD_WHOWAS_H
24 #include "modules.h"
25
26 struct WhowasRequest : public Request
27 {
28         /* list of available internal commands */
29         enum Internals
30         {
31                 WHOWAS_ADD = 1,
32                 WHOWAS_STATS = 2,
33                 WHOWAS_PRUNE = 3,
34                 WHOWAS_MAINTAIN = 4
35         };
36
37         const Internals type;
38         std::string value;
39         User* user;
40
41         WhowasRequest(Module* src, Module* whowas, Internals Type) : Request(src, whowas, "WHOWAS"), type(Type)
42         {}
43 };
44
45 /* Forward ref for timer */
46 class WhoWasMaintainTimer;
47
48 /* Forward ref for typedefs */
49 class WhoWasGroup;
50
51 /** Timer that is used to maintain the whowas list, called once an hour
52  */
53 extern WhoWasMaintainTimer* timer;
54
55 /** A group of users related by nickname
56  */
57 typedef std::deque<WhoWasGroup*> whowas_set;
58
59 /** Sets of users in the whowas system
60  */
61 typedef std::map<irc::string,whowas_set*> whowas_users;
62
63 /** Sets of time and users in whowas list
64  */
65 typedef std::deque<std::pair<time_t,irc::string> > whowas_users_fifo;
66
67 /** Handle /WHOWAS. These command handlers can be reloaded by the core,
68  * and handle basic RFC1459 commands. Commands within modules work
69  * the same way, however, they can be fully unloaded, where these
70  * may not.
71  */
72 class CommandWhowas : public Command
73 {
74   private:
75         /** Whowas container, contains a map of vectors of users tracked by WHOWAS
76          */
77         whowas_users whowas;
78
79         /** Whowas container, contains a map of time_t to users tracked by WHOWAS
80          */
81         whowas_users_fifo whowas_fifo;
82
83   public:
84         CommandWhowas(Module* parent);
85         /** Handle command.
86          * @param parameters The parameters to the comamnd
87          * @param pcnt The number of parameters passed to teh command
88          * @param user The user issuing the command
89          * @return A value from CmdResult to indicate command success or failure.
90          */
91         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
92         void AddToWhoWas(User* user);
93         std::string GetStats();
94         void PruneWhoWas(time_t t);
95         void MaintainWhoWas(time_t t);
96         ~CommandWhowas();
97 };
98
99 /** Used to hold WHOWAS information
100  */
101 class WhoWasGroup
102 {
103  public:
104         /** Real host
105          */
106         std::string host;
107         /** Displayed host
108          */
109         std::string dhost;
110         /** Ident
111          */
112         std::string ident;
113         /** Server name
114          */
115         std::string server;
116         /** Fullname (GECOS)
117          */
118         std::string gecos;
119         /** Signon time
120          */
121         time_t signon;
122
123         /** Initialize this WhoWasFroup with a user
124          */
125         WhoWasGroup(User* user);
126         /** Destructor
127          */
128         ~WhoWasGroup();
129 };
130
131 class WhoWasMaintainTimer : public Timer
132 {
133   public:
134         WhoWasMaintainTimer(long interval)
135         : Timer(interval, ServerInstance->Time(), true)
136         {
137         }
138         virtual void Tick(time_t TIME);
139 };
140
141 #endif