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