]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/protocolinterface.cpp
Add call to protocol interface to get useful info on the server map. Return a std...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / protocolinterface.cpp
1 #include "inspircd.h"
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"
7
8 void SpanningTreeProtocolInterface::GetServerList(ProtoServerList &sl)
9 {
10         sl.clear();
11         for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
12         {
13                 ProtoServer ps;
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;
20                 sl.push_back(ps);
21         }
22 }
23
24 void SpanningTreeProtocolInterface::SendEncapsulatedData(parameterlist &encap)
25 {
26         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
27 }
28
29 void SpanningTreeProtocolInterface::SendMetaData(void* target, int type, const std::string &key, const std::string &data)
30 {
31         parameterlist params;
32
33         switch (type)
34         {
35                 case TYPE_USER:
36                         params.push_back(((User*)target)->uuid);
37                 break;
38                 case TYPE_CHANNEL:
39                         params.push_back(((Channel*)target)->name);
40                 break;
41                 case TYPE_SERVER:
42                         params.push_back("*");
43                 break;
44         }
45         params.push_back(key);
46         params.push_back(":" + data);
47
48         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",params);
49 }
50
51 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
52 {
53         parameterlist params;
54
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);
59
60         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params);
61 }
62
63 void SpanningTreeProtocolInterface::SendMode(const std::string &target, parameterlist &modedata)
64 {
65         if (modedata.empty())
66                 return;
67
68         std::string outdata;
69
70         /* Warning: in-place translation is only safe for type TR_NICK */
71         for (size_t n = 0; n < modedata.size(); n++)
72         {
73                 ServerInstance->Parser->TranslateUIDs(TR_NICK, modedata[n], outdata);
74                 modedata[n] = outdata;
75         }
76
77         std::string uidtarget;
78         ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget);
79         modedata.insert(modedata.begin(), uidtarget);
80
81         User* a = ServerInstance->FindNick(uidtarget);
82         if (a)
83         {
84                 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",modedata);
85                 return;
86         }
87         else
88         {
89                 Channel* c = ServerInstance->FindChan(target);
90                 if (c)
91                 {
92                         modedata.insert(modedata.begin() + 1, ConvToStr(c->age));
93                         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",modedata);
94                 }
95         }
96 }
97
98 void SpanningTreeProtocolInterface::SendModeNotice(const std::string &modes, const std::string &text)
99 {
100         parameterlist p;
101         p.push_back(modes);
102         p.push_back(":" + text);
103         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "MODENOTICE", p);
104 }
105
106 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
107 {
108         parameterlist p;
109         p.push_back(snomask);
110         p.push_back(":" + text);
111         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
112 }
113
114 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
115 {
116         parameterlist p;
117         p.push_back(target->uuid);
118         p.push_back(rawline);
119         Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
120 }
121
122 void SpanningTreeProtocolInterface::SendChannel(Channel* target, char status, const std::string &text)
123 {
124         std::string cname = target->name;
125         if (status)
126                 cname = status + cname;
127         TreeServerList list;
128         CUList exempt_list;
129         Utils->GetListOfServersForChannel(target,list,status,exempt_list);
130         for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
131         {
132                 TreeSocket* Sock = i->second->GetSocket();
133                 if (Sock)
134                         Sock->WriteLine(text);
135         }
136 }
137
138
139 void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text)
140 {
141         SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" PRIVMSG "+target->name+" :"+text);
142 }
143
144 void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text)
145 {
146         SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" NOTICE "+target->name+" :"+text);
147 }
148
149 void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text)
150 {
151         TreeServer* serv = Utils->FindServer(target->server);
152         if (serv)
153         {
154                 TreeSocket* sock = serv->GetSocket();
155                 if (sock)
156                 {
157                         sock->WriteLine(":" + ServerInstance->Config->GetSID() + " PRIVMSG " + target->nick + " :"+text);
158                 }
159         }
160 }
161
162 void SpanningTreeProtocolInterface::SendUserNotice(User* target, const std::string &text)
163 {
164         TreeServer* serv = Utils->FindServer(target->server);
165         if (serv)
166         {
167                 TreeSocket* sock = serv->GetSocket();
168                 if (sock)
169                 {
170                         sock->WriteLine(":" + ServerInstance->Config->GetSID() + " NOTICE " + target->nick + " :"+text);
171                 }
172         }
173 }
174