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 /* $ModDesc: Provides the /check command to retrieve information on a user, channel, or IP address */
29 class cmd_check : public command_t
32 cmd_check (InspIRCd* Instance) : command_t(Instance,"CHECK", 'o', 1)
34 this->source = "m_check.so";
35 syntax = "<nickname>|<ip>|<hostmask>|<channel>";
38 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
43 std::string chliststr;
49 checkstr = "304 " + std::string(user->nick) + " :CHECK";
51 targuser = ServerInstance->FindNick(parameters[0]);
52 targchan = ServerInstance->FindChan(parameters[0]);
55 * Syntax of a /check reply:
56 * :server.name 304 target :CHECK START <target>
57 * :server.name 304 target :CHECK <field> <value>
58 * :server.name 304 target :CHECK END
61 user->WriteServ(checkstr + " START " + parameters[0]);
65 /* /check on a user */
66 user->WriteServ(checkstr + " nuh " + targuser->GetFullHost());
67 user->WriteServ(checkstr + " realnuh " + targuser->GetFullRealHost());
68 user->WriteServ(checkstr + " realname " + targuser->fullname);
69 user->WriteServ(checkstr + " modes +" + targuser->FormatModes());
70 user->WriteServ(checkstr + " server " + targuser->server);
71 if (targuser->awaymsg[0] != 0)
74 user->WriteServ(checkstr + " awaymsg " + targuser->awaymsg);
76 if (targuser->oper[0] != 0)
78 /* user is an oper of type ____ */
79 user->WriteServ(checkstr + " opertype " + targuser->oper);
81 if (IS_LOCAL(targuser))
83 /* port information is only held for a local user! */
84 user->WriteServ(checkstr + " onport " + ConvToStr(targuser->GetPort()));
87 chliststr = targuser->ChannelList(targuser);
88 std::stringstream dump(chliststr);
90 ServerInstance->DumpText(user,checkstr + " onchans ", dump);
94 /* /check on a channel */
95 time_t creation_time = targchan->created;
96 time_t topic_time = targchan->topicset;
98 mytime = gmtime(&creation_time);
99 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
100 user->WriteServ(checkstr + " created " + timebuf);
102 if (targchan->topic[0] != 0)
104 /* there is a topic, assume topic related information exists */
105 user->WriteServ(checkstr + " topic " + targchan->topic);
106 user->WriteServ(checkstr + " topic_setby " + targchan->setby);
107 mytime = gmtime(&topic_time);
108 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
109 user->WriteServ(checkstr + " topic_setat " + timebuf);
112 user->WriteServ(checkstr + " modes " + targchan->ChanModes(true));
113 user->WriteServ(checkstr + " membercount " + ConvToStr(targchan->GetUserCounter()));
115 /* now the ugly bit, spool current members of a channel. :| */
117 CUList *ulist= targchan->GetUsers();
119 /* note that unlike /names, we do NOT check +i vs in the channel */
120 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
124 * Unlike Asuka, I define a clone as coming from the same host. --w00t
126 snprintf(tmpbuf, MAXBUF, "%lu %s%s (%s@%s) %s ", i->second->GlobalCloneCount(), targchan->GetAllPrefixChars(i->second), i->second->nick, i->second->ident, i->second->dhost, i->second->fullname);
127 user->WriteServ(checkstr + " member " + tmpbuf);
132 /* /check on an IP address, or something that doesn't exist */
135 /* hostname or other */
136 for (user_hash::const_iterator a = ServerInstance->clientlist.begin(); a != ServerInstance->clientlist.end(); a++)
138 if (match(a->second->host, parameters[0]) || match(a->second->dhost, parameters[0]))
140 /* host or vhost matches mask */
141 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
144 else if (match(a->second->GetIPString(), parameters[0]))
147 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
151 user->WriteServ(checkstr + " matches " + ConvToStr(x));
154 user->WriteServ(checkstr + " END " + std::string(parameters[0]));
161 class ModuleCheck : public Module
164 cmd_check *mycommand;
166 ModuleCheck(InspIRCd* Me) : Module::Module(Me)
169 mycommand = new cmd_check(ServerInstance);
170 ServerInstance->AddCommand(mycommand);
173 virtual ~ModuleCheck()
177 virtual Version GetVersion()
179 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
182 void Implements(char* List)
184 /* we don't hook anything, nothing required */
191 class ModuleCheckFactory : public ModuleFactory
198 ~ModuleCheckFactory()
202 virtual Module * CreateModule(InspIRCd* Me)
204 return new ModuleCheck(Me);
209 extern "C" void * init_module( void )
211 return new ModuleCheckFactory;