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