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/>.
23 #include "treeserver.h"
24 #include "protocolinterface.h"
27 * For documentation on this class, see include/protocol.h.
30 void SpanningTreeProtocolInterface::GetServerList(ProtoServerList &sl)
33 for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
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;
47 bool SpanningTreeProtocolInterface::SendEncapsulatedData(const parameterlist &encap)
49 if (encap[0].find_first_of("*?") != std::string::npos)
51 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
54 return Utils->DoOneToOne(ServerInstance->Config->GetSID(), "ENCAP", encap, encap[0]);
57 void SpanningTreeProtocolInterface::SendMetaData(Extensible* target, const std::string &key, const std::string &data)
61 User* u = dynamic_cast<User*>(target);
62 Channel* c = dynamic_cast<Channel*>(target);
64 params.push_back(u->uuid);
67 params.push_back(c->name);
68 params.push_back(ConvToStr(c->age));
71 params.push_back("*");
73 params.push_back(key);
74 params.push_back(":" + data);
76 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",params);
79 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
83 params.push_back(channel->name);
84 params.push_back(ConvToStr(channel->age));
85 params.push_back(ConvToStr(ServerInstance->Time()));
86 params.push_back(ServerInstance->Config->ServerName);
87 params.push_back(":" + topic);
89 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params);
92 void SpanningTreeProtocolInterface::SendMode(const std::string &target, const parameterlist &modedata, const std::vector<TranslateType> &translate)
98 ServerInstance->Parser->TranslateUIDs(translate, modedata, outdata);
100 std::string uidtarget;
101 ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget);
103 parameterlist outlist;
104 outlist.push_back(uidtarget);
105 outlist.push_back(outdata);
107 User* a = ServerInstance->FindNick(uidtarget);
110 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",outlist);
115 Channel* c = ServerInstance->FindChan(target);
118 outlist.insert(outlist.begin() + 1, ConvToStr(c->age));
119 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",outlist);
124 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
127 p.push_back(snomask);
128 p.push_back(":" + text);
129 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
132 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
135 p.push_back(target->uuid);
136 p.push_back(":" + rawline);
137 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
140 void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text)
143 Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "PRIVMSG");
146 void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text)
149 Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "NOTICE");
152 void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text)
155 p.push_back(target->uuid);
156 p.push_back(":" + text);
157 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PRIVMSG", p, target->server);
160 void SpanningTreeProtocolInterface::SendUserNotice(User* target, const std::string &text)
163 p.push_back(target->uuid);
164 p.push_back(":" + text);
165 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "NOTICE", p, target->server);