2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
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.
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
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/>.
24 #include "treeserver.h"
26 void ModuleSpanningTree::OnPostCommand(Command* command, const std::vector<std::string>& parameters, LocalUser* user, CmdResult result, const std::string& original_line)
28 if (result == CMD_SUCCESS)
29 Utils->RouteCommand(NULL, command, parameters, user);
32 void SpanningTreeUtilities::RouteCommand(TreeServer* origin, CommandBase* thiscmd, const parameterlist& parameters, User* user)
34 const std::string& command = thiscmd->name;
35 RouteDescriptor routing = thiscmd->GetRouting(user, parameters);
37 std::string sent_cmd = command;
40 if (routing.type == ROUTE_TYPE_LOCALONLY)
44 else if (routing.type == ROUTE_TYPE_OPT_BCAST)
46 params.push_back("*");
47 params.push_back(command);
50 else if (routing.type == ROUTE_TYPE_OPT_UCAST)
52 TreeServer* sdest = FindServer(routing.serverdest);
55 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Trying to route ENCAP to nonexistant server %s",
56 routing.serverdest.c_str());
59 params.push_back(sdest->GetID());
60 params.push_back(command);
65 Module* srcmodule = thiscmd->creator;
66 Version ver = srcmodule->GetVersion();
68 if (!(ver.Flags & (VF_COMMON | VF_CORE)) && srcmodule != Creator)
70 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Routed command %s from non-VF_COMMON module %s",
71 command.c_str(), srcmodule->ModuleSourceFile.c_str());
76 std::string output_text = CommandParser::TranslateUIDs(thiscmd->translation, parameters, true, thiscmd);
78 params.push_back(output_text);
80 if (routing.type == ROUTE_TYPE_MESSAGE)
83 std::string dest = routing.serverdest;
84 if (ServerInstance->Modes->FindPrefix(dest[0]))
87 dest = dest.substr(1);
91 Channel* c = ServerInstance->FindChan(dest);
95 // TODO OnBuildExemptList hook was here
96 GetListOfServersForChannel(c,list,pfx, CUList());
97 std::string data = ":" + user->uuid + " " + sent_cmd;
98 for (unsigned int x = 0; x < params.size(); x++)
99 data += " " + params[x];
100 for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
102 TreeSocket* Sock = (*i)->GetSocket();
103 if (origin && origin->GetSocket() == Sock)
106 Sock->WriteLine(data);
109 else if (dest[0] == '$')
111 DoOneToAllButSender(user->uuid, sent_cmd, params, origin);
116 User* d = ServerInstance->FindNick(dest);
119 TreeServer* tsd = BestRouteTo(d->server);
121 // huh? no routing stuff around in a circle, please.
123 DoOneToOne(user->uuid, sent_cmd, params, d->server);
126 else if (routing.type == ROUTE_TYPE_BROADCAST || routing.type == ROUTE_TYPE_OPT_BCAST)
128 DoOneToAllButSender(user->uuid, sent_cmd, params, origin);
130 else if (routing.type == ROUTE_TYPE_UNICAST || routing.type == ROUTE_TYPE_OPT_UCAST)
132 if (origin && routing.serverdest == origin->GetName())
134 DoOneToOne(user->uuid, sent_cmd, params, routing.serverdest);