Show the mode syntax in ERR_INVALIDMODEPARAM.

This commit is contained in:
Peter Powell 2019-06-12 21:46:07 +01:00
parent 938837af9f
commit 9433e34b21
21 changed files with 70 additions and 18 deletions

View File

@ -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;
};

View File

@ -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);
}
};

View File

@ -28,6 +28,7 @@ const std::string::size_type ModeChannelKey::maxkeylen = 32;
ModeChannelKey::ModeChannelKey(Module* Creator)
: ParamMode<ModeChannelKey, LocalStringExt>(Creator, "key", 'k', PARAM_ALWAYS)
{
syntax = "<key>";
}
ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)

View File

@ -26,6 +26,7 @@ ModeChannelLimit::ModeChannelLimit(Module* Creator)
: ParamMode<ModeChannelLimit, LocalIntExt>(Creator, "limit", 'l')
, minlimit(0)
{
syntax = "<limit>";
}
bool ModeChannelLimit::ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel*)

View File

@ -168,6 +168,7 @@ class ModeChannelBan : public ListModeBase
ModeChannelBan(Module* Creator)
: ListModeBase(Creator, "ban", 'b', "End of channel ban list", 367, 368, true)
{
syntax = "<mask>";
}
};

View File

@ -26,6 +26,7 @@ ModeUserServerNoticeMask::ModeUserServerNoticeMask(Module* Creator)
: ModeHandler(Creator, "snomask", 's', PARAM_SETONLY, MODETYPE_USER)
{
oper = true;
syntax = "(+|-)<snomasks>";
}
ModeAction ModeUserServerNoticeMask::OnModeChange(User* source, User* dest, Channel*, std::string &parameter, bool adding)

View File

@ -89,7 +89,10 @@ void ModeHandler::DisplayEmptyList(User*, Channel*)
void ModeHandler::OnParameterMissing(User* user, User* dest, Channel* channel)
{
const std::string message = InspIRCd::Format("You must specify a parameter for the %s mode", name.c_str());
std::string message = InspIRCd::Format("You must specify a parameter for the %s mode.", name.c_str());
if (!syntax.empty())
message.append(InspIRCd::Format(" Syntax: %s.", syntax.c_str()));
if (channel)
user->WriteNumeric(Numerics::InvalidModeParameter(channel, this, "*", message));
else
@ -171,6 +174,7 @@ PrefixMode::PrefixMode(Module* Creator, const std::string& Name, char ModeLetter
, selfremove(true)
{
list = true;
syntax = "<nick>";
}
ModResult PrefixMode::AccessCheck(User* src, Channel*, std::string& value, bool adding)

View File

@ -101,6 +101,7 @@ class AntiCapsMode : public ParamMode<AntiCapsMode, SimpleExtItem<AntiCapsSettin
AntiCapsMode(Module* Creator)
: ParamMode<AntiCapsMode, SimpleExtItem<AntiCapsSettings> >(Creator, "anticaps", 'B')
{
syntax = "{ban|block|mute|kick|kickban}:<minlen>:<percent>";
}
ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE
@ -113,7 +114,7 @@ class AntiCapsMode : public ParamMode<AntiCapsMode, SimpleExtItem<AntiCapsSettin
// Attempt to parse the method.
if (!ParseMethod(stream, method) || !ParseMinimumLength(stream, minlen) || !ParsePercent(stream, percent))
{
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter, "Invalid anticaps mode parameter. Syntax: <ban|block|mute|kick|kickban>:{minlen}:{percent}."));
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter));
return MODEACTION_DENY;
}

View File

@ -30,6 +30,7 @@ class AutoOpList : public ListModeBase
: ListModeBase(Creator, "autoop", 'w', "End of Channel Access List", 910, 911, true)
{
ranktoset = ranktounset = OP_VALUE;
syntax = "<prefix>:<mask>";
tidy = false;
}

View File

@ -41,6 +41,7 @@ class BanException : public ListModeBase
BanException(Module* Creator)
: ListModeBase(Creator, "banexception", 'e', "End of Channel Exception List", 348, 349, true)
{
syntax = "<mask>";
}
};

View File

@ -37,13 +37,14 @@ class ChanFilter : public ListModeBase
ChanFilter(Module* Creator)
: ListModeBase(Creator, "filter", 'g', "End of channel spamfilter list", 941, 940, false)
{
syntax = "<pattern>";
}
bool ValidateParam(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE
{
if (word.length() > maxlen)
{
user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Word is too long for the spamfilter list"));
user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Word is too long for the spamfilter list."));
return false;
}

View File

@ -56,6 +56,7 @@ class HistoryMode : public ParamMode<HistoryMode, SimpleExtItem<HistoryList> >
HistoryMode(Module* Creator)
: ParamMode<HistoryMode, SimpleExtItem<HistoryList> >(Creator, "history", 'H')
{
syntax = "<max-messages>:<max-duration>";
}
ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE

View File

@ -29,6 +29,7 @@ class DelayMsgMode : public ParamMode<DelayMsgMode, LocalIntExt>
, jointime("delaymsg", ExtensionItem::EXT_MEMBERSHIP, Parent)
{
ranktoset = ranktounset = OP_VALUE;
syntax = "<seconds>";
}
bool ResolveModeConflict(std::string& their_param, const std::string& our_param, Channel*) CXX11_OVERRIDE

View File

@ -29,6 +29,7 @@ class ExemptChanOps : public ListModeBase
ExemptChanOps(Module* Creator)
: ListModeBase(Creator, "exemptchanops", 'X', "End of channel exemptchanops list", 954, 953, false)
{
syntax = "<restriction>:<prefix>";
}
static PrefixMode* FindMode(const std::string& mode)
@ -77,7 +78,7 @@ class ExemptChanOps : public ListModeBase
std::string prefix;
if (!ParseEntry(word, restriction, prefix))
{
user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Invalid exemptchanops entry, format is <restriction>:<prefix>"));
user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word));
return false;
}
@ -89,13 +90,13 @@ class ExemptChanOps : public ListModeBase
if (!ServerInstance->Modes->FindMode(restriction, MODETYPE_CHANNEL))
{
user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Unknown restriction"));
user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Unknown restriction."));
return false;
}
if (prefix != "*" && !FindMode(prefix))
{
user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Unknown prefix mode"));
user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Unknown prefix mode."));
return false;
}

View File

@ -42,6 +42,7 @@ class InviteException : public ListModeBase
InviteException(Module* Creator)
: ListModeBase(Creator, "invex", 'I', "End of Channel Invite Exception List", 346, 347, true)
{
syntax = "<mask>";
}
};

View File

@ -97,6 +97,7 @@ class JoinFlood : public ParamMode<JoinFlood, SimpleExtItem<joinfloodsettings> >
JoinFlood(Module* Creator)
: ParamMode<JoinFlood, SimpleExtItem<joinfloodsettings> >(Creator, "joinflood", 'j')
{
syntax = "<joins>:<seconds>";
}
ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE

View File

@ -97,6 +97,7 @@ class KickRejoin : public ParamMode<KickRejoin, SimpleExtItem<KickRejoinData> >
: ParamMode<KickRejoin, SimpleExtItem<KickRejoinData> >(Creator, "kicknorejoin", 'J')
, max(60)
{
syntax = "<seconds>";
}
ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE

View File

@ -72,6 +72,7 @@ class MsgFlood : public ParamMode<MsgFlood, SimpleExtItem<floodsettings> >
MsgFlood(Module* Creator)
: ParamMode<MsgFlood, SimpleExtItem<floodsettings> >(Creator, "flood", 'f')
{
syntax = "[*]<messages>:<seconds>";
}
ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE

View File

@ -84,6 +84,7 @@ class NickFlood : public ParamMode<NickFlood, SimpleExtItem<nickfloodsettings> >
NickFlood(Module* Creator)
: ParamMode<NickFlood, SimpleExtItem<nickfloodsettings> >(Creator, "nickflood", 'F')
{
syntax = "<nick-changes>:<seconds>";
}
ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE

View File

@ -30,7 +30,10 @@ class Redirect : public ParamMode<Redirect, LocalStringExt>
{
public:
Redirect(Module* Creator)
: ParamMode<Redirect, LocalStringExt>(Creator, "redirect", 'L') { }
: ParamMode<Redirect, LocalStringExt>(Creator, "redirect", 'L')
{
syntax = "<target>";
}
ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE
{

View File

@ -125,6 +125,7 @@ class RepeatMode : public ParamMode<RepeatMode, SimpleExtItem<ChannelSettings> >
: ParamMode<RepeatMode, SimpleExtItem<ChannelSettings> >(Creator, "repeat", 'E')
, MemberInfoExt("repeat_memb", ExtensionItem::EXT_MEMBERSHIP, Creator)
{
syntax = "[~|*]<lines>:<sec>[:<difference>][:<backlog>]";
}
void OnUnset(User* source, Channel* chan) CXX11_OVERRIDE
@ -140,15 +141,14 @@ class RepeatMode : public ParamMode<RepeatMode, SimpleExtItem<ChannelSettings> >
ChannelSettings settings;
if (!ParseSettings(source, parameter, settings))
{
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter,
"Invalid repeat syntax. Syntax is: [~|*]<lines>:<sec>[:<difference>][:<backlog>]"));
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter));
return MODEACTION_DENY;
}
if ((settings.Backlog > 0) && (settings.Lines > settings.Backlog))
{
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter,
"Invalid repeat syntax. You can't set lines higher than backlog."));
"You can't set lines higher than backlog."));
return MODEACTION_DENY;
}
@ -309,14 +309,14 @@ class RepeatMode : public ParamMode<RepeatMode, SimpleExtItem<ChannelSettings> >
if (ms.MaxLines && settings.Lines > ms.MaxLines)
{
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter, InspIRCd::Format(
"Invalid repeat parameter. The line number you specified is too great. Maximum allowed is %u.", ms.MaxLines)));
"The line number you specified is too big. Maximum allowed is %u.", ms.MaxLines)));
return false;
}
if (ms.MaxSecs && settings.Seconds > ms.MaxSecs)
{
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter, InspIRCd::Format(
"Invalid repeat parameter. The seconds you specified are too great. Maximum allowed is %u.", ms.MaxSecs)));
"The seconds you specified are too big. Maximum allowed is %u.", ms.MaxSecs)));
return false;
}
@ -324,10 +324,10 @@ class RepeatMode : public ParamMode<RepeatMode, SimpleExtItem<ChannelSettings> >
{
if (ms.MaxDiff == 0)
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter,
"Invalid repeat parameter. The server administrator has disabled matching on edit distance."));
"The server administrator has disabled matching on edit distance."));
else
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter, InspIRCd::Format(
"Invalid repeat parameter. The distance you specified is too great. Maximum allowed is %u.", ms.MaxDiff)));
"The distance you specified is too big. Maximum allowed is %u.", ms.MaxDiff)));
return false;
}
@ -335,10 +335,10 @@ class RepeatMode : public ParamMode<RepeatMode, SimpleExtItem<ChannelSettings> >
{
if (ms.MaxBacklog == 0)
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter,
"Invalid repeat parameter. The server administrator has disabled backlog matching."));
"The server administrator has disabled backlog matching."));
else
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter, InspIRCd::Format(
"Invalid repeat paramter. The backlog you specified is too great. Maximum allowed is %u.", ms.MaxBacklog)));
"The backlog you specified is too big. Maximum allowed is %u.", ms.MaxBacklog)));
return false;
}