]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/postcommand.cpp
Change cmd_*.so to use the Module object API
[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 "socket.h"
18 #include "xline.h"
19 #include "../transport.h"
20
21 #include "main.h"
22 #include "utils.h"
23 #include "treeserver.h"
24 #include "treesocket.h"
25
26 /* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
27
28 void ModuleSpanningTree::OnPostCommand(const std::string &command, const std::vector<std::string>& parameters, User *user, CmdResult result, const std::string &original_line)
29 {
30         if (result != CMD_SUCCESS)
31                 return;
32         if (!ServerInstance->IsValidModuleCommand(command, parameters.size(), user))
33                 return;
34
35         /* We know it's non-null because IsValidModuleCommand returned true */
36         Command* thiscmd = ServerInstance->Parser->GetHandler(command);
37
38         RouteDescriptor routing = thiscmd->GetRouting(user, parameters);
39
40         std::string sent_cmd = command;
41         parameterlist params;
42
43         if (routing.type == ROUTE_TYPE_LOCALONLY)
44         {
45                 return;
46         }
47         else if (routing.type == ROUTE_TYPE_OPT_BCAST)
48         {
49                 params.push_back("*");
50                 params.push_back(command);
51                 sent_cmd = "ENCAP";
52         }
53         else if (routing.type == ROUTE_TYPE_OPT_UCAST)
54         {
55                 TreeServer* sdest = Utils->FindServer(routing.serverdest);
56                 if (!sdest)
57                 {
58                         ServerInstance->Logs->Log("m_spanningtree",ERROR,"Trying to route ENCAP to nonexistant server %s",
59                                 routing.serverdest.c_str());
60                         return;
61                 }
62                 params.push_back(sdest->GetID());
63                 params.push_back(command);
64                 sent_cmd = "ENCAP";
65         }
66         else
67         {
68                 Module* srcmodule = thiscmd->creator;
69                 Version ver = srcmodule->GetVersion();
70
71                 // XXX Temporary check to avoid routing cmd_* entries while they default to global routing
72                 if (srcmodule->ModuleSourceFile[0] == 'c')
73                         return;
74
75                 if (!(ver.Flags & VF_COMMON))
76                 {
77                         ServerInstance->Logs->Log("m_spanningtree",ERROR,"Routed command %s from non-VF_COMMON module %s",
78                                 command.c_str(), srcmodule->ModuleSourceFile.c_str());
79                         return;
80                 }
81         }
82
83         std::string output_text;
84         ServerInstance->Parser->TranslateUIDs(thiscmd->translation, parameters, output_text, true, thiscmd);
85
86         params.push_back(output_text);
87
88         if (routing.type == ROUTE_TYPE_BROADCAST || routing.type == ROUTE_TYPE_OPT_BCAST)
89                 Utils->DoOneToMany(user->uuid, sent_cmd, params);
90         else
91                 Utils->DoOneToOne(user->uuid, sent_cmd, params, routing.serverdest);
92 }