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"
9 * For documentation on this class, see include/protocol.h.
12 void SpanningTreeProtocolInterface::GetServerList(ProtoServerList &sl)
15 for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
18 ps.servername = i->second->GetName();
19 TreeServer* s = i->second->GetParent();
20 ps.parentname = s ? s->GetName() : "";
21 ps.usercount = i->second->GetUserCount();
22 ps.opercount = i->second->GetOperCount();
23 ps.gecos = i->second->GetDesc();
24 ps.latencyms = i->second->rtt;
29 void SpanningTreeProtocolInterface::SendEncapsulatedData(parameterlist &encap)
31 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
34 void SpanningTreeProtocolInterface::SendMetaData(void* target, TargetTypeFlags type, const std::string &key, const std::string &data)
41 params.push_back(((User*)target)->uuid);
44 params.push_back(((Channel*)target)->name);
47 params.push_back("*");
50 throw CoreException("I don't know how to handle TYPE_OTHER.");
53 params.push_back(key);
54 params.push_back(":" + data);
56 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",params);
59 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
63 params.push_back(channel->name);
64 params.push_back(ConvToStr(ServerInstance->Time()));
65 params.push_back(ServerInstance->Config->ServerName);
66 params.push_back(":" + topic);
68 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params);
71 void SpanningTreeProtocolInterface::SendMode(const std::string &target, const parameterlist &modedata, const std::deque<TranslateType> &translate)
77 ServerInstance->Parser->TranslateUIDs(translate, modedata, outdata);
79 std::string uidtarget;
80 ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget);
82 parameterlist outlist;
83 outlist.push_back(uidtarget);
84 outlist.push_back(outdata);
86 User* a = ServerInstance->FindNick(uidtarget);
89 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",outlist);
94 Channel* c = ServerInstance->FindChan(target);
97 outlist.insert(outlist.begin() + 1, ConvToStr(c->age));
98 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",outlist);
103 void SpanningTreeProtocolInterface::SendModeNotice(const std::string &modes, const std::string &text)
107 p.push_back(":" + text);
108 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "MODENOTICE", p);
111 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
114 p.push_back(snomask);
115 p.push_back(":" + text);
116 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
119 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
122 p.push_back(target->uuid);
123 p.push_back(rawline);
124 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
127 void SpanningTreeProtocolInterface::SendChannel(Channel* target, char status, const std::string &text)
129 std::string cname = target->name;
131 cname = status + cname;
134 Utils->GetListOfServersForChannel(target,list,status,exempt_list);
135 for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
137 TreeSocket* Sock = i->second->GetSocket();
139 Sock->WriteLine(text);
144 void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text)
146 SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" PRIVMSG "+target->name+" :"+text);
149 void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text)
151 SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" NOTICE "+target->name+" :"+text);
154 void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text)
156 TreeServer* serv = Utils->FindServer(target->server);
159 TreeSocket* sock = serv->GetSocket();
162 sock->WriteLine(":" + ServerInstance->Config->GetSID() + " PRIVMSG " + target->nick + " :"+text);
167 void SpanningTreeProtocolInterface::SendUserNotice(User* target, const std::string &text)
169 TreeServer* serv = Utils->FindServer(target->server);
172 TreeSocket* sock = serv->GetSocket();
175 sock->WriteLine(":" + ServerInstance->Config->GetSID() + " NOTICE " + target->nick + " :"+text);
180 void SpanningTreeProtocolInterface::Introduce(User* user)
186 std::deque<std::string> params;
187 params.push_back(user->uuid);
188 params.push_back(ConvToStr(user->age));
189 params.push_back(user->nick);
190 params.push_back(user->host);
191 params.push_back(user->dhost);
192 params.push_back(user->ident);
193 params.push_back(user->GetIPString());
194 params.push_back(ConvToStr(user->signon));
195 params.push_back("+"+std::string(user->FormatModes(true)));
196 params.push_back(":"+std::string(user->fullname));
197 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "UID", params);
200 TreeServer* SourceServer = Utils->FindServer(user->server);
203 SourceServer->SetUserCount(1); // increment by 1