]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/cmd_whois.cpp
972b0439e0ad62ad1d5573e8e5d749b543d89a3d
[user/henk/code/inspircd.git] / src / modules / cmd_whois.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /** Handle /WHOIS. These command handlers can be reloaded by the core,
17  * and handle basic RFC1459 commands. Commands within modules work
18  * the same way, however, they can be fully unloaded, where these
19  * may not.
20  */
21 class CommandWhois : public Command
22 {
23  public:
24         /** Constructor for whois.
25          */
26         CommandWhois ( Module* parent) : Command(parent,"WHOIS",1) { Penalty = 2; syntax = "<nick>{,<nick>}"; }
27         /** Handle command.
28          * @param parameters The parameters to the comamnd
29          * @param pcnt The number of parameters passed to teh command
30          * @param user The user issuing the command
31          * @return A value from CmdResult to indicate command success or failure.
32          */
33         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
34 };
35
36
37 CmdResult CommandWhois::Handle (const std::vector<std::string>& parameters, User *user)
38 {
39         User *dest;
40         int userindex = 0;
41         unsigned long idle = 0, signon = 0;
42
43         if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
44                 return CMD_SUCCESS;
45
46
47         /*
48          * If 2 paramters are specified (/whois nick nick), ignore the first one like spanningtree
49          * does, and use the second one, otherwise, use the only paramter. -- djGrrr
50          */
51         if (parameters.size() > 1)
52                 userindex = 1;
53
54         if (IS_LOCAL(user))
55                 dest = ServerInstance->FindNickOnly(parameters[userindex]);
56         else
57                 dest = ServerInstance->FindNick(parameters[userindex]);
58
59         if (dest)
60         {
61                 /*
62                  * Okay. Umpteenth attempt at doing this, so let's re-comment...
63                  * For local users (/w localuser), we show idletime if hidewhois is disabled
64                  * For local users (/w localuser localuser), we always show idletime, hence parameters.size() > 1 check.
65                  * For remote users (/w remoteuser), we do NOT show idletime
66                  * For remote users (/w remoteuser remoteuser), spanningtree will handle calling do_whois, so we can ignore this case.
67                  * Thanks to djGrrr for not being impatient while I have a crap day coding. :p -- w00t
68                  */
69                 if (IS_LOCAL(dest) && (!*ServerInstance->Config->HideWhoisServer || parameters.size() > 1))
70                 {
71                         idle = abs((long)((dest->idle_lastmsg)-ServerInstance->Time()));
72                         signon = dest->signon;
73                 }
74
75                 ServerInstance->DoWhois(user,dest,signon,idle,parameters[userindex].c_str());
76         }
77         else
78         {
79                 /* no such nick/channel */
80                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), !parameters[userindex].empty() ? parameters[userindex].c_str() : "*");
81                 user->WriteNumeric(318, "%s %s :End of /WHOIS list.",user->nick.c_str(), parameters[userindex].empty() ? parameters[userindex].c_str() : "*");
82                 return CMD_FAILURE;
83         }
84
85         return CMD_SUCCESS;
86 }
87
88
89
90 COMMAND_INIT(CommandWhois)