From 08eee19aff6451171d1c63ecdf9a2c4820bf9da0 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Thu, 6 Jun 2019 16:00:24 +0100 Subject: Make messageflood weights configurable. Also, default TAGMSG to being worth 0.2 NOTICE/PRIVMSG. This should prevent flood kicks from typing notifications. Closes #1649. --- src/modules/m_messageflood.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/modules/m_messageflood.cpp') diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index 3021b1771..7b96804f0 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -36,7 +36,7 @@ class floodsettings unsigned int secs; unsigned int lines; time_t reset; - insp::flat_map counters; + insp::flat_map counters; floodsettings(bool a, unsigned int b, unsigned int c) : ban(a) @@ -46,7 +46,7 @@ class floodsettings reset = ServerInstance->Time() + secs; } - bool addmessage(User* who) + bool addmessage(User* who, double weight) { if (ServerInstance->Time() > reset) { @@ -54,7 +54,8 @@ class floodsettings reset = ServerInstance->Time() + secs; } - return (++counters[who] >= this->lines); + counters[who] += weight; + return (counters[who] >= this->lines); } void clear(User* who) @@ -113,6 +114,9 @@ class ModuleMsgFlood private: CheckExemption::EventProvider exemptionprov; MsgFlood mf; + double notice; + double privmsg; + double tagmsg; public: ModuleMsgFlood() @@ -122,7 +126,15 @@ private: { } - ModResult HandleMessage(User* user, const MessageTarget& target) + void ReadConfig(ConfigStatus&) CXX11_OVERRIDE + { + ConfigTag* tag = ServerInstance->Config->ConfValue("messageflood"); + notice = tag->getFloat("notice", 1.0); + privmsg = tag->getFloat("privmsg", 1.0); + tagmsg = tag->getFloat("tagmsg", 0.2); + } + + ModResult HandleMessage(User* user, const MessageTarget& target, double weight) { if (target.type != MessageTarget::TYPE_CHANNEL) return MOD_RES_PASSTHRU; @@ -138,7 +150,7 @@ private: floodsettings *f = mf.ext.get(dest); if (f) { - if (f->addmessage(user)) + if (f->addmessage(user, weight)) { /* Youre outttta here! */ f->clear(user); @@ -163,12 +175,12 @@ private: ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - return HandleMessage(user, target); + return HandleMessage(user, target, (details.type == MSG_PRIVMSG ? privmsg : notice)); } ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE { - return HandleMessage(user, target); + return HandleMessage(user, target, tagmsg); } void Prioritize() CXX11_OVERRIDE -- cgit v1.3.1-10-gc9f91 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/mode.h | 6 ++++++ include/numericbuilder.h | 27 +++++++++++++++++++++++++-- src/coremods/core_channel/cmode_k.cpp | 1 + src/coremods/core_channel/cmode_l.cpp | 1 + src/coremods/core_channel/core_channel.h | 1 + src/coremods/core_user/umode_s.cpp | 1 + src/mode.cpp | 6 +++++- src/modules/m_anticaps.cpp | 3 ++- src/modules/m_autoop.cpp | 1 + src/modules/m_banexception.cpp | 1 + src/modules/m_chanfilter.cpp | 3 ++- src/modules/m_chanhistory.cpp | 1 + src/modules/m_delaymsg.cpp | 1 + src/modules/m_exemptchanops.cpp | 7 ++++--- src/modules/m_inviteexception.cpp | 1 + src/modules/m_joinflood.cpp | 1 + src/modules/m_kicknorejoin.cpp | 1 + src/modules/m_messageflood.cpp | 1 + src/modules/m_nickflood.cpp | 1 + src/modules/m_redirect.cpp | 5 ++++- src/modules/m_repeat.cpp | 18 +++++++++--------- 21 files changed, 70 insertions(+), 18 deletions(-) (limited to 'src/modules/m_messageflood.cpp') 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); } }; diff --git a/src/coremods/core_channel/cmode_k.cpp b/src/coremods/core_channel/cmode_k.cpp index 43f41ddfd..ff8beeaf9 100644 --- a/src/coremods/core_channel/cmode_k.cpp +++ b/src/coremods/core_channel/cmode_k.cpp @@ -28,6 +28,7 @@ const std::string::size_type ModeChannelKey::maxkeylen = 32; ModeChannelKey::ModeChannelKey(Module* Creator) : ParamMode(Creator, "key", 'k', PARAM_ALWAYS) { + syntax = ""; } ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding) diff --git a/src/coremods/core_channel/cmode_l.cpp b/src/coremods/core_channel/cmode_l.cpp index e71eb500e..d3b806956 100644 --- a/src/coremods/core_channel/cmode_l.cpp +++ b/src/coremods/core_channel/cmode_l.cpp @@ -26,6 +26,7 @@ ModeChannelLimit::ModeChannelLimit(Module* Creator) : ParamMode(Creator, "limit", 'l') , minlimit(0) { + syntax = ""; } bool ModeChannelLimit::ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel*) diff --git a/src/coremods/core_channel/core_channel.h b/src/coremods/core_channel/core_channel.h index c054d5265..bfcf59358 100644 --- a/src/coremods/core_channel/core_channel.h +++ b/src/coremods/core_channel/core_channel.h @@ -168,6 +168,7 @@ class ModeChannelBan : public ListModeBase ModeChannelBan(Module* Creator) : ListModeBase(Creator, "ban", 'b', "End of channel ban list", 367, 368, true) { + syntax = ""; } }; diff --git a/src/coremods/core_user/umode_s.cpp b/src/coremods/core_user/umode_s.cpp index 7c83e008b..4c3725ee5 100644 --- a/src/coremods/core_user/umode_s.cpp +++ b/src/coremods/core_user/umode_s.cpp @@ -26,6 +26,7 @@ ModeUserServerNoticeMask::ModeUserServerNoticeMask(Module* Creator) : ModeHandler(Creator, "snomask", 's', PARAM_SETONLY, MODETYPE_USER) { oper = true; + syntax = "(+|-)"; } ModeAction ModeUserServerNoticeMask::OnModeChange(User* source, User* dest, Channel*, std::string ¶meter, bool adding) diff --git a/src/mode.cpp b/src/mode.cpp index aa4d50b08..159474985 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -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 = ""; } ModResult PrefixMode::AccessCheck(User* src, Channel*, std::string& value, bool adding) diff --git a/src/modules/m_anticaps.cpp b/src/modules/m_anticaps.cpp index ef3c750ce..8f020ed03 100644 --- a/src/modules/m_anticaps.cpp +++ b/src/modules/m_anticaps.cpp @@ -101,6 +101,7 @@ class AntiCapsMode : public ParamMode >(Creator, "anticaps", 'B') { + syntax = "{ban|block|mute|kick|kickban}::"; } ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE @@ -113,7 +114,7 @@ class AntiCapsMode : public ParamModeWriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter, "Invalid anticaps mode parameter. Syntax: :{minlen}:{percent}.")); + source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter)); return MODEACTION_DENY; } diff --git a/src/modules/m_autoop.cpp b/src/modules/m_autoop.cpp index b1b08228c..339666457 100644 --- a/src/modules/m_autoop.cpp +++ b/src/modules/m_autoop.cpp @@ -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 = ":"; tidy = false; } diff --git a/src/modules/m_banexception.cpp b/src/modules/m_banexception.cpp index c7864ea9e..44b93b457 100644 --- a/src/modules/m_banexception.cpp +++ b/src/modules/m_banexception.cpp @@ -41,6 +41,7 @@ class BanException : public ListModeBase BanException(Module* Creator) : ListModeBase(Creator, "banexception", 'e', "End of Channel Exception List", 348, 349, true) { + syntax = ""; } }; diff --git a/src/modules/m_chanfilter.cpp b/src/modules/m_chanfilter.cpp index 051b8c60d..b2323176c 100644 --- a/src/modules/m_chanfilter.cpp +++ b/src/modules/m_chanfilter.cpp @@ -37,13 +37,14 @@ class ChanFilter : public ListModeBase ChanFilter(Module* Creator) : ListModeBase(Creator, "filter", 'g', "End of channel spamfilter list", 941, 940, false) { + syntax = ""; } 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; } diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp index ed7bb684f..7db851ee3 100644 --- a/src/modules/m_chanhistory.cpp +++ b/src/modules/m_chanhistory.cpp @@ -56,6 +56,7 @@ class HistoryMode : public ParamMode > HistoryMode(Module* Creator) : ParamMode >(Creator, "history", 'H') { + syntax = ":"; } ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE diff --git a/src/modules/m_delaymsg.cpp b/src/modules/m_delaymsg.cpp index 6acaa9a2f..04d4119c7 100644 --- a/src/modules/m_delaymsg.cpp +++ b/src/modules/m_delaymsg.cpp @@ -29,6 +29,7 @@ class DelayMsgMode : public ParamMode , jointime("delaymsg", ExtensionItem::EXT_MEMBERSHIP, Parent) { ranktoset = ranktounset = OP_VALUE; + syntax = ""; } bool ResolveModeConflict(std::string& their_param, const std::string& our_param, Channel*) CXX11_OVERRIDE diff --git a/src/modules/m_exemptchanops.cpp b/src/modules/m_exemptchanops.cpp index b10a44859..794b06f6a 100644 --- a/src/modules/m_exemptchanops.cpp +++ b/src/modules/m_exemptchanops.cpp @@ -29,6 +29,7 @@ class ExemptChanOps : public ListModeBase ExemptChanOps(Module* Creator) : ListModeBase(Creator, "exemptchanops", 'X', "End of channel exemptchanops list", 954, 953, false) { + syntax = ":"; } 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 :")); + 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; } diff --git a/src/modules/m_inviteexception.cpp b/src/modules/m_inviteexception.cpp index b12c98b5d..03a2fbc7c 100644 --- a/src/modules/m_inviteexception.cpp +++ b/src/modules/m_inviteexception.cpp @@ -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 = ""; } }; diff --git a/src/modules/m_joinflood.cpp b/src/modules/m_joinflood.cpp index 1b9deac5f..cccdd15b6 100644 --- a/src/modules/m_joinflood.cpp +++ b/src/modules/m_joinflood.cpp @@ -97,6 +97,7 @@ class JoinFlood : public ParamMode > JoinFlood(Module* Creator) : ParamMode >(Creator, "joinflood", 'j') { + syntax = ":"; } ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE diff --git a/src/modules/m_kicknorejoin.cpp b/src/modules/m_kicknorejoin.cpp index ec5ac661e..5130bcbdd 100644 --- a/src/modules/m_kicknorejoin.cpp +++ b/src/modules/m_kicknorejoin.cpp @@ -97,6 +97,7 @@ class KickRejoin : public ParamMode > : ParamMode >(Creator, "kicknorejoin", 'J') , max(60) { + syntax = ""; } ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index 7b96804f0..ea5493c78 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -72,6 +72,7 @@ class MsgFlood : public ParamMode > MsgFlood(Module* Creator) : ParamMode >(Creator, "flood", 'f') { + syntax = "[*]:"; } ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE diff --git a/src/modules/m_nickflood.cpp b/src/modules/m_nickflood.cpp index 9b8bbcdb6..48f085dde 100644 --- a/src/modules/m_nickflood.cpp +++ b/src/modules/m_nickflood.cpp @@ -84,6 +84,7 @@ class NickFlood : public ParamMode > NickFlood(Module* Creator) : ParamMode >(Creator, "nickflood", 'F') { + syntax = ":"; } ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE diff --git a/src/modules/m_redirect.cpp b/src/modules/m_redirect.cpp index 5e14b211e..3d10663aa 100644 --- a/src/modules/m_redirect.cpp +++ b/src/modules/m_redirect.cpp @@ -30,7 +30,10 @@ class Redirect : public ParamMode { public: Redirect(Module* Creator) - : ParamMode(Creator, "redirect", 'L') { } + : ParamMode(Creator, "redirect", 'L') + { + syntax = ""; + } ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE { diff --git a/src/modules/m_repeat.cpp b/src/modules/m_repeat.cpp index a2e9b1f8b..57a6edab6 100644 --- a/src/modules/m_repeat.cpp +++ b/src/modules/m_repeat.cpp @@ -125,6 +125,7 @@ class RepeatMode : public ParamMode > : ParamMode >(Creator, "repeat", 'E') , MemberInfoExt("repeat_memb", ExtensionItem::EXT_MEMBERSHIP, Creator) { + syntax = "[~|*]:[:][:]"; } void OnUnset(User* source, Channel* chan) CXX11_OVERRIDE @@ -140,15 +141,14 @@ class RepeatMode : public ParamMode > ChannelSettings settings; if (!ParseSettings(source, parameter, settings)) { - source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter, - "Invalid repeat syntax. Syntax is: [~|*]:[:][:]")); + 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 > 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 > { 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 > { 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; } -- cgit v1.3.1-10-gc9f91