X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcommand_parse.cpp;h=c2ae39d494e3a75579d4635f36f62394d5c95671;hb=654355c2d114a68639ac36238291ebfceec2537d;hp=c133c475e333c1fbe5a602dc6691b012813adad4;hpb=02838a09396a3626b61263791570e96324563fa0;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/command_parse.cpp b/src/command_parse.cpp index c133c475e..c2ae39d49 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -93,13 +93,14 @@ bool CommandParser::LoopCall(User* user, Command* handler, const CommandBase::Pa new_parameters[extra] = item; } - CmdResult result = handler->Handle(user, new_parameters); + CommandBase::Params params(new_parameters, parameters.GetTags()); + CmdResult result = handler->Handle(user, params); if (localuser) { - // Run the OnPostCommand hook with the last parameter (original line) being empty - // to indicate that the command had more targets in its original form. + // Run the OnPostCommand hook with the last parameter being true to indicate + // that the event is being called in a loop. item.clear(); - FOREACH_MOD(OnPostCommand, (handler, new_parameters, localuser, result)); + FOREACH_MOD(OnPostCommand, (handler, new_parameters, localuser, result, true)); } } } @@ -152,14 +153,16 @@ CmdResult CommandParser::CallHandler(const std::string& commandname, const Comma { if (cmd) *cmd = n->second; - return n->second->Handle(user, parameters); + + ClientProtocol::TagMap tags; + return n->second->Handle(user, CommandBase::Params(parameters, tags)); } } } return CMD_INVALID; } -void CommandParser::ProcessCommand(LocalUser* user, std::string& command, Command::Params& command_p) +void CommandParser::ProcessCommand(LocalUser* user, std::string& command, CommandBase::Params& command_p) { /* find the command, check it exists */ Command* handler = GetHandler(command); @@ -313,7 +316,7 @@ void CommandParser::ProcessCommand(LocalUser* user, std::string& command, Comman */ CmdResult result = handler->Handle(user, command_p); - FOREACH_MOD(OnPostCommand, (handler, command_p, user, result)); + FOREACH_MOD(OnPostCommand, (handler, command_p, user, result, false)); } } @@ -369,44 +372,14 @@ void Command::RegisterService() void CommandParser::ProcessBuffer(LocalUser* user, const std::string& buffer) { - size_t start = buffer.find_first_not_of(" "); - if (start == std::string::npos) - { - // Discourage the user from flooding the server. - user->CommandFloodPenalty += 2000; + ClientProtocol::ParseOutput parseoutput; + if (!user->serializer->Parse(user, buffer, parseoutput)) return; - } - - ServerInstance->Logs->Log("USERINPUT", LOG_RAWIO, "C[%s] I %s", user->uuid.c_str(), buffer.c_str()); - - irc::tokenstream tokens(buffer, start); - std::string command; - CommandBase::Params parameters; - - // Get the command name. This will always exist because of the check - // at the start of the function. - tokens.GetMiddle(command); - // If this exists then the client sent a prefix as part of their - // message. Section 2.3 of RFC 1459 technically says we should only - // allow the nick of the client here but in practise everyone just - // ignores it so we will copy them. - if (command[0] == ':' && !tokens.GetMiddle(command)) - { - // Discourage the user from flooding the server. - user->CommandFloodPenalty += 2000; - return; - } - - // We upper-case the command name to ensure consistency internally. + std::string& command = parseoutput.cmd; std::transform(command.begin(), command.end(), command.begin(), ::toupper); - // Build the parameter map. We intentionally do not respect the RFC 1459 - // thirteen parameter limit here. - std::string parameter; - while (tokens.GetTrailing(parameter)) - parameters.push_back(parameter); - + CommandBase::Params parameters(parseoutput.params, parseoutput.tags); ProcessCommand(user, command, parameters); } @@ -425,7 +398,7 @@ CommandParser::CommandParser() { } -std::string CommandParser::TranslateUIDs(const std::vector& to, const std::vector& source, bool prefix_final, CommandBase* custom_translator) +std::string CommandParser::TranslateUIDs(const std::vector& to, const CommandBase::Params& source, bool prefix_final, CommandBase* custom_translator) { std::vector::const_iterator types = to.begin(); std::string dest; @@ -479,7 +452,7 @@ void CommandParser::TranslateSingleParam(TranslateType to, const std::string& it } // If no custom translator was given, fall through } - case TR_TEXT: + /*@fallthrough@*/ default: /* Do nothing */ dest.append(item);