]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/override_stats.cpp
4bde25fbe60c05e806c6617199b33f64c816dabd
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / override_stats.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 /* $ModDesc: Provides a spanning tree server link protocol */
15
16 #include "inspircd.h"
17 #include "commands/cmd_whois.h"
18 #include "commands/cmd_stats.h"
19 #include "socket.h"
20 #include "xline.h"
21 #include "../transport.h"
22
23 #include "main.h"
24 #include "utils.h"
25 #include "treeserver.h"
26 #include "link.h"
27 #include "treesocket.h"
28
29 /* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */
30
31 int ModuleSpanningTree::HandleStats(const std::vector<std::string>& parameters, User* user)
32 {
33         if (parameters.size() > 1)
34         {
35                 if (InspIRCd::Match(ServerInstance->Config->ServerName, parameters[1]))
36                         return 0;
37
38                 /* Remote STATS, the server is within the 2nd parameter */
39                 std::deque<std::string> params;
40                 params.push_back(parameters[0]);
41                 params.push_back(parameters[1]);
42                 /* Send it out remotely, generate no reply yet */
43
44                 TreeServer* s = Utils->FindServerMask(parameters[1]);
45                 if (s)
46                 {
47                         params[1] = s->GetName();
48                         Utils->DoOneToOne(user->uuid, "STATS", params, s->GetName());
49                 }
50                 else
51                 {
52                         user->WriteServ( "402 %s %s :No such server", user->nick.c_str(), parameters[1].c_str());
53                 }
54                 return 1;
55         }
56         return 0;
57 }
58
59 int ModuleSpanningTree::OnStats(char statschar, User* user, string_list &results)
60 {
61         if ((statschar == 'c') || (statschar == 'n'))
62         {
63                 for (unsigned int i = 0; i < Utils->LinkBlocks.size(); i++)
64                 {
65                         results.push_back(std::string(ServerInstance->Config->ServerName)+" 213 "+user->nick+" "+statschar+" *@"+(Utils->LinkBlocks[i].HiddenFromStats ? "<hidden>" : Utils->LinkBlocks[i].IPAddr)+" * "+Utils->LinkBlocks[i].Name.c_str()+" "+ConvToStr(Utils->LinkBlocks[i].Port)+" "+(Utils->LinkBlocks[i].Hook.empty() ? "plaintext" : Utils->LinkBlocks[i].Hook)+" "+(Utils->LinkBlocks[i].AutoConnect ? 'a': '-')+'s');
66                         if (statschar == 'c')
67                                 results.push_back(std::string(ServerInstance->Config->ServerName)+" 244 "+user->nick+" H * * "+Utils->LinkBlocks[i].Name.c_str());
68                 }
69                 return 1;
70         }
71
72         if (statschar == 'p')
73         {
74                 /* show all server ports, after showing client ports. -- w00t */
75
76                 for (unsigned int i = 0; i < Utils->Bindings.size(); i++)
77                 {
78                         std::string ip = Utils->Bindings[i]->GetIP();
79                         if (ip.empty())
80                                 ip = "*";
81
82                         std::string transport("plaintext");
83                         if (Utils->Bindings[i]->GetIOHook())
84                                 transport = BufferedSocketNameRequest(this, Utils->Bindings[i]->GetIOHook()).Send();
85
86                         results.push_back(ConvToStr(ServerInstance->Config->ServerName) + " 249 "+user->nick+" :" + ip + ":" + ConvToStr(Utils->Bindings[i]->GetPort())+
87                                 " (server, " + transport + ")");
88                 }
89         }
90         return 0;
91 }
92