From 9433e34b2133d8f1e77fea15447ba4d0259a5fb0 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Wed, 12 Jun 2019 21:46:07 +0100 Subject: Show the mode syntax in ERR_INVALIDMODEPARAM. --- include/numericbuilder.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'include/numericbuilder.h') diff --git a/include/numericbuilder.h b/include/numericbuilder.h index 0d55093ca..4431fbc52 100644 --- a/include/numericbuilder.h +++ b/include/numericbuilder.h @@ -207,6 +207,29 @@ namespace Numerics /* Builder for the ERR_INVALIDMODEPARAM numeric. */ class Numerics::InvalidModeParameter : public Numeric::Numeric { + private: + void push_message(ModeHandler* mode, const std::string& message) + { + if (!message.empty()) + { + // The caller has specified their own message. + push(message); + return; + } + + const std::string& syntax = mode->GetSyntax(); + if (!syntax.empty()) + { + // If the mode has a syntax hint we include it in the message. + push(InspIRCd::Format("Invalid %s mode parameter. Syntax: %s.", mode->name.c_str(), syntax.c_str())); + } + else + { + // Otherwise, send it without. + push(InspIRCd::Format("Invalid %s mode parameter.", mode->name.c_str())); + } + } + public: InvalidModeParameter(Channel* chan, ModeHandler* mode, const std::string& parameter, const std::string& message = "") : Numeric(ERR_INVALIDMODEPARAM) @@ -214,7 +237,7 @@ class Numerics::InvalidModeParameter : public Numeric::Numeric push(chan->name); push(mode->GetModeChar()); push(parameter); - push(message.empty() ? InspIRCd::Format("Invalid %s mode parameter", mode->name.c_str()) : message); + push_message(mode, message); } InvalidModeParameter(User* user, ModeHandler* mode, const std::string& parameter, const std::string& message = "") @@ -223,7 +246,7 @@ class Numerics::InvalidModeParameter : public Numeric::Numeric push(user->registered & REG_NICK ? user->nick : "*"); push(mode->GetModeChar()); push(parameter); - push(message.empty() ? InspIRCd::Format("Invalid %s mode parameter", mode->name.c_str()) : message); + push_message(mode, message); } }; -- cgit v1.2.3