]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_check.cpp
0b93e0288fbebe2daa8ebd8825d1a16411c4c1cd
[user/henk/code/inspircd.git] / src / modules / m_check.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 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 using namespace std;
18
19 #include "users.h"
20 #include "channels.h"
21 #include "modules.h"
22 #include "message.h"
23 #include "commands.h"
24 #include "inspircd.h"
25 #include "helperfuncs.h"
26
27 /* $ModDesc: Provides the /check command to retrieve information on a user, channel, or IP address */
28
29 static Server *Srv;
30
31 class cmd_check : public command_t
32 {
33  public:
34         cmd_check() : command_t("CHECK", 'o', 1)
35         {
36                 this->source = "m_check.so";
37         }
38
39         void Handle (char **parameters, int pcnt, userrec *user)
40         {
41                 userrec *targuser;
42                 chanrec *targchan;
43                 std::string checkstr;
44                 std::string chliststr;
45
46                 char timebuf[60];
47                 struct tm *mytime;
48
49
50                 checkstr = "304 " + std::string(user->nick) + " :CHECK";
51
52                 targuser = Srv->FindNick(std::string(parameters[0]));
53                 targchan = Srv->FindChannel(std::string(parameters[0]));
54
55                 /*
56                  * Syntax of a /check reply:
57                  *  :server.name 304 target :CHECK START <target>
58                  *  :server.name 304 target :CHECK <field> <value>
59                  *  :server.name 304 target :CHECK END
60                  */
61
62                 Srv->SendTo(NULL, user, checkstr + " START " + parameters[0]);
63
64                 if (targuser)
65                 {
66                         /* /check on a user */
67                         Srv->SendTo(NULL, user, checkstr + " nuh " + targuser->GetFullHost());
68                         Srv->SendTo(NULL, user, checkstr + " realnuh " + targuser->GetFullRealHost());
69                         Srv->SendTo(NULL, user, checkstr + " realname " + targuser->fullname);
70                         Srv->SendTo(NULL, user, checkstr + " modes +" + targuser->modes);
71                         Srv->SendTo(NULL, user, checkstr + " server " + targuser->server);
72                         if (targuser->awaymsg[0] != 0)
73                         {
74                                 /* user is away */
75                                 Srv->SendTo(NULL, user, checkstr + " awaymsg " + targuser->awaymsg);
76                         }
77                         if (targuser->oper[0] != 0)
78                         {
79                                 /* user is an oper of type ____ */
80                                 Srv->SendTo(NULL, user, checkstr + " opertype " + targuser->oper);
81                         }
82                         if (IS_LOCAL(targuser))
83                         {
84                                 /* port information is only held for a local user! */
85                                 Srv->SendTo(NULL, user, checkstr + " onport " + ConvToStr(targuser->port));
86                         }
87
88                         chliststr = chlist(targuser, targuser);
89                         std::stringstream dump(chliststr);
90
91                         Srv->DumpText(user,checkstr + " onchans ", dump);
92                 }
93                 else if (targchan)
94                 {
95                         /* /check on a channel */
96                         time_t creation_time = targchan->created;
97                         time_t topic_time = targchan->topicset;
98
99                         mytime = gmtime(&creation_time);
100                         strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
101                         Srv->SendTo(NULL, user, checkstr + " created " + timebuf);
102
103                         if (targchan->topic[0] != 0)
104                         {
105                                 /* there is a topic, assume topic related information exists */
106                                 Srv->SendTo(NULL, user, checkstr + " topic " + targchan->topic);
107                                 Srv->SendTo(NULL, user, checkstr + " topic_setby " + targchan->setby);
108                                 mytime = gmtime(&topic_time);
109                                 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
110                                 Srv->SendTo(NULL, user, checkstr + " topic_setat " + timebuf);
111                         }
112
113                         Srv->SendTo(NULL, user, checkstr + " modes " + chanmodes(targchan, true));
114                         Srv->SendTo(NULL, user, checkstr + " usercount " + ConvToStr(targchan->GetUserCounter()));
115                 }
116                 else
117                 {
118                         /*  /check on an IP address, or something that doesn't exist */
119                 }
120
121                 Srv->SendTo(NULL, user, checkstr + " END " + std::string(parameters[0]));
122         }
123 };
124
125
126 class ModuleCheck : public Module
127 {
128  private:
129         cmd_check *mycommand;
130  public:
131         ModuleCheck(Server* Me) : Module::Module(Me)
132         {
133                 Srv = Me;
134                 mycommand = new cmd_check();
135                 Srv->AddCommand(mycommand);
136         }
137         
138         virtual ~ModuleCheck()
139         {
140         }
141         
142         virtual Version GetVersion()
143         {
144                 return Version(1, 0, 0, 0, VF_VENDOR);
145         }
146
147         void Implements(char* List)
148         {
149                 /* we don't hook anything, nothing required */
150         }
151         
152 };
153
154
155
156 class ModuleCheckFactory : public ModuleFactory
157 {
158  public:
159         ModuleCheckFactory()
160         {
161         }
162         
163         ~ModuleCheckFactory()
164         {
165         }
166         
167         virtual Module * CreateModule(Server* Me)
168         {
169                 return new ModuleCheck(Me);
170         }
171         
172 };
173
174 extern "C" void * init_module( void )
175 {
176         return new ModuleCheckFactory;
177 }
178