]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add optional max_params for commands, which means that we can compress 'extra' params...
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 25 Oct 2008 16:41:09 +0000 (16:41 +0000)
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 25 Oct 2008 16:41:09 +0000 (16:41 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10715 e03df62e-2008-0410-955e-edbf42e46eb7

include/commands/cmd_gline.h
include/ctables.h
src/command_parse.cpp

index 7db1f18a5efd5ecb802c46a2facb571993a380c1..47971f190496122d5885f156bdc2b48a1584759d 100644 (file)
@@ -29,7 +29,7 @@ class CommandGline : public Command
  public:
        /** Constructor for gline.
         */
-       CommandGline (InspIRCd* Instance) : Command(Instance,"GLINE","o",1,false,0) { syntax = "<ident@host> [<duration> :<reason>]"; }
+       CommandGline (InspIRCd* Instance) : Command(Instance,"GLINE","o",1,3,false,0) { syntax = "<ident@host> [<duration> :<reason>]"; }
        /** Handle command.
         * @param parameters The parameters to the comamnd
         * @param pcnt The number of parameters passed to teh command
index 37ed92ce0dac923b83ee2c24f217d76b1e8a0d27..f2994cd8c8dc3227d9e3cbf22d17253fa76a174d 100644 (file)
@@ -60,27 +60,41 @@ class CoreExport Command : public Extensible
        /** Command name
        */
         std::string command;
+
        /** User flags needed to execute the command or 0
         */
        char flags_needed;
+
        /** Minimum number of parameters command takes
        */
-       unsigned int min_params;
+       const unsigned int min_params;
+
+       /** Maximum number of parameters command takes.
+        * This is used by the command parser to join extra parameters into one last param.
+        * If not set, no munging is done to this command.
+        */
+       const unsigned int max_params;
+
        /** used by /stats m
         */
        long double use_count;
+
        /** used by /stats m
         */
        long double total_bytes;
+
        /** used for resource tracking between modules
         */
        std::string source;
+
        /** True if the command is disabled to non-opers
         */
        bool disabled;
+
        /** True if the command can be issued before registering
         */
        bool works_before_reg;
+
        /** Syntax string for the command, displayed if non-empty string.
         * This takes place of the text in the 'not enough parameters' numeric.
         */
@@ -101,11 +115,21 @@ class CoreExport Command : public Extensible
         * @param flags User mode required to execute the command. May ONLY be one mode - it's a string to give warnings if people mix params up.
         * For oper only commands, set this to 'o', otherwise use 0.
         * @param minpara Minimum parameters required for the command.
+        * @param maxpara Maximum number of parameters this command may have - extra parameters will be tossed into one last space-seperated param.
         * @param before_reg If this is set to true, the command will
         * be allowed before the user is 'registered' (has sent USER,
         * NICK, optionally PASS, and been resolved).
         */
-       Command(InspIRCd* Instance, const std::string &cmd, const char *flags, int minpara, int before_reg = false, int penalty = 1) :  ServerInstance(Instance), command(cmd), flags_needed(flags ? *flags : 0), min_params(minpara), disabled(false), works_before_reg(before_reg),   Penalty(penalty)
+       Command(InspIRCd* Instance, const std::string &cmd, const char *flags, int minpara, bool before_reg = false, int penalty = 1) :         ServerInstance(Instance), command(cmd), flags_needed(flags ? *flags : 0), min_params(minpara), max_params(0), disabled(false), works_before_reg(before_reg), Penalty(penalty)
+       {
+               use_count = 0;
+               total_bytes = 0;
+               source = "<core>";
+               syntax = "";
+               translation.clear();
+       }
+
+       Command(InspIRCd* Instance, const std::string &cmd, const char *flags, int minpara, int maxpara, bool before_reg = false, int penalty = 1) :    ServerInstance(Instance), command(cmd), flags_needed(flags ? *flags : 0), min_params(minpara), max_params(maxpara), disabled(false), works_before_reg(before_reg), Penalty(penalty)
        {
                use_count = 0;
                total_bytes = 0;
index 0f93e6f53d83e0ad9978d4b215f8f0ff11018a05..984ce2314d2a03e1230d8c65f19d269fb412bc05 100644 (file)
@@ -296,6 +296,43 @@ bool CommandParser::ProcessCommand(User *user, std::string &cmd)
                return true;
        }
 
+       if (cm->second->max_params && command_p.size() > cm->second->max_params)
+       {
+               /*
+                * command_p input (assuming max_params 1):
+                *      this
+                *      is
+                *      a
+                *      test
+                */
+               std::string lparam = "";
+
+               /*
+                * The '-1' here is a clever trick, we'll go backwards throwing everything into a temporary param
+                * and then just toss that into the array.
+                * -- w00t
+                */
+               while (command_p.size() > (cm->second->max_params - 1))
+               {
+                       // BE CAREFUL: .end() returns past the end of the vector, hence decrement.
+                       std::vector<std::string>::iterator it = --command_p.end();
+               
+                       lparam.insert(0, " " + *(it));
+                       command_p.erase(it); // remove last element
+               }
+
+               /* we now have (each iteration):
+                *      ' test'
+                *      ' a test'
+                *      ' is a test' <-- final string
+                * ...now remove the ' ' at the start...
+                */
+               lparam.erase(lparam.begin());
+
+               /* param is now 'is a test', which is exactly what we wanted! */
+               command_p.push_back(lparam);
+       }
+
        /* Modify the user's penalty */
        bool do_more = true;
        if (!user->ExemptFromPenalty)