]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/protocolinterface.cpp
48d0f78ebb447ed840fc8ab4ae9801d41ce409d5
[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/protocolinterface.h"
5
6 void SpanningTreeProtocolInterface::SendEncapsulatedData(parameterlist &encap)
7 {
8         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
9 }
10
11 void SpanningTreeProtocolInterface::SendMetaData(void* target, int type, const std::string &key, const std::string &data)
12 {
13         parameterlist params;
14
15         switch (type)
16         {
17                 case TYPE_USER:
18                         params.push_back(((User*)target)->uuid);
19                 break;
20                 case TYPE_CHANNEL:
21                         params.push_back(((Channel*)target)->name);
22                 break;
23                 case TYPE_SERVER:
24                         params.push_back("*");
25                 break;
26         }
27         params.push_back(key);
28         params.push_back(":" + data);
29
30         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",params);
31 }
32
33 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
34 {
35         parameterlist params;
36
37         params.push_back(channel->name);
38         params.push_back(ConvToStr(ServerInstance->Time()));
39         params.push_back(ServerInstance->Config->ServerName);
40         params.push_back(":" + topic);
41
42         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params);
43 }
44
45 void SpanningTreeProtocolInterface::SendMode(const std::string &target, parameterlist &modedata)
46 {
47         if (modedata.empty())
48                 return;
49
50         /* Warning: in-place translation is only safe for type TR_NICK */
51         for (size_t n = 0; n < modedata.size(); n++)
52                 ServerInstance->Parser->TranslateUIDs(TR_NICK, modedata[n], modedata[n]);
53
54         std::string uidtarget;
55         ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget);
56         modedata.insert(modedata.begin(), uidtarget);
57
58         User* a = ServerInstance->FindNick(uidtarget);
59         if (a)
60         {
61                 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",modedata);
62                 return;
63         }
64         else
65         {
66                 Channel* c = ServerInstance->FindChan(target);
67                 if (c)
68                 {
69                         modedata.insert(modedata.begin() + 1, ConvToStr(c->age));
70                         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",modedata);
71                 }
72         }
73 }
74
75 void SpanningTreeProtocolInterface::SendOperNotice(const std::string &text)
76 {
77         parameterlist p;
78         p.push_back(":" + text);
79         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "OPERNOTICE", p);
80 }
81
82 void SpanningTreeProtocolInterface::SendModeNotice(const std::string &modes, const std::string &text)
83 {
84         parameterlist p;
85         p.push_back(modes);
86         p.push_back(":" + text);
87         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "MODENOTICE", p);
88 }
89
90 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
91 {
92         parameterlist p;
93         p.push_back(snomask);
94         p.push_back(":" + text);
95         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
96 }
97
98 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
99 {
100         parameterlist p;
101         p.push_back(target->uuid);
102         p.push_back(rawline);
103         Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
104 }
105