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