diff options
author | Adam <Adam@anope.org> | 2010-12-06 20:53:15 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-12-12 19:37:03 -0500 |
commit | f1d04a2f8e4e9077d07a94b64478bb331b49bbc0 (patch) | |
tree | 5bb30c0cafa49e4956ca2fb3408e3430ac3efd37 | |
parent | aed53dbb47822a79eb9a6b61095ad04ec3d67818 (diff) |
Allow command aliases to be redirected to different pseudo clients
-rw-r--r-- | data/example.conf | 36 | ||||
-rw-r--r-- | include/modules.h | 2 | ||||
-rw-r--r-- | modules/core/os_defcon.cpp | 2 | ||||
-rw-r--r-- | modules/extra/m_alias.cpp | 51 |
4 files changed, 52 insertions, 39 deletions
diff --git a/data/example.conf b/data/example.conf index df6bcee3d..ddbdbbc42 100644 --- a/data/example.conf +++ b/data/example.conf @@ -1871,37 +1871,41 @@ m_xmlrpc module { name = "m_alias" } alias { - /* Set to yes to make this alias triggerabe by fantasy commands. - */ + /* Set to yes to make this alias triggerable by fantasy commands. */ fantasy = no + /* Set to yes to make this alias oper only */ + operonly = no - /* Target client the alias should be for (if not using fantasy). + /* Source client and command. */ - client = "NickServ" + source_client = "NickServ" + source_command = "ID" - /* Alias name and command */ - alias = "ID" - command = "IDENTIFY" - - /* Set to yes to make this alias oper only */ - operonly = no + /* Target client and command. + */ + target_client = "NickServ" + target_command = "IDENTIFY" } /* Provides the !k fantasy command */ alias { - fantasy = true - alias = "K" - command = "KICK" + fantasy = yes + source_command = "K" + + target_client = "ChanServ" + target_command = "KICK" } /* Provides the !kb fantasy command */ alias { - fantasy = true - alias = "KB" - command = "BAN" + fantasy = yes + source_command = "KB" + + target_client = "ChanServ" + target_command = "BAN" } /* diff --git a/include/modules.h b/include/modules.h index c96c1ae27..55697dbb9 100644 --- a/include/modules.h +++ b/include/modules.h @@ -367,7 +367,7 @@ class CoreExport Module : public Extensible * @param ci If a tanasy command, the channel the comman was used on * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it */ - virtual EventReturn OnPreCommandRun(User *u, BotInfo *bi, Anope::string &command, Anope::string &message, ChannelInfo *ci) { return EVENT_CONTINUE; } + virtual EventReturn OnPreCommandRun(User *&u, BotInfo *&bi, Anope::string &command, Anope::string &message, ChannelInfo *&ci) { return EVENT_CONTINUE; } /** Called before a command is due to be executed. * @param source The source of the command diff --git a/modules/core/os_defcon.cpp b/modules/core/os_defcon.cpp index cc8809586..88f7b4d79 100644 --- a/modules/core/os_defcon.cpp +++ b/modules/core/os_defcon.cpp @@ -206,7 +206,7 @@ class OSDefcon : public Module return EVENT_CONTINUE; } - EventReturn OnPreCommandRun(User *u, BotInfo *bi, Anope::string &command, Anope::string &message, ChannelInfo *ci) + EventReturn OnPreCommandRun(User *&u, BotInfo *&bi, Anope::string &command, Anope::string &message, ChannelInfo *&ci) { if (!u->HasMode(UMODE_OPER) && (CheckDefCon(DEFCON_OPER_ONLY) || CheckDefCon(DEFCON_SILENT_OPER_ONLY))) { diff --git a/modules/extra/m_alias.cpp b/modules/extra/m_alias.cpp index 3b9556772..53f04e3b4 100644 --- a/modules/extra/m_alias.cpp +++ b/modules/extra/m_alias.cpp @@ -11,14 +11,15 @@ struct CommandAlias { bool fantasy; bool operonly; - Anope::string client; - Anope::string alias; - Anope::string command; + Anope::string source_client; + Anope::string source_command; + Anope::string target_client; + Anope::string target_command; }; class ModuleAlias : public Module { - std::map<Anope::string, CommandAlias, std::less<ci::string> > aliases; + std::multimap<Anope::string, CommandAlias, std::less<ci::string> > aliases; public: ModuleAlias(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { @@ -38,40 +39,48 @@ class ModuleAlias : public Module { bool fantasy = config.ReadFlag("alias", "fantasy", "no", i); bool operonly = config.ReadFlag("alias", "operonly", "no", i); - Anope::string client = config.ReadValue("alias", "client", "", i); - Anope::string aliasname = config.ReadValue("alias", "alias", "", i); - Anope::string command = config.ReadValue("alias", "command", "", i); + Anope::string source_client = config.ReadValue("alias", "source_client", "", i); + Anope::string source_command = config.ReadValue("alias", "source_command", "", i); + Anope::string target_client = config.ReadValue("alias", "target_client", "", i); + Anope::string target_command = config.ReadValue("alias", "target_command", "", i); - if (aliasname.empty() || command.empty()) + if ((!fantasy &&source_client.empty()) || source_command.empty() || target_client.empty() || target_command.empty()) continue; CommandAlias alias; alias.fantasy = fantasy; alias.operonly = operonly; - alias.client = client; - alias.alias = aliasname; - alias.command = command; + alias.source_client = source_client; + alias.source_command = source_command; + alias.target_client = target_client; + alias.target_command = target_command; - this->aliases.insert(std::make_pair(aliasname, alias)); + this->aliases.insert(std::make_pair(source_command, alias)); } } - EventReturn OnPreCommandRun(User *u, BotInfo *bi, Anope::string &command, Anope::string &message, ChannelInfo *ci) + EventReturn OnPreCommandRun(User *&u, BotInfo *&bi, Anope::string &command, Anope::string &message, ChannelInfo *&ci) { bool fantasy = ci != NULL; - std::map<Anope::string, CommandAlias, std::less<ci::string> >::const_iterator it = aliases.find(command); - if (it != aliases.end()) + std::map<Anope::string, CommandAlias, std::less<ci::string> >::const_iterator it = aliases.find(command), + it_end = aliases.upper_bound(command); + for (; it != it_end; ++it) { const CommandAlias &alias = it->second; - if (fantasy != alias.fantasy) - return EVENT_CONTINUE; + + if (!fantasy && !bi->nick.equals_ci(alias.source_client)) + continue; + else if (fantasy != alias.fantasy) + continue; else if (!u->HasMode(UMODE_OPER) && alias.operonly) - return EVENT_CONTINUE; - else if (!fantasy && !bi->nick.equals_ci(alias.client)) - return EVENT_CONTINUE; + continue; - command = alias.command; + BotInfo *target = findbot(alias.target_client); + if (target) + bi = target; + command = alias.target_command; + break; } return EVENT_CONTINUE; |