]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/protocolinterface.cpp
a6c826c7bf0c763cdc4006206099c01658e789d6
[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 #include "commands.h"
26
27 /*
28  * For documentation on this class, see include/protocol.h.
29  */
30
31 void SpanningTreeProtocolInterface::GetServerList(ServerList& sl)
32 {
33         for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
34         {
35                 ServerInfo 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         CmdBuilder params("ENCAP");
50         params.insert(encap);
51         if (encap[0].find_first_of("*?") != std::string::npos)
52         {
53                 params.Broadcast();
54                 return true;
55         }
56         return params.Unicast(encap[0]);
57 }
58
59 void SpanningTreeProtocolInterface::SendMetaData(User* u, const std::string& key, const std::string& data)
60 {
61         CommandMetadata::Builder(u, key, data).Broadcast();
62 }
63
64 void SpanningTreeProtocolInterface::SendMetaData(Channel* c, const std::string& key, const std::string& data)
65 {
66         CommandMetadata::Builder(c, key, data).Broadcast();
67 }
68
69 void SpanningTreeProtocolInterface::SendMetaData(const std::string& key, const std::string& data)
70 {
71         CommandMetadata::Builder(key, data).Broadcast();
72 }
73
74 void SpanningTreeProtocolInterface::Server::SendMetaData(const std::string& key, const std::string& data)
75 {
76         sock->WriteLine(CommandMetadata::Builder(key, data));
77 }
78
79 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
80 {
81         CommandFTopic::Builder(ServerInstance->FakeClient, channel).Broadcast();
82 }
83
84 void SpanningTreeProtocolInterface::SendMode(User* source, User* u, Channel* c, const std::vector<std::string>& modedata, const std::vector<TranslateType>& translate)
85 {
86         if (u)
87         {
88                 if (u->registered != REG_ALL)
89                         return;
90
91                 CmdBuilder params(source, "MODE");
92                 params.push_back(u->uuid);
93                 params.insert(modedata);
94                 params.Broadcast();
95         }
96         else
97         {
98                 CmdBuilder params(source, "FMODE");
99                 params.push_back(c->name);
100                 params.push_back(ConvToStr(c->age));
101                 params.push_back(CommandParser::TranslateUIDs(translate, modedata));
102                 params.Broadcast();
103         }
104 }
105
106 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
107 {
108         CmdBuilder("SNONOTICE").push(snomask).push_last(text).Broadcast();
109 }
110
111 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
112 {
113         CmdBuilder("PUSH").push(target->uuid).push_last(rawline).Unicast(target);
114 }
115
116 void SpanningTreeProtocolInterface::SendMessage(Channel* target, char status, const std::string& text, MessageType msgtype)
117 {
118         const char* cmd = (msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE");
119         CUList exempt_list;
120         Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, cmd);
121 }
122
123 void SpanningTreeProtocolInterface::SendMessage(User* target, const std::string& text, MessageType msgtype)
124 {
125         CmdBuilder p(msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE");
126         p.push_back(target->uuid);
127         p.push_last(text);
128         p.Unicast(target);
129 }