From bde833f1827cfc5367602a580d23afcafc12d15b Mon Sep 17 00:00:00 2001 From: w00t Date: Sat, 25 Oct 2008 16:41:09 +0000 Subject: 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 --- src/command_parse.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/command_parse.cpp') 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::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) -- cgit v1.2.3