summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2008-10-25 16:41:09 +0000
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2008-10-25 16:41:09 +0000
commitbde833f1827cfc5367602a580d23afcafc12d15b (patch)
treeb2b81e557542aac912320443bd772b818144256c /src
parent2d52c375efbad941407fdc81846b6e11a9d31834 (diff)
Add optional max_params for commands, which means that we can compress 'extra' params, while still accepting ':' terminated params, etc.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10715 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/command_parse.cpp37
1 files changed, 37 insertions, 0 deletions
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)