]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/postcommand.cpp
Fix a lot of calls to match() and uses of wildcard.h (which doesn't exist anymore...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / postcommand.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 "m_spanningtree/main.h"
24 #include "m_spanningtree/utils.h"
25 #include "m_spanningtree/treeserver.h"
26 #include "m_spanningtree/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) && (ServerInstance->IsValidModuleCommand(command, parameters.size(), user)))
33         {
34                 /* Safe, we know its non-null because IsValidModuleCommand returned true */
35                 Command* thiscmd = ServerInstance->Parser->GetHandler(command);
36                 // this bit of code cleverly routes all module commands
37                 // to all remote severs *automatically* so that modules
38                 // can just handle commands locally, without having
39                 // to have any special provision in place for remote
40                 // commands and linking protocols.
41                 std::deque<std::string> params;
42                 params.clear();
43                 unsigned int n_translate = thiscmd->translation.size();
44                 TranslateType translate_to;
45
46                 /* To make sure that parameters with spaces, or empty
47                  * parameters, etc, are always sent properly, *always*
48                  * prefix the last parameter with a :. This also removes
49                  * an extra strchr() */
50                 for (unsigned int j = 0; j < parameters.size(); j++)
51                 {
52                         std::string target;
53
54                         /* Map all items to UUIDs where neccessary */
55                         if (j < n_translate)
56                         {
57                                 /* We have a translation mapping for this index */
58                                 translate_to = thiscmd->translation[j] != TR_END ? thiscmd->translation[j] : TR_TEXT;
59                         }
60                         else
61                                 translate_to = TR_TEXT;
62
63                         ServerInstance->Logs->Log("m_spanningtree",DEBUG,"TRANSLATION: %s - type is %d", parameters[j].c_str(), translate_to);
64                         if (translate_to == TR_CUSTOM)
65                         {
66                                 target = parameters[j];
67                                 thiscmd->EncodeParameter(target, j);
68                         }
69                         else
70                         {
71                                 ServerInstance->Parser->TranslateUIDs(translate_to, parameters[j], target);
72                         }
73
74                         if (j == (parameters.size() - 1))
75                                 params.push_back(":" + target);
76                         else
77                                 params.push_back(target);
78                 }
79                 Utils->DoOneToMany(user->uuid, command, params);
80         }
81 }
82