2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
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.
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
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/>.
24 #include "treeserver.h"
25 #include "treesocket.h"
26 #include "protocolinterface.h"
29 * For documentation on this class, see include/protocol.h.
32 void SpanningTreeProtocolInterface::GetServerList(ProtoServerList &sl)
35 for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
38 ps.servername = i->second->GetName();
39 TreeServer* s = i->second->GetParent();
40 ps.parentname = s ? s->GetName() : "";
41 ps.usercount = i->second->UserCount;
42 ps.opercount = i->second->OperCount;
43 ps.gecos = i->second->GetDesc();
44 ps.latencyms = i->second->rtt;
49 bool SpanningTreeProtocolInterface::SendEncapsulatedData(const parameterlist &encap)
51 if (encap[0].find_first_of("*?") != std::string::npos)
53 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
56 return Utils->DoOneToOne(ServerInstance->Config->GetSID(), "ENCAP", encap, encap[0]);
59 void SpanningTreeProtocolInterface::SendMetaData(Extensible* target, const std::string &key, const std::string &data)
63 User* u = dynamic_cast<User*>(target);
64 Channel* c = dynamic_cast<Channel*>(target);
66 params.push_back(u->uuid);
68 params.push_back(c->name);
70 params.push_back("*");
72 params.push_back(key);
73 params.push_back(":" + data);
75 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",params);
78 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
82 params.push_back(channel->name);
83 params.push_back(ConvToStr(ServerInstance->Time()));
84 params.push_back(ServerInstance->Config->ServerName);
85 params.push_back(":" + topic);
87 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params);
90 void SpanningTreeProtocolInterface::SendMode(const std::string &target, const parameterlist &modedata, const std::vector<TranslateType> &translate)
96 ServerInstance->Parser->TranslateUIDs(translate, modedata, outdata);
98 std::string uidtarget;
99 ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget);
101 parameterlist outlist;
102 outlist.push_back(uidtarget);
103 outlist.push_back(outdata);
105 User* a = ServerInstance->FindNick(uidtarget);
108 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",outlist);
113 Channel* c = ServerInstance->FindChan(target);
116 outlist.insert(outlist.begin() + 1, ConvToStr(c->age));
117 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",outlist);
122 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
125 p.push_back(snomask);
126 p.push_back(":" + text);
127 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
130 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
133 p.push_back(target->uuid);
134 p.push_back(":" + rawline);
135 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
138 void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text)
141 Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "PRIVMSG");
144 void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text)
147 Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "NOTICE");
150 void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text)
153 p.push_back(target->uuid);
154 p.push_back(":" + text);
155 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PRIVMSG", p, target->server);
158 void SpanningTreeProtocolInterface::SendUserNotice(User* target, const std::string &text)
161 p.push_back(target->uuid);
162 p.push_back(":" + text);
163 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "NOTICE", p, target->server);