]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_check.cpp
Remove unnecessary header traffic
[user/henk/code/inspircd.git] / src / modules / m_check.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "wildcard.h"
16
17 /* $ModDesc: Provides the /check command to retrieve information on a user, channel, or IP address */
18
19 /** Handle /CHECK
20  */
21 class cmd_check : public command_t
22 {
23  public:
24         cmd_check (InspIRCd* Instance) : command_t(Instance,"CHECK", 'o', 1)
25         {
26                 this->source = "m_check.so";
27                 syntax = "<nickname>|<ip>|<hostmask>|<channel>";
28         }
29
30         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
31         {
32                 userrec *targuser;
33                 chanrec *targchan;
34                 std::string checkstr;
35                 std::string chliststr;
36
37                 char timebuf[60];
38                 struct tm *mytime;
39
40
41                 checkstr = "304 " + std::string(user->nick) + " :CHECK";
42
43                 targuser = ServerInstance->FindNick(parameters[0]);
44                 targchan = ServerInstance->FindChan(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                 user->WriteServ(checkstr + " START " + parameters[0]);
54
55                 if (targuser)
56                 {
57                         /* /check on a user */
58                         user->WriteServ(checkstr + " nuh " + targuser->GetFullHost());
59                         user->WriteServ(checkstr + " realnuh " + targuser->GetFullRealHost());
60                         user->WriteServ(checkstr + " realname " + targuser->fullname);
61                         user->WriteServ(checkstr + " modes +" + targuser->FormatModes());
62                         user->WriteServ(checkstr + " snomasks +" + targuser->FormatNoticeMasks());
63                         user->WriteServ(checkstr + " server " + targuser->server);
64
65                         if (IS_AWAY(targuser))
66                         {
67                                 /* user is away */
68                                 user->WriteServ(checkstr + " awaymsg " + targuser->awaymsg);
69                         }
70
71                         if (IS_OPER(targuser))
72                         {
73                                 /* user is an oper of type ____ */
74                                 user->WriteServ(checkstr + " opertype " + irc::Spacify(targuser->oper));
75                         }
76
77                         if (IS_LOCAL(targuser))
78                         {
79                                 /* port information is only held for a local user! */
80                                 user->WriteServ(checkstr + " onport " + ConvToStr(targuser->GetPort()));
81                         }
82
83                         chliststr = targuser->ChannelList(targuser);
84                         std::stringstream dump(chliststr);
85
86                         ServerInstance->DumpText(user,checkstr + " onchans ", dump);
87                 }
88                 else if (targchan)
89                 {
90                         /* /check on a channel */
91                         time_t creation_time = targchan->created;
92                         time_t topic_time = targchan->topicset;
93
94                         mytime = gmtime(&creation_time);
95                         strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
96                         user->WriteServ(checkstr + " created " + timebuf);
97
98                         if (targchan->topic[0] != 0)
99                         {
100                                 /* there is a topic, assume topic related information exists */
101                                 user->WriteServ(checkstr + " topic " + targchan->topic);
102                                 user->WriteServ(checkstr + " topic_setby " + targchan->setby);
103                                 mytime = gmtime(&topic_time);
104                                 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
105                                 user->WriteServ(checkstr + " topic_setat " + timebuf);
106                         }
107
108                         user->WriteServ(checkstr + " modes " + targchan->ChanModes(true));
109                         user->WriteServ(checkstr + " membercount " + ConvToStr(targchan->GetUserCounter()));
110                         
111                         /* now the ugly bit, spool current members of a channel. :| */
112
113                         CUList *ulist= targchan->GetUsers();
114
115                         /* note that unlike /names, we do NOT check +i vs in the channel */
116                         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
117                         {
118                                 char tmpbuf[MAXBUF];
119                                 /*
120                                  * Unlike Asuka, I define a clone as coming from the same host. --w00t
121                                  */
122                                 snprintf(tmpbuf, MAXBUF, "%lu    %s%s (%s@%s) %s ", i->first->GlobalCloneCount(), targchan->GetAllPrefixChars(i->first), i->first->nick, i->first->ident, i->first->dhost, i->first->fullname);
123                                 user->WriteServ(checkstr + " member " + tmpbuf);
124                         }
125                 }
126                 else
127                 {
128                         /*  /check on an IP address, or something that doesn't exist */
129                         long x = 0;
130
131                         /* hostname or other */
132                         for (user_hash::const_iterator a = ServerInstance->clientlist->begin(); a != ServerInstance->clientlist->end(); a++)
133                         {
134                                 if (match(a->second->host, parameters[0]) || match(a->second->dhost, parameters[0]))
135                                 {
136                                         /* host or vhost matches mask */
137                                         user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
138                                 }
139                                 /* IP address */
140                                 else if (match(a->second->GetIPString(), parameters[0], true))
141                                 {
142                                         /* same IP. */
143                                         user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
144                                 }
145                         }
146
147                         user->WriteServ(checkstr + " matches " + ConvToStr(x));
148                 }
149
150                 user->WriteServ(checkstr + " END " + std::string(parameters[0]));
151
152                 return CMD_LOCALONLY;
153         }
154 };
155
156
157 class ModuleCheck : public Module
158 {
159  private:
160         cmd_check *mycommand;
161  public:
162         ModuleCheck(InspIRCd* Me) : Module(Me)
163         {
164                 
165                 mycommand = new cmd_check(ServerInstance);
166                 ServerInstance->AddCommand(mycommand);
167         }
168         
169         virtual ~ModuleCheck()
170         {
171         }
172         
173         virtual Version GetVersion()
174         {
175                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
176         }
177
178         void Implements(char* List)
179         {
180                 /* we don't hook anything, nothing required */
181         }
182         
183 };
184
185 MODULE_INIT(ModuleCheck)