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