]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/idle.cpp
Release 2.0.13
[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         User* u = ServerInstance->FindNick(prefix);
35         if (u)
36         {
37                 // an incoming request
38                 if (params.size() == 1)
39                 {
40                         User* x = ServerInstance->FindNick(params[0]);
41                         if ((x) && (IS_LOCAL(x)))
42                         {
43                                 long idle = abs((long)((x->idle_lastmsg) - ServerInstance->Time()));
44                                 parameterlist par;
45                                 par.push_back(prefix);
46                                 par.push_back(ConvToStr(x->signon));
47                                 par.push_back(ConvToStr(idle));
48                                 // ours, we're done, pass it BACK
49                                 Utils->DoOneToOne(params[0], "IDLE", par, u->server);
50                         }
51                         else
52                         {
53                                 // not ours pass it on
54                                 if (x)
55                                         Utils->DoOneToOne(prefix, "IDLE", params, x->server);
56                         }
57                 }
58                 else if (params.size() == 3)
59                 {
60                         std::string who_did_the_whois = params[0];
61                         User* who_to_send_to = ServerInstance->FindNick(who_did_the_whois);
62                         if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
63                         {
64                                 // an incoming reply to a whois we sent out
65                                 std::string nick_whoised = prefix;
66                                 unsigned long signon = atoi(params[1].c_str());
67                                 unsigned long idle = atoi(params[2].c_str());
68                                 if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
69                                 {
70                                         ServerInstance->DoWhois(who_to_send_to, u, signon, idle, nick_whoised.c_str());
71                                 }
72                         }
73                         else
74                         {
75                                 // not ours, pass it on
76                                 if (who_to_send_to)
77                                         Utils->DoOneToOne(prefix, "IDLE", params, who_to_send_to->server);
78                         }
79                 }
80         }
81         return true;
82 }
83
84