2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012-2015 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
8 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
11 * This file is part of InspIRCd. InspIRCd is free software: you can
12 * redistribute it and/or modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation, version 2.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 CmdResult CommandIdle::HandleRemote(RemoteUser* issuer, Params& params)
32 * There are two forms of IDLE: request and reply. Requests have one parameter,
33 * replies have more than one.
35 * If this is a request, 'issuer' did a /whois and its server wants to learn the
36 * idle time of the user in params[0].
38 * If this is a reply, params[0] is the user who did the whois and params.back() is
39 * the number of seconds 'issuer' has been idle.
42 User* target = ServerInstance->FindUUID(params[0]);
43 if ((!target) || (target->registered != REG_ALL))
46 LocalUser* localtarget = IS_LOCAL(target);
49 // Forward to target's server
53 if (params.size() >= 2)
55 ServerInstance->Parser.CallHandler("WHOIS", params, issuer);
59 // A server is asking us the idle time of our user
61 if (localtarget->idle_lastmsg >= ServerInstance->Time())
62 // Possible case when our clock ticked backwards
65 idle = ((unsigned int) (ServerInstance->Time() - localtarget->idle_lastmsg));
67 CmdBuilder reply(target, "IDLE");
68 reply.push(issuer->uuid);
69 reply.push(ConvToStr(target->signon));
70 reply.push(ConvToStr(idle));
71 reply.Unicast(issuer);