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