]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/protocolinterface.cpp
Clean up the protocol interface
[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(ServerList& sl)
31 {
32         for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
33         {
34                 ServerInfo ps;
35                 ps.servername = i->second->GetName();
36                 TreeServer* s = i->second->GetParent();
37                 ps.parentname = s ? s->GetName() : "";
38                 ps.usercount = i->second->UserCount;
39                 ps.opercount = i->second->OperCount;
40                 ps.gecos = i->second->GetDesc();
41                 ps.latencyms = i->second->rtt;
42                 sl.push_back(ps);
43         }
44 }
45
46 bool SpanningTreeProtocolInterface::SendEncapsulatedData(const parameterlist &encap)
47 {
48         if (encap[0].find_first_of("*?") != std::string::npos)
49         {
50                 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
51                 return true;
52         }
53         return Utils->DoOneToOne(ServerInstance->Config->GetSID(), "ENCAP", encap, encap[0]);
54 }
55
56 void SpanningTreeProtocolInterface::SendMetaData(Extensible* target, const std::string &key, const std::string &data)
57 {
58         parameterlist params;
59
60         User* u = dynamic_cast<User*>(target);
61         Channel* c = dynamic_cast<Channel*>(target);
62         if (u)
63                 params.push_back(u->uuid);
64         else if (c)
65         {
66                 params.push_back(c->name);
67                 params.push_back(ConvToStr(c->age));
68         }
69         else
70                 params.push_back("*");
71
72         params.push_back(key);
73         params.push_back(":" + data);
74
75         Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",params);
76 }
77
78 void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
79 {
80         parameterlist params;
81
82         params.push_back(channel->name);
83         params.push_back(ConvToStr(channel->age));
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(User* source, User* u, Channel* c, const parameterlist& modedata, const std::vector<TranslateType>& translate)
92 {
93         parameterlist params;
94
95         if (u)
96         {
97                 if (u->registered != REG_ALL)
98                         return;
99
100                 params.push_back(u->uuid);
101                 params.insert(params.end(), modedata.begin(), modedata.end());
102                 Utils->DoOneToMany(source->uuid, "MODE", params);
103         }
104         else
105         {
106                 params.push_back(c->name);
107                 params.push_back(ConvToStr(c->age));
108                 params.push_back(CommandParser::TranslateUIDs(translate, modedata));
109                 Utils->DoOneToMany(source->uuid, "FMODE", params);
110         }
111 }
112
113 void SpanningTreeProtocolInterface::SendSNONotice(const std::string &snomask, const std::string &text)
114 {
115         parameterlist p;
116         p.push_back(snomask);
117         p.push_back(":" + text);
118         Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", p);
119 }
120
121 void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline)
122 {
123         parameterlist p;
124         p.push_back(target->uuid);
125         p.push_back(":" + rawline);
126         Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
127 }
128
129 void SpanningTreeProtocolInterface::SendMessage(Channel* target, char status, const std::string& text, MessageType msgtype)
130 {
131         const char* cmd = (msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE");
132         CUList exempt_list;
133         Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, cmd);
134 }
135
136 void SpanningTreeProtocolInterface::SendMessage(User* target, const std::string& text, MessageType msgtype)
137 {
138         const char* cmd = (msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE");
139         parameterlist p;
140         p.push_back(target->uuid);
141         p.push_back(":" + text);
142         Utils->DoOneToOne(ServerInstance->Config->GetSID(), cmd, p, target->server);
143 }