]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/command_parse.cpp
Convert InspIRCd::SetSignals to a static function.
[user/henk/code/inspircd.git] / src / command_parse.cpp
index c133c475e333c1fbe5a602dc6691b012813adad4..57db5d496c3dc99f3852e7a00be08e622e753fc9 100644 (file)
@@ -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));
                        }
                }
        }
@@ -138,7 +139,7 @@ CmdResult CommandParser::CallHandler(const std::string& commandname, const Comma
                                if (user->IsModeSet(n->second->flags_needed))
                                {
                                        /* if user has the flags, and now has the permissions, go ahead */
-                                       if (user->HasPermission(commandname))
+                                       if (user->HasCommandPermission(commandname))
                                                bOkay = 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);
@@ -243,7 +246,7 @@ void CommandParser::ProcessCommand(LocalUser* user, std::string& command, Comman
                return;
 
        /* activity resets the ping pending timer */
-       user->nping = ServerInstance->Time() + user->MyClass->GetPingTime();
+       user->nextping = ServerInstance->Time() + user->MyClass->GetPingTime();
 
        if (handler->flags_needed)
        {
@@ -254,7 +257,7 @@ void CommandParser::ProcessCommand(LocalUser* user, std::string& command, Comman
                        return;
                }
 
-               if (!user->HasPermission(command))
+               if (!user->HasCommandPermission(command))
                {
                        user->CommandFloodPenalty += failpenalty;
                        user->WriteNumeric(ERR_NOPRIVILEGES, InspIRCd::Format("Permission Denied - Oper type %s does not have access to command %s",
@@ -263,24 +266,6 @@ void CommandParser::ProcessCommand(LocalUser* user, std::string& command, Comman
                }
        }
 
-       if ((user->registered == REG_ALL) && (!user->IsOper()) && (handler->IsDisabled()))
-       {
-               /* command is disabled! */
-               user->CommandFloodPenalty += failpenalty;
-               if (ServerInstance->Config->DisabledDontExist)
-               {
-                       user->WriteNumeric(ERR_UNKNOWNCOMMAND, command, "Unknown command");
-               }
-               else
-               {
-                       user->WriteNumeric(ERR_UNKNOWNCOMMAND, command, "This command has been disabled.");
-               }
-
-               ServerInstance->SNO->WriteToSnoMask('a', "%s denied for %s (%s@%s)",
-                               command.c_str(), user->nick.c_str(), user->ident.c_str(), user->GetRealHost().c_str());
-               return;
-       }
-
        if ((!command_p.empty()) && (command_p.back().empty()) && (!handler->allow_empty_last_param))
                command_p.pop_back();
 
@@ -313,7 +298,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));
        }
 }
 
@@ -330,7 +315,6 @@ CommandBase::CommandBase(Module* mod, const std::string& cmd, unsigned int minpa
        , min_params(minpara)
        , max_params(maxpara)
        , use_count(0)
-       , disabled(false)
        , works_before_reg(false)
        , allow_empty_last_param(true)
        , Penalty(1)
@@ -369,44 +353,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;
-               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;
+       ClientProtocol::ParseOutput parseoutput;
+       if (!user->serializer->Parse(user, buffer, parseoutput))
                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 +379,7 @@ CommandParser::CommandParser()
 {
 }
 
-std::string CommandParser::TranslateUIDs(const std::vector<TranslateType>& to, const std::vector<std::string>& source, bool prefix_final, CommandBase* custom_translator)
+std::string CommandParser::TranslateUIDs(const std::vector<TranslateType>& to, const CommandBase::Params& source, bool prefix_final, CommandBase* custom_translator)
 {
        std::vector<TranslateType>::const_iterator types = to.begin();
        std::string dest;
@@ -479,7 +433,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);