]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/idle.cpp
m_spanningtree Remove duplicate code for sending channel messages from RouteCommand()
[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::Handle(User* issuer, std::vector<std::string>& params)
25 {
26         /* If this is a request, this user did the /whois
27          * If this is a reply, this user's information is in params[1] and params[2]
28          */
29         if (IS_SERVER(issuer))
30                 return CMD_FAILURE;
31
32         /* If this is a request, this is the user whose idle information was requested
33          * If this is a reply, this user did the /whois
34          */
35         User* target = ServerInstance->FindUUID(params[0]);
36         if ((!target) || (IS_SERVER(target)))
37                 return CMD_FAILURE;
38
39         LocalUser* localtarget = IS_LOCAL(target);
40         if (!localtarget)
41         {
42                 // Forward to target's server
43                 return CMD_SUCCESS;
44         }
45
46         if (params.size() >= 2)
47         {
48                 ServerInstance->Parser->CallHandler("WHOIS", params, issuer);
49         }
50         else
51         {
52                 // A server is asking us the idle time of our user
53                 unsigned int idle;
54                 if (localtarget->idle_lastmsg >= ServerInstance->Time())
55                         // Possible case when our clock ticked backwards
56                         idle = 0;
57                 else
58                         idle = ((unsigned int) (ServerInstance->Time() - localtarget->idle_lastmsg));
59
60                 parameterlist reply;
61                 reply.push_back(issuer->uuid);
62                 reply.push_back(ConvToStr(target->signon));
63                 reply.push_back(ConvToStr(idle));
64                 Utils->DoOneToOne(params[0], "IDLE", reply, issuer->server);
65         }
66
67         return CMD_SUCCESS;
68 }