]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_whois.cpp
Merge pull request #1018 from SaberUK/insp20+hidekills
[user/henk/code/inspircd.git] / src / commands / cmd_whois.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
6  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7  *
8  * This file is part of InspIRCd.  InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21
22 #include "inspircd.h"
23
24 /** Handle /WHOIS. These command handlers can be reloaded by the core,
25  * and handle basic RFC1459 commands. Commands within modules work
26  * the same way, however, they can be fully unloaded, where these
27  * may not.
28  */
29 class CommandWhois : public Command
30 {
31  public:
32         /** Constructor for whois.
33          */
34         CommandWhois ( Module* parent) : Command(parent,"WHOIS",1) { Penalty = 2; syntax = "<nick>{,<nick>}"; }
35         /** Handle command.
36          * @param parameters The parameters to the comamnd
37          * @param pcnt The number of parameters passed to teh command
38          * @param user The user issuing the command
39          * @return A value from CmdResult to indicate command success or failure.
40          */
41         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
42 };
43
44
45 CmdResult CommandWhois::Handle (const std::vector<std::string>& parameters, User *user)
46 {
47         User *dest;
48         int userindex = 0;
49         unsigned long idle = 0, signon = 0;
50
51         if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
52                 return CMD_SUCCESS;
53
54
55         /*
56          * If 2 paramters are specified (/whois nick nick), ignore the first one like spanningtree
57          * does, and use the second one, otherwise, use the only paramter. -- djGrrr
58          */
59         if (parameters.size() > 1)
60                 userindex = 1;
61
62         if (IS_LOCAL(user))
63                 dest = ServerInstance->FindNickOnly(parameters[userindex]);
64         else
65                 dest = ServerInstance->FindNick(parameters[userindex]);
66
67         if ((dest) && (dest->registered == REG_ALL))
68         {
69                 /*
70                  * Okay. Umpteenth attempt at doing this, so let's re-comment...
71                  * For local users (/w localuser), we show idletime if hidewhois is disabled
72                  * For local users (/w localuser localuser), we always show idletime, hence parameters.size() > 1 check.
73                  * For remote users (/w remoteuser), we do NOT show idletime
74                  * For remote users (/w remoteuser remoteuser), spanningtree will handle calling do_whois, so we can ignore this case.
75                  * Thanks to djGrrr for not being impatient while I have a crap day coding. :p -- w00t
76                  */
77                 if (IS_LOCAL(dest) && (ServerInstance->Config->HideWhoisServer.empty() || parameters.size() > 1))
78                 {
79                         idle = labs((long)((dest->idle_lastmsg)-ServerInstance->Time()));
80                         signon = dest->signon;
81                 }
82
83                 ServerInstance->DoWhois(user,dest,signon,idle,parameters[userindex].c_str());
84         }
85         else
86         {
87                 /* no such nick/channel */
88                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), !parameters[userindex].empty() ? parameters[userindex].c_str() : "*");
89                 user->WriteNumeric(318, "%s %s :End of /WHOIS list.",user->nick.c_str(), !parameters[userindex].empty() ? parameters[userindex].c_str() : "*");
90                 return CMD_FAILURE;
91         }
92
93         return CMD_SUCCESS;
94 }
95
96
97
98 COMMAND_INIT(CommandWhois)