summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/commands/cmd_gline.h2
-rw-r--r--include/ctables.h28
-rw-r--r--src/command_parse.cpp37
3 files changed, 64 insertions, 3 deletions
diff --git a/include/commands/cmd_gline.h b/include/commands/cmd_gline.h
index 7db1f18a5..47971f190 100644
--- a/include/commands/cmd_gline.h
+++ b/include/commands/cmd_gline.h
@@ -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
diff --git a/include/ctables.h b/include/ctables.h
index 37ed92ce0..f2994cd8c 100644
--- a/include/ctables.h
+++ b/include/ctables.h
@@ -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;
diff --git a/src/command_parse.cpp b/src/command_parse.cpp
index 0f93e6f53..984ce2314 100644
--- a/src/command_parse.cpp
+++ b/src/command_parse.cpp
@@ -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)