X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_alias.cpp;h=6f27ecc095ec0947f236542f845d293cebca49d1;hb=3d0d64933da3d37866fadfa042e34a1125315db6;hp=01338e8b47d3285223fe651b0b47d929ccd65e0e;hpb=2fcb5ff4389a9a82d253acdff02a388ddcf14653;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 01338e8b4..6f27ecc09 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -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 ¶meters, 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 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