]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/protocolinterface.cpp
Allow SASL messages to be targeted at the services server
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / protocolinterface.cpp
1 #include "inspircd.h"
2 #include "main.h"
3 #include "utils.h"
4 #include "treeserver.h"
5 #include "treesocket.h"
6 #include "protocolinterface.h"
7
8 /*
9  * For documentation on this class, see include/protocol.h.
10  */
11
12 void SpanningTreeProtocolInterface::GetServerList(ProtoServerList &sl)
13 {
14         sl.clear();
15         for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
16         {
17                 ProtoServer ps;
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;
25                 sl.push_back(ps);
26         }
27 }
28
29 bool SpanningTreeProtocolInterface::SendEncapsulatedData(const parameterlist &encap)
30 {
31         if (encap[0].find('*') != std::string::npos)
32         {
33                 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
34                 return true;
35         }
36         return Utils->DoOneToOne(ServerInstance->Config->GetSID(), "ENCAP", encap, encap[0]);
37 }
38
39 void SpanningTreeProtocolInterface::SendMetaData(Extensible* target, const std::string &key, const std::string &data)
40 {
41         parameterlist params;
42
43         User* u = dynamic_cast<User*>(target);
44         Channel* c = dynamic_cast<Channel*>(target);
45         if (u)
46                 params.push_back(u->uuid);
47         else if (c)
48                 params.push_back(c->name);
49         else
50                 params.push_back("*");
51
52         params.push_back(key);
53         params.push_back(":" + data);
54
55         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",params);
56 }
57
58 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
59 {
60         parameterlist params;
61
62         params.push_back(channel->name);
63         params.push_back(ConvToStr(ServerInstance->Time()));
64         params.push_back(ServerInstance->Config->ServerName);
65         params.push_back(":" + topic);
66
67         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params);
68 }
69
70 void SpanningTreeProtocolInterface::SendMode(const std::string &target, const parameterlist &modedata, const std::vector<TranslateType> &translate)
71 {
72         if (modedata.empty())
73                 return;
74
75         std::string outdata;
76         ServerInstance->Parser->TranslateUIDs(translate, modedata, outdata);
77
78         std::string uidtarget;
79         ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget);
80
81         parameterlist outlist;
82         outlist.push_back(uidtarget);
83         outlist.push_back(outdata);
84
85         User* a = ServerInstance->FindNick(uidtarget);
86         if (a)
87         {
88                 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",outlist);
89                 return;
90         }
91         else
92         {
93                 Channel* c = ServerInstance->FindChan(target);
94                 if (c)
95                 {
96                         outlist.insert(outlist.begin() + 1, ConvToStr(c->age));
97                         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",outlist);
98                 }
99         }
100 }
101
102 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
103 {
104         parameterlist p;
105         p.push_back(snomask);
106         p.push_back(":" + text);
107         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
108 }
109
110 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
111 {
112         parameterlist p;
113         p.push_back(target->uuid);
114         p.push_back(":" + rawline);
115         Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
116 }
117
118 void SpanningTreeProtocolInterface::SendChannel(Channel* target, char status, const std::string &text)
119 {
120         std::string cname = target->name;
121         if (status)
122                 cname = status + cname;
123         TreeServerList list;
124         CUList exempt_list;
125         Utils->GetListOfServersForChannel(target,list,status,exempt_list);
126         for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
127         {
128                 TreeSocket* Sock = i->second->GetSocket();
129                 if (Sock)
130                         Sock->WriteLine(text);
131         }
132 }
133
134
135 void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text)
136 {
137         SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" PRIVMSG "+target->name+" :"+text);
138 }
139
140 void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text)
141 {
142         SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" NOTICE "+target->name+" :"+text);
143 }
144
145 void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text)
146 {
147         TreeServer* serv = Utils->FindServer(target->server);
148         if (serv)
149         {
150                 TreeSocket* sock = serv->GetSocket();
151                 if (sock)
152                 {
153                         sock->WriteLine(":" + ServerInstance->Config->GetSID() + " PRIVMSG " + target->nick + " :"+text);
154                 }
155         }
156 }
157
158 void SpanningTreeProtocolInterface::SendUserNotice(User* target, const std::string &text)
159 {
160         TreeServer* serv = Utils->FindServer(target->server);
161         if (serv)
162         {
163                 TreeSocket* sock = serv->GetSocket();
164                 if (sock)
165                 {
166                         sock->WriteLine(":" + ServerInstance->Config->GetSID() + " NOTICE " + target->nick + " :"+text);
167                 }
168         }
169 }