2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2011 Adam <Adam@anope.org>
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.
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
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/>.
23 #include "socketengine.h"
27 #include "treeserver.h"
28 #include "treesocket.h"
30 bool TreeSocket::Whois(const std::string &prefix, parameterlist ¶ms)
32 if (params.size() < 1)
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]
38 User* issuer = ServerInstance->FindUUID(prefix);
39 if ((!issuer) || (IS_SERVER(issuer)))
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
45 User* target = ServerInstance->FindUUID(params[0]);
46 if ((!target) || (IS_SERVER(target)))
49 LocalUser* localtarget = IS_LOCAL(target);
52 // Forward to target's server
53 Utils->DoOneToOne(prefix, "IDLE", params, target->server);
57 if (params.size() >= 2)
59 ServerInstance->Parser->CallHandler("WHOIS", params, issuer);
63 // A server is asking us the idle time of our user
65 if (localtarget->idle_lastmsg >= ServerInstance->Time())
66 // Possible case when our clock ticked backwards
69 idle = ((unsigned int) (localtarget->idle_lastmsg - ServerInstance->Time()));
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);