1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
25 #include "helperfuncs.h"
27 /* $ModDesc: Provides the /check command to retrieve information on a user, channel, or IP address */
29 extern user_hash clientlist;
30 extern bool match(const char *, const char *);
34 class cmd_check : public command_t
37 cmd_check() : command_t("CHECK", 'o', 1)
39 this->source = "m_check.so";
42 void Handle (char **parameters, int pcnt, userrec *user)
47 std::string chliststr;
53 checkstr = "304 " + std::string(user->nick) + " :CHECK";
55 targuser = Srv->FindNick(std::string(parameters[0]));
56 targchan = Srv->FindChannel(std::string(parameters[0]));
59 * Syntax of a /check reply:
60 * :server.name 304 target :CHECK START <target>
61 * :server.name 304 target :CHECK <field> <value>
62 * :server.name 304 target :CHECK END
65 Srv->SendTo(NULL, user, checkstr + " START " + parameters[0]);
69 /* /check on a user */
70 Srv->SendTo(NULL, user, checkstr + " nuh " + targuser->GetFullHost());
71 Srv->SendTo(NULL, user, checkstr + " realnuh " + targuser->GetFullRealHost());
72 Srv->SendTo(NULL, user, checkstr + " realname " + targuser->fullname);
73 Srv->SendTo(NULL, user, checkstr + " modes +" + targuser->FormatModes());
74 Srv->SendTo(NULL, user, checkstr + " server " + targuser->server);
75 if (targuser->awaymsg[0] != 0)
78 Srv->SendTo(NULL, user, checkstr + " awaymsg " + targuser->awaymsg);
80 if (targuser->oper[0] != 0)
82 /* user is an oper of type ____ */
83 Srv->SendTo(NULL, user, checkstr + " opertype " + targuser->oper);
85 if (IS_LOCAL(targuser))
87 /* port information is only held for a local user! */
88 Srv->SendTo(NULL, user, checkstr + " onport " + ConvToStr(targuser->port));
91 chliststr = chlist(targuser, targuser);
92 std::stringstream dump(chliststr);
94 Srv->DumpText(user,checkstr + " onchans ", dump);
98 /* /check on a channel */
99 time_t creation_time = targchan->created;
100 time_t topic_time = targchan->topicset;
102 mytime = gmtime(&creation_time);
103 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
104 Srv->SendTo(NULL, user, checkstr + " created " + timebuf);
106 if (targchan->topic[0] != 0)
108 /* there is a topic, assume topic related information exists */
109 Srv->SendTo(NULL, user, checkstr + " topic " + targchan->topic);
110 Srv->SendTo(NULL, user, checkstr + " topic_setby " + targchan->setby);
111 mytime = gmtime(&topic_time);
112 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
113 Srv->SendTo(NULL, user, checkstr + " topic_setat " + timebuf);
116 Srv->SendTo(NULL, user, checkstr + " modes " + chanmodes(targchan, true));
117 Srv->SendTo(NULL, user, checkstr + " membercount " + ConvToStr(targchan->GetUserCounter()));
119 /* now the ugly bit, spool current members of a channel. :| */
121 CUList *ulist= targchan->GetUsers();
123 /* note that unlike /names, we do NOT check +i vs in the channel */
124 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
129 int flags = cflags(i->second, targchan);
131 * find how many connections from this user's IP -- unlike Asuka,
132 * I define a clone as coming from the same host. --w00t
134 sprintf(ptr, "%lu ", FindMatchingGlobal(i->second));
136 if (flags & UCMODE_OP)
141 if (flags & UCMODE_HOP)
146 if (flags & UCMODE_VOICE)
151 sprintf(tmpbuf, "%s (%s@%s) %s ", i->second->nick, i->second->ident, i->second->dhost, i->second->fullname);
154 Srv->SendTo(NULL, user, checkstr + " member " + ptr);
159 /* /check on an IP address, or something that doesn't exist */
160 struct sockaddr_in addr;
163 if (inet_aton(parameters[0], &addr.sin_addr) == 0)
165 /* hostname or other */
166 for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++)
168 if (match(a->second->host, parameters[0]) || match(a->second->dhost, parameters[0]))
170 /* host or vhost matches mask */
171 Srv->SendTo(NULL, user, checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
178 for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++)
180 if (addr.sin_addr.s_addr == a->second->ip4.s_addr)
183 Srv->SendTo(NULL, user, checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
188 Srv->SendTo(NULL, user, checkstr + " matches " + ConvToStr(x));
191 Srv->SendTo(NULL, user, checkstr + " END " + std::string(parameters[0]));
196 class ModuleCheck : public Module
199 cmd_check *mycommand;
201 ModuleCheck(Server* Me) : Module::Module(Me)
204 mycommand = new cmd_check();
205 Srv->AddCommand(mycommand);
208 virtual ~ModuleCheck()
212 virtual Version GetVersion()
214 return Version(1, 0, 0, 0, VF_VENDOR);
217 void Implements(char* List)
219 /* we don't hook anything, nothing required */
226 class ModuleCheckFactory : public ModuleFactory
233 ~ModuleCheckFactory()
237 virtual Module * CreateModule(Server* Me)
239 return new ModuleCheck(Me);
244 extern "C" void * init_module( void )
246 return new ModuleCheckFactory;