]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/whois.cpp
8adf750bcf48c483731403ec70824684b25c6f8c
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / whois.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 "commands/cmd_whois.h"
16 #include "commands/cmd_stats.h"
17 #include "socket.h"
18 #include "wildcard.h"
19 #include "xline.h"
20 #include "transport.h"
21 #include "socketengine.h"
22
23 #include "m_spanningtree/main.h"
24 #include "m_spanningtree/utils.h"
25 #include "m_spanningtree/treeserver.h"
26 #include "m_spanningtree/link.h"
27 #include "m_spanningtree/treesocket.h"
28 #include "m_spanningtree/resolvers.h"
29 #include "m_spanningtree/handshaketimer.h"
30
31 /* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */
32
33 bool TreeSocket::Whois(const std::string &prefix, std::deque<std::string> &params)
34 {
35         if (params.size() < 1)
36                 return true;
37         User* u = this->Instance->FindNick(prefix);
38         if (u)
39         {
40                 // an incoming request
41                 if (params.size() == 1)
42                 {
43                         User* x = this->Instance->FindNick(params[0]);
44                         if ((x) && (IS_LOCAL(x)))
45                         {
46                                 User* x = this->Instance->FindNick(params[0]);
47                                 char signon[MAXBUF];
48                                 char idle[MAXBUF];
49                                 snprintf(signon, MAXBUF, "%lu", (unsigned long)x->signon);
50                                 snprintf(idle, MAXBUF, "%lu", (unsigned long)abs((x->idle_lastmsg) - Instance->Time(true)));
51                                 std::deque<std::string> par;
52                                 par.push_back(prefix);
53                                 par.push_back(signon);
54                                 par.push_back(idle);
55                                 // ours, we're done, pass it BACK
56                                 Utils->DoOneToOne(params[0], "IDLE", par, u->server);
57                         }
58                         else
59                         {
60                                 // not ours pass it on
61                                 if (x)
62                                         Utils->DoOneToOne(prefix, "IDLE", params, x->server);
63                         }
64                 }
65                 else if (params.size() == 3)
66                 {
67                         std::string who_did_the_whois = params[0];
68                         User* who_to_send_to = this->Instance->FindNick(who_did_the_whois);
69                         if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
70                         {
71                                 // an incoming reply to a whois we sent out
72                                 std::string nick_whoised = prefix;
73                                 unsigned long signon = atoi(params[1].c_str());
74                                 unsigned long idle = atoi(params[2].c_str());
75                                 if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
76                                 {
77                                         do_whois(this->Instance, who_to_send_to, u, signon, idle, nick_whoised.c_str());
78                                 }
79                         }
80                         else
81                         {
82                                 // not ours, pass it on
83                                 if (who_to_send_to)
84                                         Utils->DoOneToOne(prefix, "IDLE", params, who_to_send_to->server);
85                         }
86                 }
87         }
88         return true;
89 }
90