1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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 * ---------------------------------------------------
16 /* $ModDesc: Provides the /check command to retrieve information on a user, channel, or IP address */
20 class CommandCheck : public Command
23 CommandCheck (InspIRCd* Instance) : Command(Instance,"CHECK", "o", 1)
25 this->source = "m_check.so";
26 syntax = "<nickname>|<ip>|<hostmask>|<channel>";
29 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
34 std::string chliststr;
40 checkstr = "304 " + std::string(user->nick) + " :CHECK";
42 targuser = ServerInstance->FindNick(parameters[0]);
43 targchan = ServerInstance->FindChan(parameters[0]);
46 * Syntax of a /check reply:
47 * :server.name 304 target :CHECK START <target>
48 * :server.name 304 target :CHECK <field> <value>
49 * :server.name 304 target :CHECK END
52 user->WriteServ(checkstr + " START " + parameters[0]);
56 /* /check on a user */
57 user->WriteServ(checkstr + " nuh " + targuser->GetFullHost());
58 user->WriteServ(checkstr + " realnuh " + targuser->GetFullRealHost());
59 user->WriteServ(checkstr + " realname " + targuser->fullname);
60 user->WriteServ(checkstr + " modes +" + targuser->FormatModes());
61 user->WriteServ(checkstr + " snomasks +" + targuser->FormatNoticeMasks());
62 user->WriteServ(checkstr + " server " + targuser->server);
63 user->WriteServ(checkstr + " uid " + targuser->uuid);
64 user->WriteServ(checkstr + " signon " + ConvToStr(targuser->signon));
65 user->WriteServ(checkstr + " nickts " + ConvToStr(targuser->age));
66 if (IS_LOCAL(targuser))
67 user->WriteServ(checkstr + " lastmsg " + ConvToStr(targuser->idle_lastmsg));
69 if (IS_AWAY(targuser))
72 user->WriteServ(checkstr + " awaytime " + ConvToStr(targuser->awaytime));
73 user->WriteServ(checkstr + " awaymsg " + targuser->awaymsg);
76 if (IS_OPER(targuser))
78 /* user is an oper of type ____ */
79 user->WriteServ(checkstr + " opertype " + irc::Spacify(targuser->oper.c_str()));
82 user->WriteServ(checkstr + " onip " + targuser->GetIPString());
83 if (IS_LOCAL(targuser))
85 user->WriteServ(checkstr + " onport " + ConvToStr(targuser->GetPort()));
86 std::string classname = targuser->GetClass()->GetName();
87 if (!classname.empty())
88 user->WriteServ(checkstr + " connectclass " + classname);
91 chliststr = targuser->ChannelList(targuser);
92 std::stringstream dump(chliststr);
94 ServerInstance->DumpText(user,checkstr + " onchans ", dump);
98 /* /check on a channel */
99 time_t creation_time = targchan->age;
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 + " timestamp " + 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++)
128 * Unlike Asuka, I define a clone as coming from the same host. --w00t
130 snprintf(tmpbuf, MAXBUF, "%-3lu %s%s (%s@%s) %s ", ServerInstance->Users->GlobalCloneCount(i->first), targchan->GetAllPrefixChars(i->first), i->first->nick.c_str(), i->first->ident.c_str(), i->first->dhost.c_str(), i->first->fullname.c_str());
131 user->WriteServ(checkstr + " member " + tmpbuf);
136 /* /check on an IP address, or something that doesn't exist */
139 /* hostname or other */
140 for (user_hash::const_iterator a = ServerInstance->Users->clientlist->begin(); a != ServerInstance->Users->clientlist->end(); a++)
142 if (InspIRCd::Match(a->second->host, parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(a->second->dhost, parameters[0], ascii_case_insensitive_map))
144 /* host or vhost matches mask */
145 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
148 else if (InspIRCd::MatchCIDR(a->second->GetIPString(), parameters[0]))
151 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
155 user->WriteServ(checkstr + " matches " + ConvToStr(x));
158 user->WriteServ(checkstr + " END " + parameters[0]);
160 return CMD_LOCALONLY;
165 class ModuleCheck : public Module
168 CommandCheck *mycommand;
170 ModuleCheck(InspIRCd* Me) : Module(Me)
173 mycommand = new CommandCheck(ServerInstance);
174 ServerInstance->AddCommand(mycommand);
178 virtual ~ModuleCheck()
182 virtual Version GetVersion()
184 return Version("$Id$", VF_VENDOR, API_VERSION);
190 MODULE_INIT(ModuleCheck)