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