]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/postcommand.cpp
Split up spanningtree some more, the filenames should be more intuitive so that devel...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / postcommand.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 "wildcard.h"
21 #include "xline.h"      
22 #include "transport.h"  
23                         
24 #include "m_spanningtree/timesynctimer.h"
25 #include "m_spanningtree/resolvers.h"
26 #include "m_spanningtree/main.h"
27 #include "m_spanningtree/utils.h"
28 #include "m_spanningtree/treeserver.h"
29 #include "m_spanningtree/link.h"
30 #include "m_spanningtree/treesocket.h"
31 #include "m_spanningtree/rconnect.h"
32 #include "m_spanningtree/rsquit.h"
33
34 /* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h m_spanningtree/rconnect.h m_spanningtree/rsquit.h */
35
36 void ModuleSpanningTree::OnPostCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, CmdResult result, const std::string &original_line)
37 {
38         if ((result == CMD_SUCCESS) && (ServerInstance->IsValidModuleCommand(command, pcnt, user)))
39         {
40                 /* Safe, we know its non-null because IsValidModuleCommand returned true */
41                 command_t* thiscmd = ServerInstance->Parser->GetHandler(command);
42                 // this bit of code cleverly routes all module commands
43                 // to all remote severs *automatically* so that modules
44                 // can just handle commands locally, without having
45                 // to have any special provision in place for remote
46                 // commands and linking protocols.
47                 std::deque<std::string> params;
48                 params.clear();
49                 int n_translate = thiscmd->translation.size();
50                 TranslateType translate_to;
51
52                 /* To make sure that parameters with spaces, or empty
53                  * parameters, etc, are always sent properly, *always*
54                  * prefix the last parameter with a :. This also removes
55                  * an extra strchr() */
56                 for (int j = 0; j < pcnt; j++)
57                 {
58                         std::string target;
59
60                         /* Map all items to UUIDs where neccessary */
61                         if (j < n_translate)
62                         {
63                                 /* We have a translation mapping for this index */
64                                 translate_to = thiscmd->translation[j] != TR_END ? thiscmd->translation[j] : TR_TEXT;
65                         }
66                         else
67                                 translate_to = TR_TEXT;
68
69                         ServerInstance->Log(DEBUG,"TRANSLATION: %s - type is %d", parameters[j], translate_to);
70                         ServerInstance->Parser->TranslateUIDs(translate_to, parameters[j], target);
71                         
72                         if (j == (pcnt - 1))
73                                 params.push_back(":" + target);
74                         else
75                                 params.push_back(target);
76                 }
77                 Utils->DoOneToMany(user->uuid, command, params);
78         }
79 }
80