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(ServerList& sl)
32 for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
35 ps.servername = i->second->GetName();
36 TreeServer* s = i->second->GetParent();
37 ps.parentname = s ? s->GetName() : "";
38 ps.usercount = i->second->UserCount;
39 ps.opercount = i->second->OperCount;
40 ps.gecos = i->second->GetDesc();
41 ps.latencyms = i->second->rtt;
46 bool SpanningTreeProtocolInterface::SendEncapsulatedData(const parameterlist &encap)
48 if (encap[0].find_first_of("*?") != std::string::npos)
50 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
53 return Utils->DoOneToOne(ServerInstance->Config->GetSID(), "ENCAP", encap, encap[0]);
56 void SpanningTreeProtocolInterface::SendMetaData(Extensible* target, const std::string &key, const std::string &data)
60 User* u = dynamic_cast<User*>(target);
61 Channel* c = dynamic_cast<Channel*>(target);
63 params.push_back(u->uuid);
66 params.push_back(c->name);
67 params.push_back(ConvToStr(c->age));
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(channel->age));
84 params.push_back(ConvToStr(ServerInstance->Time()));
85 params.push_back(ServerInstance->Config->ServerName);
86 params.push_back(":" + topic);
88 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params);
91 void SpanningTreeProtocolInterface::SendMode(User* source, User* u, Channel* c, const parameterlist& modedata, const std::vector<TranslateType>& translate)
97 if (u->registered != REG_ALL)
100 params.push_back(u->uuid);
101 params.insert(params.end(), modedata.begin(), modedata.end());
102 Utils->DoOneToMany(source->uuid, "MODE", params);
106 params.push_back(c->name);
107 params.push_back(ConvToStr(c->age));
108 params.push_back(CommandParser::TranslateUIDs(translate, modedata));
109 Utils->DoOneToMany(source->uuid, "FMODE", params);
113 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
116 p.push_back(snomask);
117 p.push_back(":" + text);
118 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
121 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
124 p.push_back(target->uuid);
125 p.push_back(":" + rawline);
126 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
129 void SpanningTreeProtocolInterface::SendMessage(Channel* target, char status, const std::string& text, MessageType msgtype)
131 const char* cmd = (msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE");
133 Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, cmd);
136 void SpanningTreeProtocolInterface::SendMessage(User* target, const std::string& text, MessageType msgtype)
138 const char* cmd = (msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE");
140 p.push_back(target->uuid);
141 p.push_back(":" + text);
142 Utils->DoOneToOne(ServerInstance->Config->GetSID(), cmd, p, target->server);