]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_check.cpp
Now requires inspircd.h for ConvToStr templated function
[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
26 /* $ModDesc: Provides the /check command to retrieve information on a user, channel, or IP address */
27
28 static Server *Srv;
29
30 class cmd_check : public command_t
31 {
32  public:
33         cmd_check() : command_t("CHECK", 'o', 1)
34         {
35                 this->source = "m_check.so";
36         }
37
38         void Handle (char **parameters, int pcnt, userrec *user)
39         {
40                 userrec *targuser;
41                 chanrec *targchan;
42                 std::string checkstr;
43                 std::string chliststr;
44
45                 checkstr = "304 " + std::string(user->nick) + " :CHECK";
46
47                 targuser = Srv->FindNick(std::string(parameters[0]));
48                 targchan = Srv->FindChannel(std::string(parameters[0]));
49
50                 /*
51                  * Syntax of a /check reply:
52                  *  :server.name 304 target :CHECK START <target>
53                  *  :server.name 304 target :CHECK <field> <value>
54                  *  :server.name 304 target :CHECK END
55                  */
56
57                 Srv->SendTo(NULL, user, checkstr + " START " + std::string(parameters[0]));
58
59                 if (targuser)
60                 {
61                         /* /check on a user */
62                         Srv->SendTo(NULL, user, checkstr + " nuh " + std::string(targuser->GetFullHost()));
63                         Srv->SendTo(NULL, user, checkstr + " realnuh " + std::string(targuser->GetFullRealHost()));
64                         Srv->SendTo(NULL, user, checkstr + " realname " + std::string(targuser->fullname));
65                         Srv->SendTo(NULL, user, checkstr + " modes +" + std::string(targuser->modes));
66                         Srv->SendTo(NULL, user, checkstr + " server " + std::string(targuser->server));
67                         if (targuser->awaymsg[0] != 0)
68                         {
69                                 /* user is away */
70                                 Srv->SendTo(NULL, user, checkstr + " awaymsg " + std::string(targuser->awaymsg));
71                         }
72                         if (targuser->oper[0] != 0)
73                         {
74                                 /* user is an oper of type ____ */
75                                 Srv->SendTo(NULL, user, checkstr + " opertype " + std::string(targuser->oper));
76                         }
77                         if (IS_LOCAL(targuser))
78                         {
79                                 /* port information is only held for a local user! */
80                                 Srv->SendTo(NULL, user, checkstr + " onport " + ConvToStr(targuser->port));
81                         }
82
83                         chliststr = chlist(targuser, targuser);
84                         std::stringstream dump(chliststr);
85                         /* XXX - This doent suck so much */
86                         Srv->DumpText(user,checkstr + " onchans ", dump);
87                 }
88                 else if (targchan)
89                 {
90                         /* /check on a channel */
91                 }
92                 else
93                 {
94                         /*  /check on an IP address, or something that doesn't exist */
95                 }
96
97                 Srv->SendTo(NULL, user, checkstr + " END " + std::string(parameters[0]));
98         }
99 };
100
101
102 class ModuleCheck : public Module
103 {
104  private:
105         cmd_check *mycommand;
106  public:
107         ModuleCheck(Server* Me) : Module::Module(Me)
108         {
109                 Srv = Me;
110                 mycommand = new cmd_check();
111                 Srv->AddCommand(mycommand);
112         }
113         
114         virtual ~ModuleCheck()
115         {
116         }
117         
118         virtual Version GetVersion()
119         {
120                 return Version(1, 0, 0, 0, VF_VENDOR);
121         }
122
123         void Implements(char* List)
124         {
125                 /* we don't hook anything, nothing required */
126         }
127         
128 };
129
130
131
132 class ModuleCheckFactory : public ModuleFactory
133 {
134  public:
135         ModuleCheckFactory()
136         {
137         }
138         
139         ~ModuleCheckFactory()
140         {
141         }
142         
143         virtual Module * CreateModule(Server* Me)
144         {
145                 return new ModuleCheck(Me);
146         }
147         
148 };
149
150 extern "C" void * init_module( void )
151 {
152         return new ModuleCheckFactory;
153 }
154