1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $ModDesc: Provides a spanning tree server link protocol */
17 #include "commands/cmd_whois.h"
18 #include "commands/cmd_stats.h"
21 #include "../transport.h"
25 #include "treeserver.h"
26 #include "treesocket.h"
28 /* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
30 void ModuleSpanningTree::OnPostCommand(const std::string &command, const std::vector<std::string>& parameters, User *user, CmdResult result, const std::string &original_line)
32 if (result != CMD_SUCCESS)
34 if (!ServerInstance->IsValidModuleCommand(command, parameters.size(), user))
37 /* We know it's non-null because IsValidModuleCommand returned true */
38 Command* thiscmd = ServerInstance->Parser->GetHandler(command);
40 RouteDescriptor routing = thiscmd->GetRouting(user, parameters);
42 std::string sent_cmd = command;
45 if (routing.type == ROUTE_TYPE_LOCALONLY)
49 else if (routing.type == ROUTE_TYPE_OPT_BCAST)
51 params.push_back("*");
52 params.push_back(command);
55 else if (routing.type == ROUTE_TYPE_OPT_UCAST)
57 TreeServer* sdest = Utils->FindServer(routing.serverdest);
60 ServerInstance->Logs->Log("m_spanningtree",ERROR,"Trying to route ENCAP to nonexistant server %s",
61 routing.serverdest.c_str());
64 params.push_back(sdest->GetID());
65 params.push_back(command);
70 Module* srcmodule = thiscmd->creator;
72 if (srcmodule && !(srcmodule->GetVersion().Flags & VF_COMMON)) {
73 ServerInstance->Logs->Log("m_spanningtree",ERROR,"Routed command %s from non-VF_COMMON module %s",
74 command.c_str(), srcmodule->ModuleSourceFile.c_str());
79 std::string output_text;
80 ServerInstance->Parser->TranslateUIDs(thiscmd->translation, parameters, output_text, true, thiscmd);
82 params.push_back(output_text);
84 if (routing.type == ROUTE_TYPE_BROADCAST || routing.type == ROUTE_TYPE_OPT_BCAST)
85 Utils->DoOneToMany(user->uuid, sent_cmd, params);
87 Utils->DoOneToOne(user->uuid, sent_cmd, params, routing.serverdest);