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 */
19 #include "../transport.h"
23 #include "treeserver.h"
24 #include "treesocket.h"
26 /* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
28 void ModuleSpanningTree::OnPostCommand(const std::string &command, const std::vector<std::string>& parameters, User *user, CmdResult result, const std::string &original_line)
30 if (result != CMD_SUCCESS)
32 if (!ServerInstance->IsValidModuleCommand(command, parameters.size(), user))
35 /* We know it's non-null because IsValidModuleCommand returned true */
36 Command* thiscmd = ServerInstance->Parser->GetHandler(command);
38 RouteDescriptor routing = thiscmd->GetRouting(user, parameters);
40 std::string sent_cmd = command;
43 if (routing.type == ROUTE_TYPE_LOCALONLY)
47 else if (routing.type == ROUTE_TYPE_OPT_BCAST)
49 params.push_back("*");
50 params.push_back(command);
53 else if (routing.type == ROUTE_TYPE_OPT_UCAST)
55 TreeServer* sdest = Utils->FindServer(routing.serverdest);
58 ServerInstance->Logs->Log("m_spanningtree",ERROR,"Trying to route ENCAP to nonexistant server %s",
59 routing.serverdest.c_str());
62 params.push_back(sdest->GetID());
63 params.push_back(command);
68 Module* srcmodule = thiscmd->creator;
69 Version ver = srcmodule->GetVersion();
71 if (!(ver.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);