]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/idle.cpp
1b020701be8ff0a35d3f98b325126ddaaaf58a63
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / idle.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2011 Adam <Adam@anope.org>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21 #include "utils.h"
22 #include "commands.h"
23
24 CmdResult CommandIdle::HandleRemote(RemoteUser* issuer, std::vector<std::string>& params)
25 {
26         /**
27          * There are two forms of IDLE: request and reply. Requests have one parameter,
28          * replies have more than one.
29          *
30          * If this is a request, 'issuer' did a /whois and its server wants to learn the
31          * idle time of the user in params[0].
32          *
33          * If this is a reply, params[0] is the user who did the whois and params.back() is
34          * the number of seconds 'issuer' has been idle.
35          */
36
37         User* target = ServerInstance->FindUUID(params[0]);
38         if ((!target) || (IS_SERVER(target) || (target->registered != REG_ALL)))
39                 return CMD_FAILURE;
40
41         LocalUser* localtarget = IS_LOCAL(target);
42         if (!localtarget)
43         {
44                 // Forward to target's server
45                 return CMD_SUCCESS;
46         }
47
48         if (params.size() >= 2)
49         {
50                 ServerInstance->Parser->CallHandler("WHOIS", params, issuer);
51         }
52         else
53         {
54                 // A server is asking us the idle time of our user
55                 unsigned int idle;
56                 if (localtarget->idle_lastmsg >= ServerInstance->Time())
57                         // Possible case when our clock ticked backwards
58                         idle = 0;
59                 else
60                         idle = ((unsigned int) (ServerInstance->Time() - localtarget->idle_lastmsg));
61
62                 CmdBuilder reply(params[0], "IDLE");
63                 reply.push_back(issuer->uuid);
64                 reply.push_back(ConvToStr(target->signon));
65                 reply.push_back(ConvToStr(idle));
66                 reply.Unicast(issuer);
67         }
68
69         return CMD_SUCCESS;
70 }