]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/whois.cpp
Merge remote/local MODULES output
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / whois.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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 "../transport.h"
18 #include "socketengine.h"
19
20 #include "main.h"
21 #include "utils.h"
22 #include "treeserver.h"
23 #include "treesocket.h"
24
25 /* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
26
27 bool TreeSocket::Whois(const std::string &prefix, parameterlist &params)
28 {
29         if (params.size() < 1)
30                 return true;
31         User* u = ServerInstance->FindNick(prefix);
32         if (u)
33         {
34                 // an incoming request
35                 if (params.size() == 1)
36                 {
37                         User* x = ServerInstance->FindNick(params[0]);
38                         if ((x) && (IS_LOCAL(x)))
39                         {
40                                 char signon[MAXBUF];
41                                 char idle[MAXBUF];
42                                 snprintf(signon, MAXBUF, "%lu", (unsigned long)x->signon);
43                                 snprintf(idle, MAXBUF, "%lu", (unsigned long)abs((long)((x->idle_lastmsg) - ServerInstance->Time())));
44                                 parameterlist par;
45                                 par.push_back(prefix);
46                                 par.push_back(signon);
47                                 par.push_back(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