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 #include "helperfuncs.h"
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() : command_t("CHECK", 'o', 1)
36 this->source = "m_check.so";
39 void Handle (char **parameters, int pcnt, userrec *user)
44 std::string chliststr;
50 checkstr = "304 " + std::string(user->nick) + " :CHECK";
52 targuser = Srv->FindNick(std::string(parameters[0]));
53 targchan = Srv->FindChannel(std::string(parameters[0]));
56 * Syntax of a /check reply:
57 * :server.name 304 target :CHECK START <target>
58 * :server.name 304 target :CHECK <field> <value>
59 * :server.name 304 target :CHECK END
62 Srv->SendTo(NULL, user, checkstr + " START " + parameters[0]);
66 /* /check on a user */
67 Srv->SendTo(NULL, user, checkstr + " nuh " + targuser->GetFullHost());
68 Srv->SendTo(NULL, user, checkstr + " realnuh " + targuser->GetFullRealHost());
69 Srv->SendTo(NULL, user, checkstr + " realname " + targuser->fullname);
70 Srv->SendTo(NULL, user, checkstr + " modes +" + targuser->modes);
71 Srv->SendTo(NULL, user, checkstr + " server " + targuser->server);
72 if (targuser->awaymsg[0] != 0)
75 Srv->SendTo(NULL, user, checkstr + " awaymsg " + targuser->awaymsg);
77 if (targuser->oper[0] != 0)
79 /* user is an oper of type ____ */
80 Srv->SendTo(NULL, user, checkstr + " opertype " + targuser->oper);
82 if (IS_LOCAL(targuser))
84 /* port information is only held for a local user! */
85 Srv->SendTo(NULL, user, checkstr + " onport " + ConvToStr(targuser->port));
88 chliststr = chlist(targuser, targuser);
89 std::stringstream dump(chliststr);
91 Srv->DumpText(user,checkstr + " onchans ", dump);
95 /* /check on a channel */
96 time_t creation_time = targchan->created;
97 time_t topic_time = targchan->topicset;
99 mytime = gmtime(&creation_time);
100 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
101 Srv->SendTo(NULL, user, checkstr + " created " + timebuf);
103 if (targchan->topic[0] != 0)
105 /* there is a topic, assume topic related information exists */
106 Srv->SendTo(NULL, user, checkstr + " topic " + targchan->topic);
107 Srv->SendTo(NULL, user, checkstr + " topic_setby " + targchan->setby);
108 mytime = gmtime(&topic_time);
109 strftime(timebuf, 59, "%Y/%m/%d - %H:%M:%S", mytime);
110 Srv->SendTo(NULL, user, checkstr + " topic_setat " + timebuf);
113 Srv->SendTo(NULL, user, checkstr + " modes " + chanmodes(targchan, true));
114 Srv->SendTo(NULL, user, checkstr + " usercount " + ConvToStr(targchan->GetUserCounter()));
118 /* /check on an IP address, or something that doesn't exist */
121 Srv->SendTo(NULL, user, checkstr + " END " + std::string(parameters[0]));
126 class ModuleCheck : public Module
129 cmd_check *mycommand;
131 ModuleCheck(Server* Me) : Module::Module(Me)
134 mycommand = new cmd_check();
135 Srv->AddCommand(mycommand);
138 virtual ~ModuleCheck()
142 virtual Version GetVersion()
144 return Version(1, 0, 0, 0, VF_VENDOR);
147 void Implements(char* List)
149 /* we don't hook anything, nothing required */
156 class ModuleCheckFactory : public ModuleFactory
163 ~ModuleCheckFactory()
167 virtual Module * CreateModule(Server* Me)
169 return new ModuleCheck(Me);
174 extern "C" void * init_module( void )
176 return new ModuleCheckFactory;