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