]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Allow commands to override ERR_{NEEDSMOREPARAMS,NOTREGISTERED}.
authorSadie Powell <sadie@witchery.services>
Wed, 18 Mar 2020 10:54:37 +0000 (10:54 +0000)
committerSadie Powell <sadie@witchery.services>
Wed, 18 Mar 2020 11:26:05 +0000 (11:26 +0000)
include/ctables.h
src/command_parse.cpp
src/commands.cpp

index a3fcdfbd4ca23266cc9aaca44d6def330c0695a3..22c0ef67eb60003abd24366295def4fbac10f599 100644 (file)
@@ -236,6 +236,18 @@ class CoreExport Command : public CommandBase
 
        /** Registers this command with the command parser. */
        void RegisterService() CXX11_OVERRIDE;
+
+       /** Tells the user they did not specify enough parameters.
+        * @param user The user who issued the command.
+        * @param parameters The parameters for the command.
+        */
+       virtual void TellNotEnoughParameters(LocalUser* user, const Params& parameters);
+
+       /** Tells the user they need to be registered to execute this command.
+        * @param user The user who issued the command.
+        * @param parameters The parameters for the command.
+        */
+       virtual void TellNotRegistered(LocalUser* user, const Params& parameters);
 };
 
 class CoreExport SplitCommand : public Command
index c4e55c3ca4db806fc31ab3afb1acdcc0b97ed85b..7174310874d453c8992e1857712c9a7527322087 100644 (file)
@@ -283,9 +283,7 @@ void CommandParser::ProcessCommand(LocalUser* user, std::string& command, Comman
        if (command_p.size() < handler->min_params)
        {
                user->CommandFloodPenalty += failpenalty;
-               user->WriteNumeric(ERR_NEEDMOREPARAMS, command, "Not enough parameters.");
-               if ((ServerInstance->Config->SyntaxHints) && (user->registered == REG_ALL) && (handler->syntax.length()))
-                       user->WriteNumeric(RPL_SYNTAX, handler->name, handler->syntax);
+               handler->TellNotEnoughParameters(user, command_p);
                FOREACH_MOD(OnCommandBlocked, (command, command_p, user));
                return;
        }
@@ -293,7 +291,7 @@ void CommandParser::ProcessCommand(LocalUser* user, std::string& command, Comman
        if ((user->registered != REG_ALL) && (!handler->works_before_reg))
        {
                user->CommandFloodPenalty += failpenalty;
-               user->WriteNumeric(ERR_NOTREGISTERED, command, "You have not registered");
+               handler->TellNotRegistered(user, command_p);
                FOREACH_MOD(OnCommandBlocked, (command, command_p, user));
        }
        else
index 8343cfaacbbf8e85964c149ed384dd273900821b..d1746bc5f0f66d962b3315e4a9c63d5dfa9a74e4 100644 (file)
@@ -66,6 +66,17 @@ void Command::RegisterService()
                throw ModuleException("Command already exists: " + name);
 }
 
+void Command::TellNotEnoughParameters(LocalUser* user, const Params& parameters)
+{
+       user->WriteNumeric(ERR_NEEDMOREPARAMS, name, "Not enough parameters.");
+       if (ServerInstance->Config->SyntaxHints && user->registered == REG_ALL && syntax.length())
+               user->WriteNumeric(RPL_SYNTAX, name, syntax);
+}
+
+void Command::TellNotRegistered(LocalUser* user, const Params& parameters)
+{
+       user->WriteNumeric(ERR_NOTREGISTERED, name, "You have not registered.");
+}
 
 SplitCommand::SplitCommand(Module* me, const std::string& cmd, unsigned int minpara, unsigned int maxpara)
        : Command(me, cmd, minpara, maxpara)