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