]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_check.cpp
f1a160b98fe1bf04f230a998f523947304eb1ae2
[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                         if (chliststr.length())
84                         {
85                                 if (chliststr.length() > 400)
86                                 {
87                                         /* XXX - this sucks. deal with it. */
88                                         std::stringstream chstream(chliststr);
89                                         std::string line = "";
90                                         std::string cname = "";
91                                         while (!chstream.eof())
92                                         {
93                                                 chstream >> cname;
94                                                 line = line + cname + " ";
95                                                 if (line.length() > 400)
96                                                 {
97                                                         Srv->SendTo(NULL, user, checkstr + " onchans " + line);
98                                                         line = "";
99                                                 }
100                                         }
101                                         if (line.length())
102                                         {
103                                                 Srv->SendTo(NULL, user, checkstr + " onchans " + line);
104                                         }
105                                 }
106                                 else
107                                 {
108                                         Srv->SendTo(NULL, user, checkstr + " onchans " + chliststr);
109                                 }                               
110                         }
111                 }
112                 else if (targchan)
113                 {
114                         /* /check on a channel */
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