]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/protocolinterface.cpp
Rename `<link:ssl>` to `<link:sslprofile>`.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / protocolinterface.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2018 Matt Schatz <genius3000@g3k.solutions>
6  *   Copyright (C) 2012-2014 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
10  *   Copyright (C) 2008 Craig Edwards <brain@inspircd.org>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27 #include "utils.h"
28 #include "treeserver.h"
29 #include "protocolinterface.h"
30 #include "commands.h"
31
32 /*
33  * For documentation on this class, see include/protocol.h.
34  */
35
36 void SpanningTreeProtocolInterface::GetServerList(ServerList& sl)
37 {
38         for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
39         {
40                 ServerInfo ps;
41                 ps.servername = i->second->GetName();
42                 TreeServer* s = i->second->GetParent();
43                 ps.parentname = s ? s->GetName() : "";
44                 ps.usercount = i->second->UserCount;
45                 ps.opercount = i->second->OperCount;
46                 ps.description = i->second->GetDesc();
47                 ps.latencyms = i->second->rtt;
48                 sl.push_back(ps);
49         }
50 }
51
52 bool SpanningTreeProtocolInterface::SendEncapsulatedData(const std::string& targetmask, const std::string& cmd, const CommandBase::Params& params, User* source)
53 {
54         if (!source)
55                 source = ServerInstance->FakeClient;
56
57         CmdBuilder encap(source, "ENCAP");
58
59         // Are there any wildcards in the target string?
60         if (targetmask.find_first_of("*?") != std::string::npos)
61         {
62                 // Yes, send the target string as-is; servers will decide whether or not it matches them
63                 encap.push(targetmask).push(cmd).insert(params).Broadcast();
64         }
65         else
66         {
67                 // No wildcards which means the target string has to be the name of a known server
68                 TreeServer* server = Utils->FindServer(targetmask);
69                 if (!server)
70                         return false;
71
72                 // Use the SID of the target in the message instead of the server name
73                 encap.push(server->GetId()).push(cmd).insert(params).Unicast(server->ServerUser);
74         }
75
76         return true;
77 }
78
79 void SpanningTreeProtocolInterface::BroadcastEncap(const std::string& cmd, const CommandBase::Params& params, User* source, User* omit)
80 {
81         if (!source)
82                 source = ServerInstance->FakeClient;
83
84         // If omit is non-NULL we pass the route belonging to the user to Forward(),
85         // otherwise we pass NULL, which is equivalent to Broadcast()
86         TreeServer* server = (omit ? TreeServer::Get(omit)->GetRoute() : NULL);
87         CmdBuilder(source, "ENCAP * ").push_raw(cmd).insert(params).Forward(server);
88 }
89
90 void SpanningTreeProtocolInterface::SendMetaData(User* u, const std::string& key, const std::string& data)
91 {
92         CommandMetadata::Builder(u, key, data).Broadcast();
93 }
94
95 void SpanningTreeProtocolInterface::SendMetaData(Channel* c, const std::string& key, const std::string& data)
96 {
97         CommandMetadata::Builder(c, key, data).Broadcast();
98 }
99
100 void SpanningTreeProtocolInterface::SendMetaData(const std::string& key, const std::string& data)
101 {
102         CommandMetadata::Builder(key, data).Broadcast();
103 }
104
105 void SpanningTreeProtocolInterface::Server::SendMetaData(const std::string& key, const std::string& data)
106 {
107         sock->WriteLine(CommandMetadata::Builder(key, data));
108 }
109
110 void SpanningTreeProtocolInterface::SendSNONotice(char snomask, const std::string &text)
111 {
112         CmdBuilder("SNONOTICE").push(snomask).push_last(text).Broadcast();
113 }
114
115 void SpanningTreeProtocolInterface::SendMessage(Channel* target, char status, const std::string& text, MessageType msgtype)
116 {
117         const char* cmd = (msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE");
118         CUList exempt_list;
119         ClientProtocol::TagMap tags;
120         Utils->SendChannelMessage(ServerInstance->FakeClient, target, text, status, tags, exempt_list, cmd);
121 }
122
123 void SpanningTreeProtocolInterface::SendMessage(User* target, const std::string& text, MessageType msgtype)
124 {
125         CmdBuilder p(msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE");
126         p.push(target->uuid);
127         p.push_last(text);
128         p.Unicast(target);
129 }