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