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