]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_alias.cpp
Fix an inverted condition in the cgiirc module.
[user/henk/code/inspircd.git] / src / modules / m_alias.cpp
index 4333971236ce28c2bce638cf36065275ae15e940..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,14 +132,14 @@ class ModuleAlias : public Module
                return word;
        }
 
-       std::string CreateRFCMessage(const std::string& command, Command::Params& parameters)
+       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;
+                       const std::string& parameter = *iter++;
                        message.push_back(' ');
-                       if (iter == parameters.end())
+                       if (iter == parameters.end() && (parameter.empty() || parameter.find(' ') != std::string::npos))
                                message.push_back(':');
                        message.append(parameter);
                }
@@ -177,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))
@@ -346,12 +358,15 @@ class ModuleAlias : public Module
                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