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