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 * ---------------------------------------------------
27 /* $ModDesc: Provides the /check command to retrieve information on a user, channel, or IP address */
31 class cmd_check : public command_t
34 cmd_check (InspIRCd* Instance) : command_t(Instance,"CHECK", 'o', 1)
36 this->source = "m_check.so";
37 syntax = "<nickname>|<ip>|<hostmask>|<channel>";
40 void Handle (const char** parameters, int pcnt, userrec *user)
45 std::string chliststr;
51 checkstr = "304 " + std::string(user->nick) + " :CHECK";
53 targuser = ServerInstance->FindNick(parameters[0]);
54 targchan = ServerInstance->FindChan(parameters[0]);
57 * Syntax of a /check reply:
58 * :server.name 304 target :CHECK START <target>
59 * :server.name 304 target :CHECK <field> <value>
60 * :server.name 304 target :CHECK END
63 user->WriteServ(checkstr + " START " + parameters[0]);
67 /* /check on a user */
68 user->WriteServ(checkstr + " nuh " + targuser->GetFullHost());
69 user->WriteServ(checkstr + " realnuh " + targuser->GetFullRealHost());
70 user->WriteServ(checkstr + " realname " + targuser->fullname);
71 user->WriteServ(checkstr + " modes +" + targuser->FormatModes());
72 user->WriteServ(checkstr + " server " + targuser->server);
73 if (targuser->awaymsg[0] != 0)
76 user->WriteServ(checkstr + " awaymsg " + targuser->awaymsg);
78 if (targuser->oper[0] != 0)
80 /* user is an oper of type ____ */
81 user->WriteServ(checkstr + " opertype " + targuser->oper);
83 if (IS_LOCAL(targuser))
85 /* port information is only held for a local user! */
86 user->WriteServ(checkstr + " onport " + ConvToStr(targuser->GetPort()));
89 chliststr = targuser->ChannelList(targuser);
90 std::stringstream dump(chliststr);
92 ServerInstance->DumpText(user,checkstr + " onchans ", dump);
96 /* /check on a channel */
97 time_t creation_time = targchan->created;
98 time_t topic_time = targchan->topicset;
100 mytime = gmtime(&creation_time);
101 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
102 user->WriteServ(checkstr + " created " + timebuf);
104 if (targchan->topic[0] != 0)
106 /* there is a topic, assume topic related information exists */
107 user->WriteServ(checkstr + " topic " + targchan->topic);
108 user->WriteServ(checkstr + " topic_setby " + targchan->setby);
109 mytime = gmtime(&topic_time);
110 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
111 user->WriteServ(checkstr + " topic_setat " + timebuf);
114 user->WriteServ(checkstr + " modes " + targchan->ChanModes(true));
115 user->WriteServ(checkstr + " membercount " + ConvToStr(targchan->GetUserCounter()));
117 /* now the ugly bit, spool current members of a channel. :| */
119 CUList *ulist= targchan->GetUsers();
121 /* note that unlike /names, we do NOT check +i vs in the channel */
122 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
127 int flags = targchan->GetStatusFlags(i->second);
129 * find how many connections from this user's IP -- unlike Asuka,
130 * I define a clone as coming from the same host. --w00t
132 sprintf(ptr, "%lu ", i->second->GlobalCloneCount());
134 if (flags & UCMODE_OP)
139 if (flags & UCMODE_HOP)
144 if (flags & UCMODE_VOICE)
149 sprintf(tmpbuf, "%s (%s@%s) %s ", i->second->nick, i->second->ident, i->second->dhost, i->second->fullname);
152 user->WriteServ(checkstr + " member " + ptr);
157 /* /check on an IP address, or something that doesn't exist */
160 /* hostname or other */
161 for (user_hash::const_iterator a = ServerInstance->clientlist.begin(); a != ServerInstance->clientlist.end(); a++)
163 if (match(a->second->host, parameters[0]) || match(a->second->dhost, parameters[0]))
165 /* host or vhost matches mask */
166 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
169 else if (match(a->second->GetIPString(), parameters[0]))
172 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
176 user->WriteServ(checkstr + " matches " + ConvToStr(x));
179 user->WriteServ(checkstr + " END " + std::string(parameters[0]));
184 class ModuleCheck : public Module
187 cmd_check *mycommand;
189 ModuleCheck(InspIRCd* Me) : Module::Module(Me)
192 mycommand = new cmd_check(ServerInstance);
193 ServerInstance->AddCommand(mycommand);
196 virtual ~ModuleCheck()
200 virtual Version GetVersion()
202 return Version(1, 0, 0, 0, VF_VENDOR);
205 void Implements(char* List)
207 /* we don't hook anything, nothing required */
214 class ModuleCheckFactory : public ModuleFactory
221 ~ModuleCheckFactory()
225 virtual Module * CreateModule(InspIRCd* Me)
227 return new ModuleCheck(Me);
232 extern "C" void * init_module( void )
234 return new ModuleCheckFactory;