2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
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
29 class CommandWhois : public Command
32 /** Constructor for whois.
34 CommandWhois ( Module* parent) : Command(parent,"WHOIS",1) { Penalty = 2; syntax = "<nick>{,<nick>}"; }
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.
41 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
45 CmdResult CommandWhois::Handle (const std::vector<std::string>& parameters, User *user)
49 unsigned long idle = 0, signon = 0;
51 if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
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
59 if (parameters.size() > 1)
63 dest = ServerInstance->FindNickOnly(parameters[userindex]);
65 dest = ServerInstance->FindNick(parameters[userindex]);
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
77 if (IS_LOCAL(dest) && (ServerInstance->Config->HideWhoisServer.empty() || parameters.size() > 1))
79 idle = abs((long)((dest->idle_lastmsg)-ServerInstance->Time()));
80 signon = dest->signon;
83 ServerInstance->DoWhois(user,dest,signon,idle,parameters[userindex].c_str());
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() : "*");
98 COMMAND_INIT(CommandWhois)