diff options
Diffstat (limited to 'src/command_parse.cpp')
-rw-r--r-- | src/command_parse.cpp | 37 |
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) |