]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/protocolinterface.cpp
d10f7f98143ec1c594747534eca24171f8031561
[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         /* Warning: in-place translation is only safe for type TR_NICK */
53         for (size_t n = 0; n < modedata.size(); n++)
54                 ServerInstance->Parser->TranslateUIDs(TR_NICK, modedata[n], modedata[n]);
55
56         std::string uidtarget;
57         ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget);
58         modedata.insert(modedata.begin(), uidtarget);
59
60         User* a = ServerInstance->FindNick(uidtarget);
61         if (a)
62         {
63                 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",modedata);
64                 return;
65         }
66         else
67         {
68                 Channel* c = ServerInstance->FindChan(target);
69                 if (c)
70                 {
71                         modedata.insert(modedata.begin() + 1, ConvToStr(c->age));
72                         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",modedata);
73                 }
74         }
75 }
76
77 void SpanningTreeProtocolInterface::SendOperNotice(const std::string &text)
78 {
79         parameterlist p;
80         p.push_back(":" + text);
81         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "OPERNOTICE", p);
82 }
83
84 void SpanningTreeProtocolInterface::SendModeNotice(const std::string &modes, const std::string &text)
85 {
86         parameterlist p;
87         p.push_back(modes);
88         p.push_back(":" + text);
89         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "MODENOTICE", p);
90 }
91
92 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
93 {
94         parameterlist p;
95         p.push_back(snomask);
96         p.push_back(":" + text);
97         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
98 }
99
100 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
101 {
102         parameterlist p;
103         p.push_back(target->uuid);
104         p.push_back(rawline);
105         Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
106 }
107
108 void SpanningTreeProtocolInterface::SendChannel(Channel* target, char status, const std::string &text)
109 {
110         std::string cname = target->name;
111         if (status)
112                 cname = status + cname;
113         TreeServerList list;
114         CUList exempt_list;
115         Utils->GetListOfServersForChannel(target,list,status,exempt_list);
116         for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
117         {
118                 TreeSocket* Sock = i->second->GetSocket();
119                 if (Sock)
120                         Sock->WriteLine(text);
121         }
122 }
123
124
125 void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text)
126 {
127         SendChannel(target, status, ServerInstance->Config->GetSID()+" PRIVMSG "+target->name+" :"+text);
128 }
129
130 void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text)
131 {
132         SendChannel(target, status, ServerInstance->Config->GetSID()+" NOTICE "+target->name+" :"+text);
133 }
134