diff options
author | Peter Powell <petpow@saberuk.com> | 2019-06-12 21:46:07 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2019-06-12 21:52:58 +0100 |
commit | 9433e34b2133d8f1e77fea15447ba4d0259a5fb0 (patch) | |
tree | 8e6bb357472f2e39c31c82053a1d02d4b1f7460d /include | |
parent | 938837af9fe92d0fef811db96a5e9d6bf8e3ae11 (diff) |
Show the mode syntax in ERR_INVALIDMODEPARAM.
Diffstat (limited to 'include')
-rw-r--r-- | include/mode.h | 6 | ||||
-rw-r--r-- | include/numericbuilder.h | 27 |
2 files changed, 31 insertions, 2 deletions
diff --git a/include/mode.h b/include/mode.h index fe02838b2..683f4b55b 100644 --- a/include/mode.h +++ b/include/mode.h @@ -154,6 +154,9 @@ class CoreExport ModeHandler : public ServiceProvider /** The prefix rank required to unset this mode on channels. */ unsigned int ranktounset; + /** If non-empty then the syntax of the parameter for this mode. */ + std::string syntax; + public: /** * The constructor for ModeHandler initalizes the mode handler. @@ -329,6 +332,9 @@ class CoreExport ModeHandler : public ServiceProvider return adding ? ranktoset : ranktounset; } + /** Retrieves the syntax of the parameter for this mode. */ + const std::string& GetSyntax() const { return syntax; } + friend class ModeParser; }; 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); } }; |