]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_alias.cpp
Update the cloaks of connected users when their IP address changes.
[user/henk/code/inspircd.git] / src / modules / m_alias.cpp
index 01338e8b47d3285223fe651b0b47d929ccd65e0e..6f27ecc095ec0947f236542f845d293cebca49d1 100644 (file)
@@ -68,6 +68,9 @@ class ModuleAlias : public Module
        bool AllowBots;
        UserModeReference botmode;
 
+       // Whether we are actively executing an alias.
+       bool active;
+
  public:
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
@@ -129,7 +132,21 @@ class ModuleAlias : public Module
                return word;
        }
 
-       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
+       std::string CreateRFCMessage(const std::string& command, CommandBase::Params& parameters)
+       {
+               std::string message(command);
+               for (CommandBase::Params::const_iterator iter = parameters.begin(); iter != parameters.end();)
+               {
+                       const std::string& parameter = *iter++;
+                       message.push_back(' ');
+                       if (iter == parameters.end() && (parameter.empty() || parameter.find(' ') != std::string::npos))
+                               message.push_back(':');
+                       message.append(parameter);
+               }
+               return message;
+       }
+
+       ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) CXX11_OVERRIDE
        {
                /* If theyre not registered yet, we dont want
                 * to know.
@@ -143,6 +160,7 @@ class ModuleAlias : public Module
                        return MOD_RES_PASSTHRU;
 
                /* The parameters for the command in their original form, with the command stripped off */
+               std::string original_line = CreateRFCMessage(command, parameters);
                std::string compare(original_line, command.length());
                while (*(compare.c_str()) == ' ')
                        compare.erase(compare.begin());
@@ -162,6 +180,15 @@ class ModuleAlias : public Module
                return MOD_RES_PASSTHRU;
        }
 
+       ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
+       {
+               // Don't echo anything which is caused by an alias.
+               if (active)
+                       details.echo = false;
+
+               return MOD_RES_PASSTHRU;
+       }
+
        void OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE
        {
                if ((target.type != MessageTarget::TYPE_CHANNEL) || (details.type != MSG_PRIVMSG))
@@ -328,15 +355,18 @@ class ModuleAlias : public Module
                }
 
                irc::tokenstream ss(result);
-               std::vector<std::string> pars;
+               CommandBase::Params pars;
                std::string command, token;
 
-               ss.GetToken(command);
-               while (ss.GetToken(token))
+               ss.GetMiddle(command);
+               while (ss.GetTrailing(token))
                {
                        pars.push_back(token);
                }
+
+               active = true;
                ServerInstance->Parser.CallHandler(command, pars, user);
+               active = false;
        }
 
        void Prioritize() CXX11_OVERRIDE