From: brain Date: Sat, 16 Dec 2006 23:15:50 +0000 (+0000) Subject: Add format="" value, at request of Emeric. X-Git-Tag: v2.0.23~6360 X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=1eb1b8d92548b16b2b0f48f7404a5dd599fdc03c;p=user%2Fhenk%2Fcode%2Finspircd.git Add format="" value, at request of Emeric. See: http://www.inspircd.org/forum/index.php/topic,245.0.html git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6019 e03df62e-2008-0410-955e-edbf42e46eb7 --- diff --git a/docs/inspircd.conf.example b/docs/inspircd.conf.example index 14e7d6b11..bac34bd57 100644 --- a/docs/inspircd.conf.example +++ b/docs/inspircd.conf.example @@ -880,9 +880,23 @@ # commands to services, however they are not limited to just this use.# # An alias tag requires the following values to be defined in it: # # # -# text - The text to detect at the start of the line, # -# must be at the start of the line to trigger the # -# alias. Cant contain spaces, but case insensitive # +# text - The text to detect as the actual command line, # +# Cant contain spaces, but case insensitive. # +# You may have multiple aliases with the same # +# command name (text="" value), however the first # +# found will be executed if its format value is # +# matched, or it has no format value. Aliases are # +# read from the top of the file to the bottom. # +# # +# format - If this is defined, the parameters of the alias # +# must match this glob pattern. For example if you # +# want the first parameter to start with a # for # +# the alias to be executed, set format="#*" in the # +# alias definition. Note that the :'s which are # +# part of IRC formatted lines will be preserved # +# for matching of this text. This value is # +# optional. # +# # # replace - The text to replace 'text' with. Usually this # # will be "PRIVMSG ServiceName :$2-" or similar. # # You may use the variables $1 through $9 in the # @@ -898,10 +912,12 @@ # commands with \n. If you wish to use the ACTUAL # # characters \ and n together in a line, you must # # use the sequence "\\n". # +# # # requires - If you provide a value for 'requires' this means # # the given nickname MUST be online for the alias # # to successfully trigger. If they are not, then # # the user receives a 'no such nick' 401 numeric. # +# # # uline - Defining this value with 'yes', 'true' or '1' # # will ensure that the user given in 'requires' # # must also be on a u-lined server, as well as # @@ -909,6 +925,7 @@ # online, but not on a u-lined server, then an # # oper-alert is sent out as this is possibly signs # # of a user trying to impersonate a service. # +# # # operonly - Defining this value, with a value of 'yes', '1' # # or true will make the alias oper only. If a non- # # oper attempts to use the alias, it will appear # @@ -920,7 +937,16 @@ # # # -# +# +# An example of using the format value to create an alias with two +# different behaviours depending on the format of the parameters. +# +# +# +# +# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # Alltime module: Shows time on all connected servers at once diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 7695b6f62..55241c278 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -34,11 +34,14 @@ class Alias : public classbase bool uline; /** Requires oper? */ bool operonly; + /** Format that must be matched for use */ + std::string format; }; class ModuleAlias : public Module { private: + /** We cant use a map, there may be multiple aliases with the same name */ std::vector Aliases; std::vector pars; @@ -57,6 +60,7 @@ class ModuleAlias : public Module a.requires = MyConf.ReadValue("alias", "requires", i); a.uline = MyConf.ReadFlag("alias", "uline", i); a.operonly = MyConf.ReadFlag("alias", "operonly", i); + a.format = MyConf.ReadValue("alias", "format", i); Aliases.push_back(a); } } @@ -127,18 +131,30 @@ class ModuleAlias : public Module virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line) { userrec *u = NULL; - irc::string c = command.c_str(); + /* If the command is valid, we dont want to know, * and if theyre not registered yet, we dont want * to know either */ if ((validated) || (user->registered != REG_ALL)) return 0; + + irc::string c = command.c_str(); + /* The parameters for the command in their original form, with the command stripped off */ + std::string compare = original_line.substr(command.length()); + while (*(compare.c_str()) == ' ') + compare.erase(compare.begin()); for (unsigned int i = 0; i < Aliases.size(); i++) { if (Aliases[i].text == c) { + /* Does it match the pattern? */ + if ((!Aliases[i].format.empty()) && (!ServerInstance->MatchText(compare, Aliases[i].format))) + { + continue; + } + if ((Aliases[i].operonly) && (!*user->oper)) return 0;