]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/idle.cpp
Add a CapReference class for the message-tags capability.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / idle.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
10  *
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.
14  *
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
18  * details.
19  *
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/>.
22  */
23
24
25 #include "inspircd.h"
26 #include "utils.h"
27 #include "commands.h"
28
29 CmdResult CommandIdle::HandleRemote(RemoteUser* issuer, Params& params)
30 {
31         /**
32          * There are two forms of IDLE: request and reply. Requests have one parameter,
33          * replies have more than one.
34          *
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].
37          *
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.
40          */
41
42         User* target = ServerInstance->FindUUID(params[0]);
43         if ((!target) || (target->registered != REG_ALL))
44                 return CMD_FAILURE;
45
46         LocalUser* localtarget = IS_LOCAL(target);
47         if (!localtarget)
48         {
49                 // Forward to target's server
50                 return CMD_SUCCESS;
51         }
52
53         if (params.size() >= 2)
54         {
55                 ServerInstance->Parser.CallHandler("WHOIS", params, issuer);
56         }
57         else
58         {
59                 // A server is asking us the idle time of our user
60                 unsigned int idle;
61                 if (localtarget->idle_lastmsg >= ServerInstance->Time())
62                         // Possible case when our clock ticked backwards
63                         idle = 0;
64                 else
65                         idle = ((unsigned int) (ServerInstance->Time() - localtarget->idle_lastmsg));
66
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);
72         }
73
74         return CMD_SUCCESS;
75 }