]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/pong.cpp
NEVER use the two-param assign unless you want your string padding to len bytes with \0!
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / pong.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::LocalPong(const std::string &prefix, std::deque<std::string> &params)
34 {
35         if (params.size() < 1)
36                 return true;
37
38         if (params.size() == 1)
39         {
40                 TreeServer* ServerSource = Utils->FindServer(prefix);
41                 if (ServerSource)
42                 {
43                         ServerSource->SetPingFlag();
44                         timeval t;
45                         gettimeofday(&t, NULL);
46                         long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
47                         ServerSource->rtt = ts - ServerSource->LastPingMsec;
48                 }
49         }
50         else
51         {
52                 std::string forwardto = params[1];
53                 if (forwardto == Instance->Config->GetSID() || forwardto == Instance->Config->ServerName)
54                 {
55                         /*
56                          * this is a PONG for us
57                          * if the prefix is a user, check theyre local, and if they are,
58                          * dump the PONG reply back to their fd. If its a server, do nowt.
59                          * Services might want to send these s->s, but we dont need to yet.
60                          */
61                         User* u = this->Instance->FindNick(prefix);
62                         if (u)
63                         {
64                                 u->WriteServ("PONG %s %s",params[0].c_str(),params[1].c_str());
65                         }
66
67                         TreeServer *ServerSource = Utils->FindServer(params[0]);
68
69                         if (ServerSource)
70                         {
71                                 timeval t;
72                                 gettimeofday(&t, NULL);
73                                 long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
74                                 ServerSource->rtt = ts - ServerSource->LastPingMsec;
75                                 ServerSource->SetPingFlag();
76                         }
77                 }
78                 else
79                 {
80                         // not for us, pass it on :)
81                         Utils->DoOneToOne(prefix,"PONG",params,forwardto);
82                 }
83         }
84
85         return true;
86 }
87