]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/commands/cmd_whowas.h
Update all wiki links to point to the new wiki. This was done automatically with...
[user/henk/code/inspircd.git] / include / commands / cmd_whowas.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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
17
18 // include the common header files
19
20 #include "users.h"
21 #include "channels.h"
22
23 /* list of available internal commands */
24 enum Internals
25 {
26         WHOWAS_ADD = 1,
27         WHOWAS_STATS = 2,
28         WHOWAS_PRUNE = 3,
29         WHOWAS_MAINTAIN = 4
30 };
31
32 /* Forward ref for timer */
33 class WhoWasMaintainTimer;
34
35 /* Forward ref for typedefs */
36 class WhoWasGroup;
37
38 /** Timer that is used to maintain the whowas list, called once an hour
39  */
40 extern WhoWasMaintainTimer* timer;
41
42 /** A group of users related by nickname
43  */
44 typedef std::deque<WhoWasGroup*> whowas_set;
45
46 /** Sets of users in the whowas system
47  */
48 typedef std::map<irc::string,whowas_set*> whowas_users;
49
50 /** Sets of time and users in whowas list
51  */
52 typedef std::deque<std::pair<time_t,irc::string> > whowas_users_fifo;
53
54 /** Handle /WHOWAS. These command handlers can be reloaded by the core,
55  * and handle basic RFC1459 commands. Commands within modules work
56  * the same way, however, they can be fully unloaded, where these
57  * may not.
58  */
59 class CommandWhowas : public Command
60 {
61   private:
62         /** Whowas container, contains a map of vectors of users tracked by WHOWAS
63          */
64         whowas_users whowas;
65
66         /** Whowas container, contains a map of time_t to users tracked by WHOWAS
67          */
68         whowas_users_fifo whowas_fifo;
69
70         /* String holding stats so it can be collected
71          */
72         std::string stats;
73
74   public:
75         CommandWhowas(InspIRCd* Instance);
76         /** Handle command.
77          * @param parameters The parameters to the comamnd
78          * @param pcnt The number of parameters passed to teh command
79          * @param user The user issuing the command
80          * @return A value from CmdResult to indicate command success or failure.
81          */
82         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
83         /** Handle an internal request from another command, the core, or a module
84          * @param Command ID
85          * @param Zero or more parameters, whos form is specified by the command ID.
86          * @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
87          * If the command succeeds but should remain local to this server,
88          * return CMD_LOCALONLY.
89          */
90         CmdResult HandleInternal(const unsigned int id, const std::deque<classbase*> &parameters);
91         void AddToWhoWas(User* user);
92         void GetStats(Extensible* ext);
93         void PruneWhoWas(time_t t);
94         void MaintainWhoWas(time_t t);
95         virtual ~CommandWhowas();
96 };
97
98 /** Used to hold WHOWAS information
99  */
100 class WhoWasGroup : public classbase
101 {
102  public:
103         /** Real host
104          */
105         char* host;
106         /** Displayed host
107          */
108         char* dhost;
109         /** Ident
110          */
111         char* ident;
112         /** Server name
113          */
114         const char* server;
115         /** Fullname (GECOS)
116          */
117         char* gecos;
118         /** Signon time
119          */
120         time_t signon;
121
122         /** Initialize this WhoQasFroup with a user
123          */
124         WhoWasGroup(User* user);
125         /** Destructor
126          */
127         ~WhoWasGroup();
128 };
129
130 class WhoWasMaintainTimer : public Timer
131 {
132   private:
133         InspIRCd* ServerInstance;
134   public:
135         WhoWasMaintainTimer(InspIRCd* Instance, long interval)
136         : Timer(interval, Instance->Time(), true), ServerInstance(Instance)
137         {
138         }
139         virtual void Tick(time_t TIME);
140 };
141
142 #endif