]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/protocolinterface.cpp
m_spanningtree Add channel timestamp to channel METADATA
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / protocolinterface.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22 #include "utils.h"
23 #include "treeserver.h"
24 #include "protocolinterface.h"
25
26 /*
27  * For documentation on this class, see include/protocol.h.
28  */
29
30 void SpanningTreeProtocolInterface::GetServerList(ProtoServerList &sl)
31 {
32         sl.clear();
33         for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
34         {
35                 ProtoServer ps;
36                 ps.servername = i->second->GetName();
37                 TreeServer* s = i->second->GetParent();
38                 ps.parentname = s ? s->GetName() : "";
39                 ps.usercount = i->second->UserCount;
40                 ps.opercount = i->second->OperCount;
41                 ps.gecos = i->second->GetDesc();
42                 ps.latencyms = i->second->rtt;
43                 sl.push_back(ps);
44         }
45 }
46
47 bool SpanningTreeProtocolInterface::SendEncapsulatedData(const parameterlist &encap)
48 {
49         if (encap[0].find_first_of("*?") != std::string::npos)
50         {
51                 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
52                 return true;
53         }
54         return Utils->DoOneToOne(ServerInstance->Config->GetSID(), "ENCAP", encap, encap[0]);
55 }
56
57 void SpanningTreeProtocolInterface::SendMetaData(Extensible* target, const std::string &key, const std::string &data)
58 {
59         parameterlist params;
60
61         User* u = dynamic_cast<User*>(target);
62         Channel* c = dynamic_cast<Channel*>(target);
63         if (u)
64                 params.push_back(u->uuid);
65         else if (c)
66         {
67                 params.push_back(c->name);
68                 params.push_back(ConvToStr(c->age));
69         }
70         else
71                 params.push_back("*");
72
73         params.push_back(key);
74         params.push_back(":" + data);
75
76         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",params);
77 }
78
79 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
80 {
81         parameterlist params;
82
83         params.push_back(channel->name);
84         params.push_back(ConvToStr(ServerInstance->Time()));
85         params.push_back(ServerInstance->Config->ServerName);
86         params.push_back(":" + topic);
87
88         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params);
89 }
90
91 void SpanningTreeProtocolInterface::SendMode(const std::string &target, const parameterlist &modedata, const std::vector<TranslateType> &translate)
92 {
93         if (modedata.empty())
94                 return;
95
96         std::string outdata;
97         ServerInstance->Parser->TranslateUIDs(translate, modedata, outdata);
98
99         std::string uidtarget;
100         ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget);
101
102         parameterlist outlist;
103         outlist.push_back(uidtarget);
104         outlist.push_back(outdata);
105
106         User* a = ServerInstance->FindNick(uidtarget);
107         if (a)
108         {
109                 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",outlist);
110                 return;
111         }
112         else
113         {
114                 Channel* c = ServerInstance->FindChan(target);
115                 if (c)
116                 {
117                         outlist.insert(outlist.begin() + 1, ConvToStr(c->age));
118                         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",outlist);
119                 }
120         }
121 }
122
123 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
124 {
125         parameterlist p;
126         p.push_back(snomask);
127         p.push_back(":" + text);
128         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
129 }
130
131 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
132 {
133         parameterlist p;
134         p.push_back(target->uuid);
135         p.push_back(":" + rawline);
136         Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
137 }
138
139 void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text)
140 {
141         CUList exempt_list;
142         Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "PRIVMSG");
143 }
144
145 void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text)
146 {
147         CUList exempt_list;
148         Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "NOTICE");
149 }
150
151 void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text)
152 {
153         parameterlist p;
154         p.push_back(target->uuid);
155         p.push_back(":" + text);
156         Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PRIVMSG", p, target->server);
157 }
158
159 void SpanningTreeProtocolInterface::SendUserNotice(User* target, const std::string &text)
160 {
161         parameterlist p;
162         p.push_back(target->uuid);
163         p.push_back(":" + text);
164         Utils->DoOneToOne(ServerInstance->Config->GetSID(), "NOTICE", p, target->server);
165 }