diff options
author | Peter Powell <petpow@saberuk.com> | 2018-01-27 13:05:14 +0000 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2018-01-29 11:52:13 +0000 |
commit | d5a6054948502625d7f0c235f6faaeea58734de5 (patch) | |
tree | a43e95ded07dca92c9d3659e331a88cb8e0b7b21 /include | |
parent | 3398ce7e50f1c269e8221df04e1eefb52d54c820 (diff) |
Add ERR_INVALIDMODEPARAM for responding to invalid mode params.
Currently on invalid modes we do a combination of different things:
1. Send a custom mode-specific numeric (which often collides with
other modes).
2. Send a server notice.
3. Do absolutely nothing.
This new numeric is a generic way of handling invalid parameters
when setting a mode that avoids all of the mistakes of the previous
behaviour.
Diffstat (limited to 'include')
-rw-r--r-- | include/numeric.h | 27 | ||||
-rw-r--r-- | include/numericbuilder.h | 54 | ||||
-rw-r--r-- | include/numerics.h | 1 |
3 files changed, 55 insertions, 27 deletions
diff --git a/include/numeric.h b/include/numeric.h index 8ea2447bf..85f2f13f0 100644 --- a/include/numeric.h +++ b/include/numeric.h @@ -85,30 +85,3 @@ class Numeric::Numeric */ std::vector<std::string>& GetParams() { return params; } }; - -namespace Numerics -{ - /** Builder for the ERR_NOSUCHNICK numeric. */ - class NoSuchNick : public Numeric::Numeric - { - public: - NoSuchNick(const std::string& nick) - : Numeric(ERR_NOSUCHNICK) - { - push(nick); - push("No such nick"); - } - }; - - /** Builder for the ERR_NOSUCHCHANNEL numeric. */ - class NoSuchChannel : public Numeric::Numeric - { - public: - NoSuchChannel(const std::string& chan) - : Numeric(ERR_NOSUCHCHANNEL) - { - push(chan); - push("No such channel"); - } - }; -} diff --git a/include/numericbuilder.h b/include/numericbuilder.h index 17aa9e0c8..0d55093ca 100644 --- a/include/numericbuilder.h +++ b/include/numericbuilder.h @@ -196,3 +196,57 @@ class Numeric::ParamBuilder : public GenericParamBuilder<NumStaticParams, SendEm { } }; + +namespace Numerics +{ + class InvalidModeParameter; + class NoSuchChannel; + class NoSuchNick; +} + +/* Builder for the ERR_INVALIDMODEPARAM numeric. */ +class Numerics::InvalidModeParameter : public Numeric::Numeric +{ + public: + InvalidModeParameter(Channel* chan, ModeHandler* mode, const std::string& parameter, const std::string& message = "") + : Numeric(ERR_INVALIDMODEPARAM) + { + push(chan->name); + push(mode->GetModeChar()); + push(parameter); + push(message.empty() ? InspIRCd::Format("Invalid %s mode parameter", mode->name.c_str()) : message); + } + + InvalidModeParameter(User* user, ModeHandler* mode, const std::string& parameter, const std::string& message = "") + : Numeric(ERR_INVALIDMODEPARAM) + { + 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); + } +}; + +/** Builder for the ERR_NOSUCHCHANNEL numeric. */ +class Numerics::NoSuchChannel : public Numeric::Numeric +{ + public: + NoSuchChannel(const std::string& chan) + : Numeric(ERR_NOSUCHCHANNEL) + { + push(chan); + push("No such channel"); + } +}; + +/** Builder for the ERR_NOSUCHNICK numeric. */ +class Numerics::NoSuchNick : public Numeric::Numeric +{ + public: + NoSuchNick(const std::string& nick) + : Numeric(ERR_NOSUCHNICK) + { + push(nick); + push("No such nick"); + } +}; diff --git a/include/numerics.h b/include/numerics.h index 57ecee4df..740ee1797 100644 --- a/include/numerics.h +++ b/include/numerics.h @@ -184,6 +184,7 @@ enum ERR_CANTSENDTOUSER = 531, // ??? RPL_SYNTAX = 650, // insp-specific + ERR_INVALIDMODEPARAM = 696, // insp-specific ERR_CHANOPEN = 713, ERR_KNOCKONCHAN = 714, |