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) && (ServerInstance->IsValidModuleCommand(command, parameters.size(), user)))
34 /* Safe, we know its non-null because IsValidModuleCommand returned true */
35 Command* thiscmd = ServerInstance->Parser->GetHandler(command);
37 Module* srcmodule = ServerInstance->Modules->Find(thiscmd->source);
39 if (srcmodule && !(srcmodule->GetVersion().Flags & VF_COMMON)) {
40 ServerInstance->Logs->Log("m_spanningtree",ERROR,"Routed command %s from non-VF_COMMON module %s",
41 command.c_str(), thiscmd->source.c_str());
45 // this bit of code cleverly routes all module commands
46 // to all remote severs *automatically* so that modules
47 // can just handle commands locally, without having
48 // to have any special provision in place for remote
49 // commands and linking protocols.
52 unsigned int n_translate = thiscmd->translation.size();
53 TranslateType translate_to;
55 /* To make sure that parameters with spaces, or empty
56 * parameters, etc, are always sent properly, *always*
57 * prefix the last parameter with a :. This also removes
58 * an extra strchr() */
59 for (unsigned int j = 0; j < parameters.size(); j++)
63 /* Map all items to UUIDs where neccessary */
66 /* We have a translation mapping for this index */
67 translate_to = thiscmd->translation[j] != TR_END ? thiscmd->translation[j] : TR_TEXT;
70 translate_to = TR_TEXT;
72 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"TRANSLATION: %s - type is %d", parameters[j].c_str(), translate_to);
73 if (translate_to == TR_CUSTOM)
75 target = parameters[j];
76 thiscmd->EncodeParameter(target, j);
80 ServerInstance->Parser->TranslateUIDs(translate_to, parameters[j], target);
83 if (j == (parameters.size() - 1))
84 params.push_back(":" + target);
86 params.push_back(target);
88 Utils->DoOneToMany(user->uuid, command, params);