]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/whois.cpp
59dc839851a5ffafdfa7e581f8eebbde4fce6b03
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / whois.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "socket.h"
16 #include "xline.h"
17 #include "socketengine.h"
18
19 #include "main.h"
20 #include "utils.h"
21 #include "treeserver.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         User* u = ServerInstance->FindNick(prefix);
29         if (u)
30         {
31                 // an incoming request
32                 if (params.size() == 1)
33                 {
34                         User* x = ServerInstance->FindNick(params[0]);
35                         if ((x) && (IS_LOCAL(x)))
36                         {
37                                 long idle = abs((long)((x->idle_lastmsg) - ServerInstance->Time()));
38                                 parameterlist par;
39                                 par.push_back(prefix);
40                                 par.push_back(ConvToStr(x->signon));
41                                 par.push_back(ConvToStr(idle));
42                                 // ours, we're done, pass it BACK
43                                 Utils->DoOneToOne(params[0], "IDLE", par, u->server);
44                         }
45                         else
46                         {
47                                 // not ours pass it on
48                                 if (x)
49                                         Utils->DoOneToOne(prefix, "IDLE", params, x->server);
50                         }
51                 }
52                 else if (params.size() == 3)
53                 {
54                         std::string who_did_the_whois = params[0];
55                         User* who_to_send_to = ServerInstance->FindNick(who_did_the_whois);
56                         if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
57                         {
58                                 // an incoming reply to a whois we sent out
59                                 std::string nick_whoised = prefix;
60                                 unsigned long signon = atoi(params[1].c_str());
61                                 unsigned long idle = atoi(params[2].c_str());
62                                 if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
63                                 {
64                                         ServerInstance->DoWhois(who_to_send_to, u, signon, idle, nick_whoised.c_str());
65                                 }
66                         }
67                         else
68                         {
69                                 // not ours, pass it on
70                                 if (who_to_send_to)
71                                         Utils->DoOneToOne(prefix, "IDLE", params, who_to_send_to->server);
72                         }
73                 }
74         }
75         return true;
76 }
77
78