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() : "";
17 ps.usercount = i->second->GetUserCount();
18 ps.opercount = i->second->GetOperCount();
19 ps.gecos = i->second->GetDesc();
20 ps.latencyms = i->second->rtt;
25 void SpanningTreeProtocolInterface::SendEncapsulatedData(parameterlist &encap)
27 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
30 void SpanningTreeProtocolInterface::SendMetaData(void* target, int type, const std::string &key, const std::string &data)
37 params.push_back(((User*)target)->uuid);
40 params.push_back(((Channel*)target)->name);
43 params.push_back("*");
46 params.push_back(key);
47 params.push_back(":" + data);
49 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",params);
52 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
56 params.push_back(channel->name);
57 params.push_back(ConvToStr(ServerInstance->Time()));
58 params.push_back(ServerInstance->Config->ServerName);
59 params.push_back(":" + topic);
61 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params);
64 void SpanningTreeProtocolInterface::SendMode(const std::string &target, parameterlist &modedata)
71 /* Warning: in-place translation is only safe for type TR_NICK */
72 for (size_t n = 0; n < modedata.size(); n++)
74 ServerInstance->Parser->TranslateUIDs(TR_NICK, modedata[n], outdata);
75 modedata[n] = outdata;
78 std::string uidtarget;
79 ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget);
80 modedata.insert(modedata.begin(), uidtarget);
82 User* a = ServerInstance->FindNick(uidtarget);
85 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",modedata);
90 Channel* c = ServerInstance->FindChan(target);
93 modedata.insert(modedata.begin() + 1, ConvToStr(c->age));
94 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",modedata);
99 void SpanningTreeProtocolInterface::SendModeNotice(const std::string &modes, const std::string &text)
103 p.push_back(":" + text);
104 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "MODENOTICE", p);
107 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
110 p.push_back(snomask);
111 p.push_back(":" + text);
112 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
115 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
118 p.push_back(target->uuid);
119 p.push_back(rawline);
120 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
123 void SpanningTreeProtocolInterface::SendChannel(Channel* target, char status, const std::string &text)
125 std::string cname = target->name;
127 cname = status + cname;
130 Utils->GetListOfServersForChannel(target,list,status,exempt_list);
131 for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
133 TreeSocket* Sock = i->second->GetSocket();
135 Sock->WriteLine(text);
140 void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text)
142 SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" PRIVMSG "+target->name+" :"+text);
145 void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text)
147 SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" NOTICE "+target->name+" :"+text);
150 void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text)
152 TreeServer* serv = Utils->FindServer(target->server);
155 TreeSocket* sock = serv->GetSocket();
158 sock->WriteLine(":" + ServerInstance->Config->GetSID() + " PRIVMSG " + target->nick + " :"+text);
163 void SpanningTreeProtocolInterface::SendUserNotice(User* target, const std::string &text)
165 TreeServer* serv = Utils->FindServer(target->server);
168 TreeSocket* sock = serv->GetSocket();
171 sock->WriteLine(":" + ServerInstance->Config->GetSID() + " NOTICE " + target->nick + " :"+text);
176 void SpanningTreeProtocolInterface::Introduce(User* user)
180 std::deque<std::string> params;
181 params.push_back(user->uuid);
182 params.push_back(ConvToStr(user->age));
183 params.push_back(user->nick);
184 params.push_back(user->host);
185 params.push_back(user->dhost);
186 params.push_back(user->ident);
187 params.push_back("+"+std::string(user->FormatModes()));
188 params.push_back(user->GetIPString());
189 params.push_back(ConvToStr(user->signon));
190 params.push_back(":"+std::string(user->fullname));
191 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "UID", params);
194 TreeServer* SourceServer = Utils->FindServer(user->server);
197 SourceServer->SetUserCount(1); // increment by 1