2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
28 #include "treeserver.h"
29 #include "protocolinterface.h"
33 * For documentation on this class, see include/protocol.h.
36 void SpanningTreeProtocolInterface::GetServerList(ServerList& sl)
38 for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
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;
52 bool SpanningTreeProtocolInterface::SendEncapsulatedData(const std::string& targetmask, const std::string& cmd, const CommandBase::Params& params, User* source)
55 source = ServerInstance->FakeClient;
57 CmdBuilder encap(source, "ENCAP");
59 // Are there any wildcards in the target string?
60 if (targetmask.find_first_of("*?") != std::string::npos)
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();
67 // No wildcards which means the target string has to be the name of a known server
68 TreeServer* server = Utils->FindServer(targetmask);
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);
79 void SpanningTreeProtocolInterface::BroadcastEncap(const std::string& cmd, const CommandBase::Params& params, User* source, User* omit)
82 source = ServerInstance->FakeClient;
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);
90 void SpanningTreeProtocolInterface::SendMetaData(User* u, const std::string& key, const std::string& data)
92 CommandMetadata::Builder(u, key, data).Broadcast();
95 void SpanningTreeProtocolInterface::SendMetaData(Channel* c, const std::string& key, const std::string& data)
97 CommandMetadata::Builder(c, key, data).Broadcast();
100 void SpanningTreeProtocolInterface::SendMetaData(const std::string& key, const std::string& data)
102 CommandMetadata::Builder(key, data).Broadcast();
105 void SpanningTreeProtocolInterface::Server::SendMetaData(const std::string& key, const std::string& data)
107 sock->WriteLine(CommandMetadata::Builder(key, data));
110 void SpanningTreeProtocolInterface::SendSNONotice(char snomask, const std::string &text)
112 CmdBuilder("SNONOTICE").push(snomask).push_last(text).Broadcast();
115 void SpanningTreeProtocolInterface::SendMessage(Channel* target, char status, const std::string& text, MessageType msgtype)
117 const char* cmd = (msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE");
119 ClientProtocol::TagMap tags;
120 Utils->SendChannelMessage(ServerInstance->FakeClient, target, text, status, tags, exempt_list, cmd);
123 void SpanningTreeProtocolInterface::SendMessage(User* target, const std::string& text, MessageType msgtype)
125 CmdBuilder p(msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE");
126 p.push(target->uuid);