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";
40 syntax = "<nickname>|<ip>|<hostmask>|<channel>";
43 void Handle (const char** parameters, int pcnt, userrec *user)
48 std::string chliststr;
54 checkstr = "304 " + std::string(user->nick) + " :CHECK";
56 targuser = Srv->FindNick(std::string(parameters[0]));
57 targchan = Srv->FindChannel(std::string(parameters[0]));
60 * Syntax of a /check reply:
61 * :server.name 304 target :CHECK START <target>
62 * :server.name 304 target :CHECK <field> <value>
63 * :server.name 304 target :CHECK END
66 Srv->SendTo(NULL, user, checkstr + " START " + parameters[0]);
70 /* /check on a user */
71 Srv->SendTo(NULL, user, checkstr + " nuh " + targuser->GetFullHost());
72 Srv->SendTo(NULL, user, checkstr + " realnuh " + targuser->GetFullRealHost());
73 Srv->SendTo(NULL, user, checkstr + " realname " + targuser->fullname);
74 Srv->SendTo(NULL, user, checkstr + " modes +" + targuser->FormatModes());
75 Srv->SendTo(NULL, user, checkstr + " server " + targuser->server);
76 if (targuser->awaymsg[0] != 0)
79 Srv->SendTo(NULL, user, checkstr + " awaymsg " + targuser->awaymsg);
81 if (targuser->oper[0] != 0)
83 /* user is an oper of type ____ */
84 Srv->SendTo(NULL, user, checkstr + " opertype " + targuser->oper);
86 if (IS_LOCAL(targuser))
88 /* port information is only held for a local user! */
89 Srv->SendTo(NULL, user, checkstr + " onport " + ConvToStr(targuser->port));
92 chliststr = chlist(targuser, targuser);
93 std::stringstream dump(chliststr);
95 Srv->DumpText(user,checkstr + " onchans ", dump);
99 /* /check on a channel */
100 time_t creation_time = targchan->created;
101 time_t topic_time = targchan->topicset;
103 mytime = gmtime(&creation_time);
104 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
105 Srv->SendTo(NULL, user, checkstr + " created " + timebuf);
107 if (targchan->topic[0] != 0)
109 /* there is a topic, assume topic related information exists */
110 Srv->SendTo(NULL, user, checkstr + " topic " + targchan->topic);
111 Srv->SendTo(NULL, user, checkstr + " topic_setby " + targchan->setby);
112 mytime = gmtime(&topic_time);
113 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
114 Srv->SendTo(NULL, user, checkstr + " topic_setat " + timebuf);
117 Srv->SendTo(NULL, user, checkstr + " modes " + chanmodes(targchan, true));
118 Srv->SendTo(NULL, user, checkstr + " membercount " + ConvToStr(targchan->GetUserCounter()));
120 /* now the ugly bit, spool current members of a channel. :| */
122 CUList *ulist= targchan->GetUsers();
124 /* note that unlike /names, we do NOT check +i vs in the channel */
125 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
130 int flags = cflags(i->second, targchan);
132 * find how many connections from this user's IP -- unlike Asuka,
133 * I define a clone as coming from the same host. --w00t
135 sprintf(ptr, "%lu ", FindMatchingGlobal(i->second));
137 if (flags & UCMODE_OP)
142 if (flags & UCMODE_HOP)
147 if (flags & UCMODE_VOICE)
152 sprintf(tmpbuf, "%s (%s@%s) %s ", i->second->nick, i->second->ident, i->second->dhost, i->second->fullname);
155 Srv->SendTo(NULL, user, checkstr + " member " + ptr);
160 /* /check on an IP address, or something that doesn't exist */
161 struct sockaddr_in addr;
164 if (inet_aton(parameters[0], &addr.sin_addr) == 0)
166 /* hostname or other */
167 for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++)
169 if (match(a->second->host, parameters[0]) || match(a->second->dhost, parameters[0]))
171 /* host or vhost matches mask */
172 Srv->SendTo(NULL, user, checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
179 for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++)
181 if (addr.sin_addr.s_addr == a->second->ip4.s_addr)
184 Srv->SendTo(NULL, user, checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
189 Srv->SendTo(NULL, user, checkstr + " matches " + ConvToStr(x));
192 Srv->SendTo(NULL, user, checkstr + " END " + std::string(parameters[0]));
197 class ModuleCheck : public Module
200 cmd_check *mycommand;
202 ModuleCheck(Server* Me) : Module::Module(Me)
205 mycommand = new cmd_check();
206 Srv->AddCommand(mycommand);
209 virtual ~ModuleCheck()
213 virtual Version GetVersion()
215 return Version(1, 0, 0, 0, VF_VENDOR);
218 void Implements(char* List)
220 /* we don't hook anything, nothing required */
227 class ModuleCheckFactory : public ModuleFactory
234 ~ModuleCheckFactory()
238 virtual Module * CreateModule(Server* Me)
240 return new ModuleCheck(Me);
245 extern "C" void * init_module( void )
247 return new ModuleCheckFactory;