From 1899ce4e2151dd1ea5741df106ba1e71c63eb0b2 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 27 Feb 2020 11:01:32 +0000 Subject: Move user command stuff from CommandBase to Command. --- src/command_parse.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/command_parse.cpp') diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 0405a5659..f8c88a9f0 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -290,7 +290,7 @@ void CommandParser::ProcessCommand(LocalUser* user, std::string& command, Comman return; } - if ((user->registered != REG_ALL) && (!handler->WorksBeforeReg())) + if ((user->registered != REG_ALL) && (!handler->works_before_reg)) { user->CommandFloodPenalty += failpenalty; user->WriteNumeric(ERR_NOTREGISTERED, command, "You have not registered"); @@ -327,13 +327,9 @@ void CommandParser::RemoveCommand(Command* x) CommandBase::CommandBase(Module* mod, const std::string& cmd, unsigned int minpara, unsigned int maxpara) : ServiceProvider(mod, cmd, SERVICE_COMMAND) - , flags_needed(0) , min_params(minpara) , max_params(maxpara) - , use_count(0) - , works_before_reg(false) , allow_empty_last_param(true) - , Penalty(1) { } @@ -352,7 +348,11 @@ RouteDescriptor CommandBase::GetRouting(User* user, const Params& parameters) Command::Command(Module* mod, const std::string& cmd, unsigned int minpara, unsigned int maxpara) : CommandBase(mod, cmd, minpara, maxpara) + , flags_needed(0) , force_manual_route(false) + , Penalty(1) + , use_count(0) + , works_before_reg(false) { } -- cgit v1.3.1-10-gc9f91 From 8d1255a82c1bdb53928a007be113caff15683d53 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 27 Feb 2020 12:16:25 +0000 Subject: Move command stuff to a more appropriate source file. --- src/command_parse.cpp | 42 ------------------------------------------ src/commands.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 42 deletions(-) (limited to 'src/command_parse.cpp') diff --git a/src/command_parse.cpp b/src/command_parse.cpp index f8c88a9f0..11d3cf15b 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -325,48 +325,6 @@ void CommandParser::RemoveCommand(Command* x) cmdlist.erase(n); } -CommandBase::CommandBase(Module* mod, const std::string& cmd, unsigned int minpara, unsigned int maxpara) - : ServiceProvider(mod, cmd, SERVICE_COMMAND) - , min_params(minpara) - , max_params(maxpara) - , allow_empty_last_param(true) -{ -} - -CommandBase::~CommandBase() -{ -} - -void CommandBase::EncodeParameter(std::string& parameter, unsigned int index) -{ -} - -RouteDescriptor CommandBase::GetRouting(User* user, const Params& parameters) -{ - return ROUTE_LOCALONLY; -} - -Command::Command(Module* mod, const std::string& cmd, unsigned int minpara, unsigned int maxpara) - : CommandBase(mod, cmd, minpara, maxpara) - , flags_needed(0) - , force_manual_route(false) - , Penalty(1) - , use_count(0) - , works_before_reg(false) -{ -} - -Command::~Command() -{ - ServerInstance->Parser.RemoveCommand(this); -} - -void Command::RegisterService() -{ - if (!ServerInstance->Parser.AddCommand(this)) - throw ModuleException("Command already exists: " + name); -} - void CommandParser::ProcessBuffer(LocalUser* user, const std::string& buffer) { ClientProtocol::ParseOutput parseoutput; diff --git a/src/commands.cpp b/src/commands.cpp index 9215a4db5..8343cfaac 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -24,6 +24,49 @@ #include "inspircd.h" +CommandBase::CommandBase(Module* mod, const std::string& cmd, unsigned int minpara, unsigned int maxpara) + : ServiceProvider(mod, cmd, SERVICE_COMMAND) + , min_params(minpara) + , max_params(maxpara) + , allow_empty_last_param(true) +{ +} + +CommandBase::~CommandBase() +{ +} + +void CommandBase::EncodeParameter(std::string& parameter, unsigned int index) +{ +} + +RouteDescriptor CommandBase::GetRouting(User* user, const Params& parameters) +{ + return ROUTE_LOCALONLY; +} + +Command::Command(Module* mod, const std::string& cmd, unsigned int minpara, unsigned int maxpara) + : CommandBase(mod, cmd, minpara, maxpara) + , flags_needed(0) + , force_manual_route(false) + , Penalty(1) + , use_count(0) + , works_before_reg(false) +{ +} + +Command::~Command() +{ + ServerInstance->Parser.RemoveCommand(this); +} + +void Command::RegisterService() +{ + if (!ServerInstance->Parser.AddCommand(this)) + throw ModuleException("Command already exists: " + name); +} + + SplitCommand::SplitCommand(Module* me, const std::string& cmd, unsigned int minpara, unsigned int maxpara) : Command(me, cmd, minpara, maxpara) { -- cgit v1.3.1-10-gc9f91 From 55882c39f1025e29674c42741ee1e00ec8c2169e Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 11 Mar 2020 13:58:45 +0000 Subject: Fix detection of the "plaintext" pseudo-hash being case sensitive. --- src/command_parse.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/command_parse.cpp') diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 11d3cf15b..c4e55c3ca 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -39,7 +39,7 @@ bool InspIRCd::PassCompare(Extensible* ex, const std::string& data, const std::s return false; /* We dont handle any hash types except for plaintext - Thanks tra26 */ - if (!hashtype.empty() && hashtype != "plaintext") + if (!hashtype.empty() && !stdalgo::string::equalsci(hashtype, "plaintext")) return false; return TimingSafeCompare(data, input); -- cgit v1.3.1-10-gc9f91 From 92d83e91038eb54a8200815d5d948c2b61dacce4 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 18 Mar 2020 10:54:37 +0000 Subject: Allow commands to override ERR_{NEEDSMOREPARAMS,NOTREGISTERED}. --- include/ctables.h | 12 ++++++++++++ src/command_parse.cpp | 6 ++---- src/commands.cpp | 11 +++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) (limited to 'src/command_parse.cpp') diff --git a/include/ctables.h b/include/ctables.h index a3fcdfbd4..22c0ef67e 100644 --- a/include/ctables.h +++ b/include/ctables.h @@ -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 diff --git a/src/command_parse.cpp b/src/command_parse.cpp index c4e55c3ca..717431087 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -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 diff --git a/src/commands.cpp b/src/commands.cpp index 8343cfaac..d1746bc5f 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -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) -- cgit v1.3.1-10-gc9f91