]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_anticaps.cpp
Add support for blocking tag messages with the deaf mode.
[user/henk/code/inspircd.git] / src / modules / m_anticaps.cpp
index b6167893c1536397a99e6549978cf9770b8e4d70..2c39dce98022c57d3d00a3f413d9c943e9a338cf 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2017 Peter Powell <petpow@saberuk.com>
+ *   Copyright (C) 2019 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2018-2020 Sadie Powell <sadie@witchery.services>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
@@ -101,9 +102,10 @@ 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)
+       ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE
        {
                irc::sepstream stream(parameter, ':');
                AntiCapsMethod method;
@@ -113,7 +115,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;
                }
 
@@ -148,7 +150,7 @@ class AntiCapsMode : public ParamMode<AntiCapsMode, SimpleExtItem<AntiCapsSettin
                out.push_back(':');
                out.append(ConvToStr(acs->minlen));
                out.push_back(':');
-               out.append(ConvToStr(acs->percent));
+               out.append(ConvNumeric(acs->percent));
        }
 };
 
@@ -173,7 +175,7 @@ class ModuleAntiCaps : public Module
 
        void InformUser(Channel* channel, User* user, const std::string& message)
        {
-               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, channel, message + " and was blocked.");
+               user->WriteNumeric(Numerics::CannotSendTo(channel, message + " and was blocked."));
        }
 
  public:
@@ -188,7 +190,7 @@ class ModuleAntiCaps : public Module
                ConfigTag* tag = ServerInstance->Config->ConfValue("anticaps");
 
                uppercase.reset();
-               const std::string upper = tag->getString("uppercase", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+               const std::string upper = tag->getString("uppercase", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1);
                for (std::string::const_iterator iter = upper.begin(); iter != upper.end(); ++iter)
                        uppercase.set(static_cast<unsigned char>(*iter));
 
@@ -216,23 +218,18 @@ class ModuleAntiCaps : public Module
                // If the user is exempt from anticaps then we don't need
                // to do anything else.
                ModResult result = CheckExemption::Call(exemptionprov, user, channel, "anticaps");
-                       if (result == MOD_RES_ALLOW)
+               if (result == MOD_RES_ALLOW)
                        return MOD_RES_PASSTHRU;
 
                // If the message is a CTCP then we skip it unless it is
-               // an ACTION in which case we skip the prefix and suffix.
-               std::string::const_iterator text_begin = details.text.begin();
-               std::string::const_iterator text_end = details.text.end();
-               if (details.text[0] == '\1')
+               // an ACTION in which case we just check against the body.
+               std::string ctcpname;
+               std::string msgbody(details.text);
+               if (details.IsCTCP(ctcpname, msgbody))
                {
                        // If the CTCP is not an action then skip it.
-                       if (details.text.compare(0, 8, "\1ACTION ", 8))
+                       if (!irc::equals(ctcpname, "ACTION"))
                                return MOD_RES_PASSTHRU;
-
-                       // Skip the CTCP message characters.
-                       text_begin += 8;
-                       if (*details.text.rbegin() == '\1')
-                               text_end -= 1;
                }
 
                // Retrieve the anticaps config. This should never be
@@ -243,14 +240,14 @@ class ModuleAntiCaps : public Module
 
                // If the message is shorter than the minimum length then
                // we don't need to do anything else.
-               size_t length = std::distance(text_begin, text_end);
+               size_t length = msgbody.length();
                if (length < config->minlen)
                        return MOD_RES_PASSTHRU;
 
                // Count the characters to see how many upper case and
                // ignored (non upper or lower) characters there are.
                size_t upper = 0;
-               for (std::string::const_iterator iter = text_begin; iter != text_end; ++iter)
+               for (std::string::const_iterator iter = msgbody.begin(); iter != msgbody.end(); ++iter)
                {
                        unsigned char chr = static_cast<unsigned char>(*iter);
                        if (uppercase.test(chr))
@@ -302,7 +299,7 @@ class ModuleAntiCaps : public Module
 
        Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("Provides support for punishing users that send capitalised messages.", VF_COMMON|VF_VENDOR);
+               return Version("Adds channel mode B (anticaps) which allows channels to block messages which are excessively capitalised.", VF_COMMON|VF_VENDOR);
        }
 };