]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_repeat.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_repeat.cpp
index 609fd9d60d36c258359c3250bde9c07e6aca8aa2..33ca5b057d33d8de42fa3c876e3ad7ea6dce247e 100644 (file)
@@ -1,6 +1,13 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
+ *   Copyright (C) 2021 iwalkalone <iwalkalone69@gmail.com>
+ *   Copyright (C) 2019 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2018-2019 linuxdaemon <linuxdaemon.irc@gmail.com>
+ *   Copyright (C) 2018 Matt Schatz <genius3000@g3k.solutions>
+ *   Copyright (C) 2017-2019 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2015 James Lu <GLolol@overdrivenetworks.com>
+ *   Copyright (C) 2013-2015 Attila Molnar <attilamolnar@hush.com>
  *   Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
@@ -23,7 +30,7 @@
 class ChannelSettings
 {
  public:
-       enum RepeatAction
+       enum RepeatAction
        {
                ACT_KICK,
                ACT_BLOCK,
@@ -84,6 +91,7 @@ class RepeatMode : public ParamMode<RepeatMode, SimpleExtItem<ChannelSettings> >
                unsigned int MaxBacklog;
                unsigned int MaxDiff;
                unsigned int MaxMessageSize;
+               std::string KickMessage;
                ModuleSettings() : MaxLines(0), MaxSecs(0), MaxBacklog(0), MaxDiff() { }
        };
 
@@ -125,6 +133,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 +149,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;
                }
 
@@ -245,6 +253,8 @@ class RepeatMode : public ParamMode<RepeatMode, SimpleExtItem<ChannelSettings> >
                if (newsize > ServerInstance->Config->Limits.MaxLine)
                        newsize = ServerInstance->Config->Limits.MaxLine;
                Resize(newsize);
+
+               ms.KickMessage = conf->getString("kickmessage", "Repeat flood");
        }
 
        std::string GetModuleSettings() const
@@ -252,6 +262,11 @@ class RepeatMode : public ParamMode<RepeatMode, SimpleExtItem<ChannelSettings> >
                return ConvToStr(ms.MaxLines) + ":" + ConvToStr(ms.MaxSecs) + ":" + ConvToStr(ms.MaxDiff) + ":" + ConvToStr(ms.MaxBacklog);
        }
 
+       std::string GetKickMessage() const
+       {
+               return ms.KickMessage;
+       }
+
        void SerializeParam(Channel* chan, const ChannelSettings* chset, std::string& out)
        {
                chset->serialize(out);
@@ -277,10 +292,7 @@ class RepeatMode : public ParamMode<RepeatMode, SimpleExtItem<ChannelSettings> >
                if ((settings.Lines = ConvToNum<unsigned int>(item)) == 0)
                        return false;
 
-               if (!InspIRCd::Duration(item, settings.Seconds))
-                       return false;
-
-               if ((!stream.GetToken(item)) || (settings.Seconds == 0))
+               if ((!stream.GetToken(item)) || !InspIRCd::Duration(item, settings.Seconds) || (settings.Seconds == 0))
                        // Required parameter missing
                        return false;
 
@@ -312,14 +324,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;
                }
 
@@ -327,10 +339,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;
                }
 
@@ -338,10 +350,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;
                }
 
@@ -399,7 +411,7 @@ class RepeatModule : public Module
                                ServerInstance->Modes->Process(ServerInstance->FakeClient, chan, NULL, changelist);
                        }
 
-                       memb->chan->KickUser(ServerInstance->FakeClient, user, "Repeat flood");
+                       memb->chan->KickUser(ServerInstance->FakeClient, user, rm.GetKickMessage());
                        return MOD_RES_DENY;
                }
                return MOD_RES_PASSTHRU;
@@ -412,7 +424,7 @@ class RepeatModule : public Module
 
        Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("Provides channel mode +E, blocking of similar messages", VF_COMMON|VF_VENDOR, rm.GetModuleSettings());
+               return Version("Adds channel mode E (repeat) which helps protect against spammers which spam the same message repeatedly.", VF_COMMON|VF_VENDOR, rm.GetModuleSettings());
        }
 };