1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
20 /* $ModDesc: Provides the /check command to retrieve information on a user, channel, or IP address */
24 class cmd_check : public command_t
27 cmd_check (InspIRCd* Instance) : command_t(Instance,"CHECK", 'o', 1)
29 this->source = "m_check.so";
30 syntax = "<nickname>|<ip>|<hostmask>|<channel>";
33 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
38 std::string chliststr;
44 checkstr = "304 " + std::string(user->nick) + " :CHECK";
46 targuser = ServerInstance->FindNick(parameters[0]);
47 targchan = ServerInstance->FindChan(parameters[0]);
50 * Syntax of a /check reply:
51 * :server.name 304 target :CHECK START <target>
52 * :server.name 304 target :CHECK <field> <value>
53 * :server.name 304 target :CHECK END
56 user->WriteServ(checkstr + " START " + parameters[0]);
60 /* /check on a user */
61 user->WriteServ(checkstr + " nuh " + targuser->GetFullHost());
62 user->WriteServ(checkstr + " realnuh " + targuser->GetFullRealHost());
63 user->WriteServ(checkstr + " realname " + targuser->fullname);
64 user->WriteServ(checkstr + " modes +" + targuser->FormatModes());
65 user->WriteServ(checkstr + " server " + targuser->server);
66 if (targuser->awaymsg[0] != 0)
69 user->WriteServ(checkstr + " awaymsg " + targuser->awaymsg);
71 if (targuser->oper[0] != 0)
73 /* user is an oper of type ____ */
74 user->WriteServ(checkstr + " opertype " + targuser->oper);
76 if (IS_LOCAL(targuser))
78 /* port information is only held for a local user! */
79 user->WriteServ(checkstr + " onport " + ConvToStr(targuser->GetPort()));
82 chliststr = targuser->ChannelList(targuser);
83 std::stringstream dump(chliststr);
85 ServerInstance->DumpText(user,checkstr + " onchans ", dump);
89 /* /check on a channel */
90 time_t creation_time = targchan->created;
91 time_t topic_time = targchan->topicset;
93 mytime = gmtime(&creation_time);
94 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
95 user->WriteServ(checkstr + " created " + timebuf);
97 if (targchan->topic[0] != 0)
99 /* there is a topic, assume topic related information exists */
100 user->WriteServ(checkstr + " topic " + targchan->topic);
101 user->WriteServ(checkstr + " topic_setby " + targchan->setby);
102 mytime = gmtime(&topic_time);
103 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
104 user->WriteServ(checkstr + " topic_setat " + timebuf);
107 user->WriteServ(checkstr + " modes " + targchan->ChanModes(true));
108 user->WriteServ(checkstr + " membercount " + ConvToStr(targchan->GetUserCounter()));
110 /* now the ugly bit, spool current members of a channel. :| */
112 CUList *ulist= targchan->GetUsers();
114 /* note that unlike /names, we do NOT check +i vs in the channel */
115 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
119 * Unlike Asuka, I define a clone as coming from the same host. --w00t
121 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);
122 user->WriteServ(checkstr + " member " + tmpbuf);
127 /* /check on an IP address, or something that doesn't exist */
130 /* hostname or other */
131 for (user_hash::const_iterator a = ServerInstance->clientlist->begin(); a != ServerInstance->clientlist->end(); a++)
133 if (match(a->second->host, parameters[0]) || match(a->second->dhost, parameters[0]))
135 /* host or vhost matches mask */
136 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
139 else if (match(a->second->GetIPString(), parameters[0]))
142 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
146 user->WriteServ(checkstr + " matches " + ConvToStr(x));
149 user->WriteServ(checkstr + " END " + std::string(parameters[0]));
156 class ModuleCheck : public Module
159 cmd_check *mycommand;
161 ModuleCheck(InspIRCd* Me) : Module::Module(Me)
164 mycommand = new cmd_check(ServerInstance);
165 ServerInstance->AddCommand(mycommand);
168 virtual ~ModuleCheck()
172 virtual Version GetVersion()
174 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
177 void Implements(char* List)
179 /* we don't hook anything, nothing required */
186 class ModuleCheckFactory : public ModuleFactory
193 ~ModuleCheckFactory()
197 virtual Module * CreateModule(InspIRCd* Me)
199 return new ModuleCheck(Me);
204 extern "C" void * init_module( void )
206 return new ModuleCheckFactory;