]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/pong.cpp
Fix total mess of makefile dependency macros (all depending on stuff they dont NEED...
[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/treesocket.h"
27
28 /* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
29
30 bool TreeSocket::LocalPong(const std::string &prefix, std::deque<std::string> &params)
31 {
32         if (params.size() < 1)
33                 return true;
34
35         if (params.size() == 1)
36         {
37                 TreeServer* ServerSource = Utils->FindServer(prefix);
38                 if (ServerSource)
39                 {
40                         ServerSource->SetPingFlag();
41                         timeval t;
42                         gettimeofday(&t, NULL);
43                         long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
44                         ServerSource->rtt = ts - ServerSource->LastPingMsec;
45                 }
46         }
47         else
48         {
49                 std::string forwardto = params[1];
50                 if (forwardto == Instance->Config->GetSID() || forwardto == Instance->Config->ServerName)
51                 {
52                         /*
53                          * this is a PONG for us
54                          * if the prefix is a user, check theyre local, and if they are,
55                          * dump the PONG reply back to their fd. If its a server, do nowt.
56                          * Services might want to send these s->s, but we dont need to yet.
57                          */
58                         User* u = this->Instance->FindNick(prefix);
59                         if (u)
60                         {
61                                 u->WriteServ("PONG %s %s",params[0].c_str(),params[1].c_str());
62                         }
63
64                         TreeServer *ServerSource = Utils->FindServer(params[0]);
65
66                         if (ServerSource)
67                         {
68                                 timeval t;
69                                 gettimeofday(&t, NULL);
70                                 long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
71                                 ServerSource->rtt = ts - ServerSource->LastPingMsec;
72                                 ServerSource->SetPingFlag();
73                         }
74                 }
75                 else
76                 {
77                         // not for us, pass it on :)
78                         Utils->DoOneToOne(prefix,"PONG",params,forwardto);
79                 }
80         }
81
82         return true;
83 }
84