]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/postcommand.cpp
Allow commands to optionally route themselves using ENCAP
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / postcommand.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *        the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* $ModDesc: Provides a spanning tree server link protocol */
15
16 #include "inspircd.h"
17 #include "commands/cmd_whois.h"
18 #include "commands/cmd_stats.h"
19 #include "socket.h"
20 #include "xline.h"
21 #include "../transport.h"
22
23 #include "main.h"
24 #include "utils.h"
25 #include "treeserver.h"
26 #include "treesocket.h"
27
28 /* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
29
30 void ModuleSpanningTree::OnPostCommand(const std::string &command, const std::vector<std::string>& parameters, User *user, CmdResult result, const std::string &original_line)
31 {
32         if (result != CMD_SUCCESS)
33                 return;
34         if (!ServerInstance->IsValidModuleCommand(command, parameters.size(), user))
35                 return;
36
37         /* We know it's non-null because IsValidModuleCommand returned true */
38         Command* thiscmd = ServerInstance->Parser->GetHandler(command);
39
40         RouteDescriptor routing = thiscmd->GetRouting(user, parameters);
41
42         std::string sent_cmd = command;
43         parameterlist params;
44
45         if (routing.type == ROUTE_TYPE_LOCALONLY)
46         {
47                 return;
48         }
49         else if (routing.type == ROUTE_TYPE_OPT_BCAST)
50         {
51                 params.push_back("*");
52                 params.push_back(command);
53                 sent_cmd = "ENCAP";
54         }
55         else if (routing.type == ROUTE_TYPE_OPT_UCAST)
56         {
57                 params.push_back(routing.serverdest);
58                 params.push_back(command);
59                 sent_cmd = "ENCAP";
60         }
61         else
62         {
63                 Module* srcmodule = ServerInstance->Modules->Find(thiscmd->source);
64
65                 if (srcmodule && !(srcmodule->GetVersion().Flags & VF_COMMON)) {
66                         ServerInstance->Logs->Log("m_spanningtree",ERROR,"Routed command %s from non-VF_COMMON module %s",
67                                 command.c_str(), thiscmd->source.c_str());
68                         return;
69                 }
70         }
71
72         std::string output_text;
73         ServerInstance->Parser->TranslateUIDs(thiscmd->translation, parameters, output_text, true, thiscmd);
74
75         params.push_back(output_text);
76
77         if (routing.type == ROUTE_TYPE_BROADCAST || routing.type == ROUTE_TYPE_OPT_BCAST)
78                 Utils->DoOneToMany(user->uuid, sent_cmd, params);
79         else
80                 Utils->DoOneToOne(user->uuid, sent_cmd, params, routing.serverdest);
81 }