]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add the Numerics::CannotSendTo class and switch stuff to use it.
authorSadie Powell <sadie@witchery.services>
Sat, 4 Apr 2020 10:49:06 +0000 (11:49 +0100)
committerSadie Powell <sadie@witchery.services>
Sat, 4 Apr 2020 11:31:14 +0000 (12:31 +0100)
16 files changed:
include/numericbuilder.h
src/coremods/core_message.cpp
src/modules/m_anticaps.cpp
src/modules/m_blockcaps.cpp
src/modules/m_blockcolor.cpp
src/modules/m_censor.cpp
src/modules/m_chanfilter.cpp
src/modules/m_commonchans.cpp
src/modules/m_delaymsg.cpp
src/modules/m_filter.cpp
src/modules/m_ircv3_ctctags.cpp
src/modules/m_muteban.cpp
src/modules/m_noctcp.cpp
src/modules/m_nonotice.cpp
src/modules/m_restrictmsg.cpp
src/modules/m_sslmodes.cpp

index 73bcc2c97f67ec28a7d0c187c3e8ae55f19adc99..f9ca26f81920e5a46ce23d4b5de4c6334af716ce 100644 (file)
@@ -200,11 +200,55 @@ class Numeric::ParamBuilder : public GenericParamBuilder<NumStaticParams, SendEm
 
 namespace Numerics
 {
+       class CannotSendTo;
        class InvalidModeParameter;
        class NoSuchChannel;
        class NoSuchNick;
 }
 
+/** Builder for the ERR_CANNOTSENDTOCHAN and ERR_CANTSENDTOUSER numerics. */
+class Numerics::CannotSendTo : public Numeric::Numeric
+{
+ public:
+       CannotSendTo(Channel* chan, const std::string& message)
+               : Numeric(ERR_CANNOTSENDTOCHAN)
+       {
+               push(chan->name);
+               push(message);
+       }
+
+       CannotSendTo(Channel* chan, const std::string& what, ModeHandler* mh)
+               : Numeric(ERR_CANNOTSENDTOCHAN)
+       {
+               push(chan->name);
+               push(InspIRCd::Format("You cannot send %s to this channel whilst the +%c (%s) mode is set.",
+                       what.c_str(), mh->GetModeChar(), mh->name.c_str()));
+       }
+
+       CannotSendTo(Channel* chan, const std::string& what, char extban, const std::string& extbandesc)
+               : Numeric(ERR_CANNOTSENDTOCHAN)
+       {
+               push(chan->name);
+               push(InspIRCd::Format("You cannot send %s to this channel whilst %s %c: (%s) extban is set on you.",
+                       what.c_str(), strchr("AEIOUaeiou", extban) ? "an" : "a", extban, extbandesc.c_str()));
+       }
+
+       CannotSendTo(User* user, const std::string& message)
+               : Numeric(ERR_CANNOTSENDTOCHAN)
+       {
+               push(user->registered & REG_NICK ? user->nick : "*");
+               push(message);
+       }
+
+       CannotSendTo(User* user, const std::string& what, ModeHandler* mh, bool self = false)
+               : Numeric(ERR_CANNOTSENDTOCHAN)
+       {
+               push(user->registered & REG_NICK ? user->nick : "*");
+               push(InspIRCd::Format("You cannot send %s to this user whilst %s have the +%c (%s) mode set.",
+                       what.c_str(), self ? "you" : "they", mh->GetModeChar(), mh->name.c_str()));
+       }
+};
+
 /* Builder for the ERR_INVALIDMODEPARAM numeric. */
 class Numerics::InvalidModeParameter : public Numeric::Numeric
 {
index 1093aad678fa06c77b97117aaba3f7c7673a3a06..b4404995df2de07a48ac4c98850e7a73da544c71 100644 (file)
@@ -408,7 +408,7 @@ class ModuleCoreMessage : public Module
                if (chan->IsModeSet(noextmsgmode) && !chan->HasUser(user))
                {
                        // The noextmsg mode is set and the user is not in the channel.
-                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (no external messages)");
+                       user->WriteNumeric(Numerics::CannotSendTo(chan, "external messages", *noextmsgmode));
                        return MOD_RES_DENY;
                }
 
@@ -416,7 +416,7 @@ class ModuleCoreMessage : public Module
                if (no_chan_priv && chan->IsModeSet(moderatedmode))
                {
                        // The moderated mode is set and the user has no status rank.
-                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (+m is set)");
+                       user->WriteNumeric(Numerics::CannotSendTo(chan, "messages", *moderatedmode));
                        return MOD_RES_DENY;
                }
 
@@ -424,7 +424,7 @@ class ModuleCoreMessage : public Module
                {
                        // The user is banned in the channel and restrictbannedusers is enabled.
                        if (ServerInstance->Config->RestrictBannedUsers == ServerConfig::BUT_RESTRICT_NOTIFY)
-                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're banned)");
+                               user->WriteNumeric(Numerics::CannotSendTo(chan, "You cannot send messages to this channel whilst banned."));
                        return MOD_RES_DENY;
                }
 
index 0d224551fc86c145ffe3ff4ac74d5b85543dd443..83fa0ecaa984070751ed2442e7186cf02f2877eb 100644 (file)
@@ -175,7 +175,7 @@ class ModuleAntiCaps : public Module
 
        void InformUser(Channel* channel, User* user, const std::string& message)
        {
-               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, channel->name, message + " and was blocked.");
+               user->WriteNumeric(Numerics::CannotSendTo(channel, message + " and was blocked."));
        }
 
  public:
index 420163a74b5377e07972b9c08032fd662bf69df8..f66a6a76352ff7b51372c426d4becf7982ab0d9c 100644 (file)
@@ -97,7 +97,8 @@ public:
                                // any upper case letters.
                                if (length > 0 && round((upper * 100) / length) >= percent)
                                {
-                                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, c->name, InspIRCd::Format("Your message cannot contain %d%% or more capital letters if it's longer than %d characters", percent, minlen));
+                                       const std::string msg = InspIRCd::Format("Your message cannot contain %d%% or more capital letters if it's longer than %d characters", percent, minlen);
+                                       user->WriteNumeric(Numerics::CannotSendTo(c, msg));
                                        return MOD_RES_DENY;
                                }
                        }
index 52a9a4749868cb624e14ee634b2eed36f22a1bdb..6607073ce82e22750efa6040c598cfdb9fb342e9 100644 (file)
@@ -65,8 +65,10 @@ class ModuleBlockColor : public Module
                                        // Block all control codes except \001 for CTCP
                                        if ((*i >= 0) && (*i < 32) && (*i != 1))
                                        {
-                                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, c->name, InspIRCd::Format("Can't send colors to channel (%s)",
-                                                       modeset ? "+c is set" : "you're extbanned"));
+                                               if (modeset)
+                                                       user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", &bc));
+                                               else
+                                                       user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", 'c', "nocolor"));
                                                return MOD_RES_DENY;
                                        }
                                }
index d216bd11f87a87accdccc74b8b79a9be9db40158..7c7d12a6d02e94f9563b2610c680662b082bd6c7 100644 (file)
@@ -51,7 +51,6 @@ class ModuleCensor : public Module
                if (!IS_LOCAL(user))
                        return MOD_RES_PASSTHRU;
 
-               int numeric = 0;
                switch (target.type)
                {
                        case MessageTarget::TYPE_USER:
@@ -59,8 +58,6 @@ class ModuleCensor : public Module
                                User* targuser = target.Get<User>();
                                if (!targuser->IsModeSet(cu))
                                        return MOD_RES_PASSTHRU;
-
-                               numeric = ERR_CANTSENDTOUSER;
                                break;
                        }
 
@@ -73,8 +70,6 @@ class ModuleCensor : public Module
                                ModResult result = CheckExemption::Call(exemptionprov, user, targchan, "censor");
                                if (result == MOD_RES_ALLOW)
                                        return MOD_RES_PASSTHRU;
-
-                               numeric = ERR_CANNOTSENDTOCHAN;
                                break;
                        }
 
@@ -89,7 +84,11 @@ class ModuleCensor : public Module
                        {
                                if (index->second.empty())
                                {
-                                       user->WriteNumeric(numeric, target.GetName(), "Your message contained a censored word (" + index->first + "), and was blocked");
+                                       const std::string msg = InspIRCd::Format("Your message to this channel contained a banned phrase (%s) and was blocked.", index->first.c_str());
+                                       if (target.type == MessageTarget::TYPE_CHANNEL)
+                                               user->WriteNumeric(Numerics::CannotSendTo(target.Get<Channel>(), msg));
+                                       else
+                                               user->WriteNumeric(Numerics::CannotSendTo(target.Get<User>(), msg));
                                        return MOD_RES_DENY;
                                }
 
index 18e2791e6b8bd59add756ffacf04e385966ddc50..46e5c149487e07293d2fc156422b176823a3344a 100644 (file)
@@ -129,9 +129,10 @@ class ModuleChanFilter : public Module
                }
 
                if (hidemask)
-                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (your part message contained a censored word)");
+                       user->WriteNumeric(Numerics::CannotSendTo(chan, "Your part message contained a banned phrase and was blocked."));
                else
-                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (your part message contained a censored word: " + match->mask + ")");
+                       user->WriteNumeric(Numerics::CannotSendTo(chan, InspIRCd::Format("Your part message contained a banned phrase (%s) and was blocked.",
+                               match->mask.c_str())));
        }
 
        ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
@@ -150,9 +151,10 @@ class ModuleChanFilter : public Module
                        }
 
                        if (hidemask)
-                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (your message contained a censored word)");
+                               user->WriteNumeric(Numerics::CannotSendTo(chan, "Your message to this channel contained a banned phrase and was blocked."));
                        else
-                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (your message contained a censored word: " + match->mask + ")");
+                               user->WriteNumeric(Numerics::CannotSendTo(chan, InspIRCd::Format("Your message to this channel contained a banned phrase (%s) and was blocked.",
+                                       match->mask.c_str())));
 
                        return MOD_RES_DENY;
                }
index 60e319aea13252000675cf42e4fa4a15141f7c1f..1e9ca3fee3bf347c6ea0a6f4cf5ab15b102c909b 100644 (file)
@@ -43,7 +43,7 @@ class ModuleCommonChans
                if (user->HasPrivPermission("users/ignore-commonchans") || user->server->IsULine())
                        return MOD_RES_PASSTHRU;
 
-               user->WriteNumeric(ERR_CANTSENDTOUSER, targuser->nick, "You are not permitted to send private messages to this user (+c is set)");
+               user->WriteNumeric(Numerics::CannotSendTo(targuser, "messages", &mode));
                return MOD_RES_DENY;
        }
 
index 84b5c8353d6543610d30d912a4ac200ca5091f49..0952cbf96d254664901ef3ab534a91a94f940e2b 100644 (file)
@@ -141,7 +141,8 @@ ModResult ModuleDelayMsg::HandleMessage(User* user, const MessageTarget& target,
        {
                if (channel->GetPrefixValue(user) < VOICE_VALUE)
                {
-                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, channel->name, InspIRCd::Format("You must wait %d seconds after joining to send to the channel (+d is set)", len));
+                       const std::string message = InspIRCd::Format("You cannot send messages to this channel until you have been a member for %d seconds.", len);
+                       user->WriteNumeric(Numerics::CannotSendTo(channel, message));
                        return MOD_RES_DENY;
                }
        }
index 9088ac3facbba1aea45bc4f88330dbafef1e440b..e1cc5d451a45b27dfeaa39ee739edf360c20e093 100644 (file)
@@ -428,9 +428,9 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar
                        if (notifyuser)
                        {
                                if (msgtarget.type == MessageTarget::TYPE_CHANNEL)
-                                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, msgtarget.GetName(), InspIRCd::Format("Message to channel blocked and opers notified (%s)", f->reason.c_str()));
+                                       user->WriteNumeric(Numerics::CannotSendTo(msgtarget.Get<Channel>(), InspIRCd::Format("Your message to this channel was blocked: %s.", f->reason.c_str())));
                                else
-                                       user->WriteNotice("Your message to "+msgtarget.GetName()+" was blocked and opers notified: "+f->reason);
+                                       user->WriteNumeric(Numerics::CannotSendTo(msgtarget.Get<User>(), InspIRCd::Format("Your message to this user was blocked: %s.", f->reason.c_str())));
                        }
                        else
                                details.echo_original = true;
@@ -440,9 +440,9 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar
                        if (notifyuser)
                        {
                                if (msgtarget.type == MessageTarget::TYPE_CHANNEL)
-                                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, msgtarget.GetName(), InspIRCd::Format("Message to channel blocked (%s)", f->reason.c_str()));
+                                       user->WriteNumeric(Numerics::CannotSendTo(msgtarget.Get<Channel>(), InspIRCd::Format("Your message to this channel was blocked: %s.", f->reason.c_str())));
                                else
-                                       user->WriteNotice("Your message to "+msgtarget.GetName()+" was blocked: "+f->reason);
+                                       user->WriteNumeric(Numerics::CannotSendTo(msgtarget.Get<User>(), InspIRCd::Format("Your message to this user was blocked: %s.", f->reason.c_str())));
                        }
                        else
                                details.echo_original = true;
index 6123d3b31ebe320d8e2bf83d89887422a1517408..19917eb79b5d89e1e36a618b9dce397ee64ace89 100644 (file)
@@ -336,7 +336,7 @@ class ModuleIRCv3CTCTags
                        if (chan->IsModeSet(noextmsgmode) && !chan->HasUser(user))
                        {
                                // The noextmsg mode is set and the user is not in the channel.
-                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (no external messages)");
+                               user->WriteNumeric(Numerics::CannotSendTo(chan, "external messages", *noextmsgmode));
                                return MOD_RES_DENY;
                        }
 
@@ -344,7 +344,7 @@ class ModuleIRCv3CTCTags
                        if (no_chan_priv && chan->IsModeSet(moderatedmode))
                        {
                                // The moderated mode is set and the user has no status rank.
-                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (+m is set)");
+                               user->WriteNumeric(Numerics::CannotSendTo(chan, "messages", *noextmsgmode));
                                return MOD_RES_DENY;
                        }
 
@@ -352,7 +352,7 @@ class ModuleIRCv3CTCTags
                        {
                                // The user is banned in the channel and restrictbannedusers is enabled.
                                if (ServerInstance->Config->RestrictBannedUsers == ServerConfig::BUT_RESTRICT_NOTIFY)
-                                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're banned)");
+                                       user->WriteNumeric(Numerics::CannotSendTo(chan, "You cannot send messages to this channel whilst banned."));
                                return MOD_RES_DENY;
                        }
                }
index fdfd2c701573970fdeb92025124c7785186e419d..8006f81521503b903e6b146adca44e528c55e276 100644 (file)
@@ -64,7 +64,7 @@ class ModuleQuietBan
                                return MOD_RES_DENY;
                        }
 
-                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're muted)");
+                       user->WriteNumeric(Numerics::CannotSendTo(chan, "messages", 'm', "mute"));
                        return MOD_RES_DENY;
                }
 
index f6877f6790ff0c82d7e2944e030891e8897d279a..4f65457000ee1784e6b1cefc6413e1975cab187d 100644 (file)
@@ -88,11 +88,15 @@ class ModuleNoCTCP : public Module
                                if (res == MOD_RES_ALLOW)
                                        return MOD_RES_PASSTHRU;
 
-                               bool modeset = c->IsModeSet(nc);
-                               if (!c->GetExtBanStatus(user, 'C').check(!modeset))
+                               if (c->IsModeSet(nc))
                                {
-                                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, c->name, InspIRCd::Format("Can't send CTCP to channel (%s)",
-                                               modeset ? "+C is set" : "you're extbanned"));
+                                       user->WriteNumeric(Numerics::CannotSendTo(c, "CTCPs", &nc));
+                                       return MOD_RES_DENY;
+                               }
+
+                               if (c->GetExtBanStatus(user, 'C') == MOD_RES_DENY)
+                               {
+                                       user->WriteNumeric(Numerics::CannotSendTo(c, "CTCPs", 'C', "noctcp"));
                                        return MOD_RES_DENY;
                                }
                                break;
@@ -105,7 +109,7 @@ class ModuleNoCTCP : public Module
                                User* u = target.Get<User>();
                                if (u->IsModeSet(ncu))
                                {
-                                       user->WriteNumeric(ERR_CANTSENDTOUSER, u->nick, "Can't send CTCP to user (+T is set)");
+                                       user->WriteNumeric(Numerics::CannotSendTo(u, "CTCPs", &ncu));
                                        return MOD_RES_DENY;
                                }
                                break;
index bff5bba2d4b82ced135a6fb7f2c6b7d3fee8e139..4ee5f8bff2b177c3996d3beb3258978f391ffcc7 100644 (file)
@@ -55,11 +55,15 @@ class ModuleNoNotice : public Module
                        if (res == MOD_RES_ALLOW)
                                return MOD_RES_PASSTHRU;
 
-                       bool modeset = c->IsModeSet(nt);
-                       if (!c->GetExtBanStatus(user, 'T').check(!modeset))
+                       if (c->IsModeSet(nt))
                        {
-                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, c->name, InspIRCd::Format("Can't send NOTICE to channel (%s)",
-                                       modeset ? "+T is set" : "you're extbanned"));
+                               user->WriteNumeric(Numerics::CannotSendTo(c, "notices", &nt));
+                               return MOD_RES_DENY;
+                       }
+
+                       if (c->GetExtBanStatus(user, 'T') == MOD_RES_DENY)
+                       {
+                               user->WriteNumeric(Numerics::CannotSendTo(c, "notices", 'T', "nonotice"));
                                return MOD_RES_DENY;
                        }
                }
index b6c82ee769609c3c2d95886a0c074e4f15c164de..1bb90a3607a20cfec0f33e0ea51efb0c5570f9cb 100644 (file)
@@ -43,10 +43,9 @@ class ModuleRestrictMsg
                        // (3) the recipient is on a ulined server
                        // anything else, blocked.
                        if (u->IsOper() || user->IsOper() || u->server->IsULine())
-                       {
                                return MOD_RES_PASSTHRU;
-                       }
-                       user->WriteNumeric(ERR_CANTSENDTOUSER, u->nick, "You are not permitted to send private messages to this user");
+
+                       user->WriteNumeric(Numerics::CannotSendTo(u, "You cannot send messages to this user."));
                        return MOD_RES_DENY;
                }
 
index e2a5bc930be5fc4b4db8885786ca02e0d62fea6b..6ad817c8ea5f178aa5dc84dbb212c0553297c679 100644 (file)
@@ -198,7 +198,7 @@ class ModuleSSLModes
                        if (!api || !api->GetCertificate(user))
                        {
                                /* The sending user is not on an SSL connection */
-                               user->WriteNumeric(ERR_CANTSENDTOUSER, target->nick, "You are not permitted to send private messages to this user (+z is set)");
+                               user->WriteNumeric(Numerics::CannotSendTo(target, "messages", &sslquery));
                                return MOD_RES_DENY;
                        }
                }
@@ -207,7 +207,7 @@ class ModuleSSLModes
                {
                        if (!api || !api->GetCertificate(target))
                        {
-                               user->WriteNumeric(ERR_CANTSENDTOUSER, target->nick, "You must remove user mode 'z' before you are able to send private messages to a non-SSL user.");
+                               user->WriteNumeric(Numerics::CannotSendTo(target, "messages", &sslquery, true));
                                return MOD_RES_DENY;
                        }
                }