2 #include "m_spanningtree/main.h"
3 #include "m_spanningtree/utils.h"
4 #include "m_spanningtree/treeserver.h"
5 #include "m_spanningtree/treesocket.h"
6 #include "m_spanningtree/protocolinterface.h"
8 void SpanningTreeProtocolInterface::GetServerList(ProtoServerList &sl)
11 for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
14 ps.servername = i->second->GetName();
15 TreeServer* s = i->second->GetParent();
16 ps.parentname = s ? s->GetName() : ServerInstance->Config->ServerName;
17 ps.usercount = i->second->GetUserCount();
18 ps.opercount = i->second->GetOperCount();
19 ps.latencyms = i->second->rtt;
24 void SpanningTreeProtocolInterface::SendEncapsulatedData(parameterlist &encap)
26 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
29 void SpanningTreeProtocolInterface::SendMetaData(void* target, int type, const std::string &key, const std::string &data)
36 params.push_back(((User*)target)->uuid);
39 params.push_back(((Channel*)target)->name);
42 params.push_back("*");
45 params.push_back(key);
46 params.push_back(":" + data);
48 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",params);
51 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
55 params.push_back(channel->name);
56 params.push_back(ConvToStr(ServerInstance->Time()));
57 params.push_back(ServerInstance->Config->ServerName);
58 params.push_back(":" + topic);
60 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params);
63 void SpanningTreeProtocolInterface::SendMode(const std::string &target, parameterlist &modedata)
70 /* Warning: in-place translation is only safe for type TR_NICK */
71 for (size_t n = 0; n < modedata.size(); n++)
73 ServerInstance->Parser->TranslateUIDs(TR_NICK, modedata[n], outdata);
74 modedata[n] = outdata;
77 std::string uidtarget;
78 ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget);
79 modedata.insert(modedata.begin(), uidtarget);
81 User* a = ServerInstance->FindNick(uidtarget);
84 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",modedata);
89 Channel* c = ServerInstance->FindChan(target);
92 modedata.insert(modedata.begin() + 1, ConvToStr(c->age));
93 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",modedata);
98 void SpanningTreeProtocolInterface::SendModeNotice(const std::string &modes, const std::string &text)
102 p.push_back(":" + text);
103 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "MODENOTICE", p);
106 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
109 p.push_back(snomask);
110 p.push_back(":" + text);
111 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
114 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
117 p.push_back(target->uuid);
118 p.push_back(rawline);
119 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
122 void SpanningTreeProtocolInterface::SendChannel(Channel* target, char status, const std::string &text)
124 std::string cname = target->name;
126 cname = status + cname;
129 Utils->GetListOfServersForChannel(target,list,status,exempt_list);
130 for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
132 TreeSocket* Sock = i->second->GetSocket();
134 Sock->WriteLine(text);
139 void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text)
141 SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" PRIVMSG "+target->name+" :"+text);
144 void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text)
146 SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" NOTICE "+target->name+" :"+text);
149 void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text)
151 TreeServer* serv = Utils->FindServer(target->server);
154 TreeSocket* sock = serv->GetSocket();
157 sock->WriteLine(":" + ServerInstance->Config->GetSID() + " PRIVMSG " + target->nick + " :"+text);
162 void SpanningTreeProtocolInterface::SendUserNotice(User* target, const std::string &text)
164 TreeServer* serv = Utils->FindServer(target->server);
167 TreeSocket* sock = serv->GetSocket();
170 sock->WriteLine(":" + ServerInstance->Config->GetSID() + " NOTICE " + target->nick + " :"+text);