]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/whois.cpp
Send SVSNICKs during nick collision to prevent servers that do not fully implement...
[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://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 "xline.h"
19 #include "transport.h"
20 #include "socketengine.h"
21
22 #include "m_spanningtree/main.h"
23 #include "m_spanningtree/utils.h"
24 #include "m_spanningtree/treeserver.h"
25 #include "m_spanningtree/treesocket.h"
26
27 /* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
28
29 bool TreeSocket::Whois(const std::string &prefix, std::deque<std::string> &params)
30 {
31         if (params.size() < 1)
32                 return true;
33         User* u = this->ServerInstance->FindNick(prefix);
34         if (u)
35         {
36                 // an incoming request
37                 if (params.size() == 1)
38                 {
39                         User* x = this->ServerInstance->FindNick(params[0]);
40                         if ((x) && (IS_LOCAL(x)))
41                         {
42                                 char signon[MAXBUF];
43                                 char idle[MAXBUF];
44                                 snprintf(signon, MAXBUF, "%lu", (unsigned long)x->signon);
45                                 snprintf(idle, MAXBUF, "%lu", (unsigned long)abs((long)((x->idle_lastmsg) - ServerInstance->Time())));
46                                 std::deque<std::string> par;
47                                 par.push_back(prefix);
48                                 par.push_back(signon);
49                                 par.push_back(idle);
50                                 // ours, we're done, pass it BACK
51                                 Utils->DoOneToOne(params[0], "IDLE", par, u->server);
52                         }
53                         else
54                         {
55                                 // not ours pass it on
56                                 if (x)
57                                         Utils->DoOneToOne(prefix, "IDLE", params, x->server);
58                         }
59                 }
60                 else if (params.size() == 3)
61                 {
62                         std::string who_did_the_whois = params[0];
63                         User* who_to_send_to = this->ServerInstance->FindNick(who_did_the_whois);
64                         if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
65                         {
66                                 // an incoming reply to a whois we sent out
67                                 std::string nick_whoised = prefix;
68                                 unsigned long signon = atoi(params[1].c_str());
69                                 unsigned long idle = atoi(params[2].c_str());
70                                 if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
71                                 {
72                                         do_whois(this->ServerInstance, who_to_send_to, u, signon, idle, nick_whoised.c_str());
73                                 }
74                         }
75                         else
76                         {
77                                 // not ours, pass it on
78                                 if (who_to_send_to)
79                                         Utils->DoOneToOne(prefix, "IDLE", params, who_to_send_to->server);
80                         }
81                 }
82         }
83         return true;
84 }
85
86