The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

postcommand.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *        the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 /* $ModDesc: Provides a spanning tree server link protocol */
00015 
00016 #include "inspircd.h"
00017 #include "commands/cmd_whois.h"
00018 #include "commands/cmd_stats.h"
00019 #include "socket.h"
00020 #include "xline.h"
00021 #include "transport.h"
00022 
00023 #include "m_spanningtree/main.h"
00024 #include "m_spanningtree/utils.h"
00025 #include "m_spanningtree/treeserver.h"
00026 #include "m_spanningtree/treesocket.h"
00027 
00028 /* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
00029 
00030 void ModuleSpanningTree::OnPostCommand(const std::string &command, const std::vector<std::string>& parameters, User *user, CmdResult result, const std::string &original_line)
00031 {
00032         if ((result == CMD_SUCCESS) && (ServerInstance->IsValidModuleCommand(command, parameters.size(), user)))
00033         {
00034                 /* Safe, we know its non-null because IsValidModuleCommand returned true */
00035                 Command* thiscmd = ServerInstance->Parser->GetHandler(command);
00036                 // this bit of code cleverly routes all module commands
00037                 // to all remote severs *automatically* so that modules
00038                 // can just handle commands locally, without having
00039                 // to have any special provision in place for remote
00040                 // commands and linking protocols.
00041                 std::deque<std::string> params;
00042                 params.clear();
00043                 unsigned int n_translate = thiscmd->translation.size();
00044                 TranslateType translate_to;
00045 
00046                 /* To make sure that parameters with spaces, or empty
00047                  * parameters, etc, are always sent properly, *always*
00048                  * prefix the last parameter with a :. This also removes
00049                  * an extra strchr() */
00050                 for (unsigned int j = 0; j < parameters.size(); j++)
00051                 {
00052                         std::string target;
00053 
00054                         /* Map all items to UUIDs where neccessary */
00055                         if (j < n_translate)
00056                         {
00057                                 /* We have a translation mapping for this index */
00058                                 translate_to = thiscmd->translation[j] != TR_END ? thiscmd->translation[j] : TR_TEXT;
00059                         }
00060                         else
00061                                 translate_to = TR_TEXT;
00062 
00063                         ServerInstance->Logs->Log("m_spanningtree",DEBUG,"TRANSLATION: %s - type is %d", parameters[j].c_str(), translate_to);
00064                         if (translate_to == TR_CUSTOM)
00065                         {
00066                                 target = parameters[j];
00067                                 thiscmd->EncodeParameter(target, j);
00068                         }
00069                         else
00070                         {
00071                                 ServerInstance->Parser->TranslateUIDs(translate_to, parameters[j], target);
00072                         }
00073 
00074                         if (j == (parameters.size() - 1))
00075                                 params.push_back(":" + target);
00076                         else
00077                                 params.push_back(target);
00078                 }
00079                 Utils->DoOneToMany(user->uuid, command, params);
00080         }
00081 }
00082