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 * ---------------------------------------------------
24 #include "helperfuncs.h"
27 /* $ModDesc: Provides the /check command to retrieve information on a user, channel, or IP address */
29 extern InspIRCd* ServerInstance;
33 class cmd_check : public command_t
36 cmd_check() : command_t("CHECK", 'o', 1)
38 this->source = "m_check.so";
39 syntax = "<nickname>|<ip>|<hostmask>|<channel>";
42 void Handle (const char** parameters, int pcnt, userrec *user)
47 std::string chliststr;
53 checkstr = "304 " + std::string(user->nick) + " :CHECK";
55 targuser = ServerInstance->FindNick(parameters[0]);
56 targchan = ServerInstance->FindChan(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 user->WriteServ(checkstr + " START " + parameters[0]);
69 /* /check on a user */
70 user->WriteServ(checkstr + " nuh " + targuser->GetFullHost());
71 user->WriteServ(checkstr + " realnuh " + targuser->GetFullRealHost());
72 user->WriteServ(checkstr + " realname " + targuser->fullname);
73 user->WriteServ(checkstr + " modes +" + targuser->FormatModes());
74 user->WriteServ(checkstr + " server " + targuser->server);
75 if (targuser->awaymsg[0] != 0)
78 user->WriteServ(checkstr + " awaymsg " + targuser->awaymsg);
80 if (targuser->oper[0] != 0)
82 /* user is an oper of type ____ */
83 user->WriteServ(checkstr + " opertype " + targuser->oper);
85 if (IS_LOCAL(targuser))
87 /* port information is only held for a local user! */
88 user->WriteServ(checkstr + " onport " + ConvToStr(targuser->GetPort()));
91 chliststr = targuser->ChannelList(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 user->WriteServ(checkstr + " created " + timebuf);
106 if (targchan->topic[0] != 0)
108 /* there is a topic, assume topic related information exists */
109 user->WriteServ(checkstr + " topic " + targchan->topic);
110 user->WriteServ(checkstr + " topic_setby " + targchan->setby);
111 mytime = gmtime(&topic_time);
112 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
113 user->WriteServ(checkstr + " topic_setat " + timebuf);
116 user->WriteServ(checkstr + " modes " + targchan->ChanModes(true));
117 user->WriteServ(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 = targchan->GetStatusFlags(i->second);
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 ", i->second->GlobalCloneCount());
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 user->WriteServ(checkstr + " member " + ptr);
159 /* /check on an IP address, or something that doesn't exist */
162 /* hostname or other */
163 for (user_hash::const_iterator a = ServerInstance->clientlist.begin(); a != ServerInstance->clientlist.end(); a++)
165 if (match(a->second->host, parameters[0]) || match(a->second->dhost, parameters[0]))
167 /* host or vhost matches mask */
168 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
171 else if (match(a->second->GetIPString(), parameters[0]))
174 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
178 user->WriteServ(checkstr + " matches " + ConvToStr(x));
181 user->WriteServ(checkstr + " END " + std::string(parameters[0]));
186 class ModuleCheck : public Module
189 cmd_check *mycommand;
191 ModuleCheck(InspIRCd* Me) : Module::Module(Me)
194 mycommand = new cmd_check();
195 Srv->AddCommand(mycommand);
198 virtual ~ModuleCheck()
202 virtual Version GetVersion()
204 return Version(1, 0, 0, 0, VF_VENDOR);
207 void Implements(char* List)
209 /* we don't hook anything, nothing required */
216 class ModuleCheckFactory : public ModuleFactory
223 ~ModuleCheckFactory()
227 virtual Module * CreateModule(InspIRCd* Me)
229 return new ModuleCheck(Me);
234 extern "C" void * init_module( void )
236 return new ModuleCheckFactory;