summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2020-04-04 11:49:06 +0100
committerSadie Powell <sadie@witchery.services>2020-04-04 12:31:14 +0100
commitcbe5b993142c218e09ae972bdce91681cc0ba485 (patch)
tree61e925088e25c4ba7e1e011929fb13555400c42a
parentcad2f3f979b2fc45bcfa7c7b7652bbe201a5b0a0 (diff)
Add the Numerics::CannotSendTo class and switch stuff to use it.
-rw-r--r--include/numericbuilder.h44
-rw-r--r--src/coremods/core_message.cpp6
-rw-r--r--src/modules/m_anticaps.cpp2
-rw-r--r--src/modules/m_blockcaps.cpp3
-rw-r--r--src/modules/m_blockcolor.cpp6
-rw-r--r--src/modules/m_censor.cpp11
-rw-r--r--src/modules/m_chanfilter.cpp10
-rw-r--r--src/modules/m_commonchans.cpp2
-rw-r--r--src/modules/m_delaymsg.cpp3
-rw-r--r--src/modules/m_filter.cpp8
-rw-r--r--src/modules/m_ircv3_ctctags.cpp6
-rw-r--r--src/modules/m_muteban.cpp2
-rw-r--r--src/modules/m_noctcp.cpp14
-rw-r--r--src/modules/m_nonotice.cpp12
-rw-r--r--src/modules/m_restrictmsg.cpp5
-rw-r--r--src/modules/m_sslmodes.cpp4
16 files changed, 97 insertions, 41 deletions
diff --git a/include/numericbuilder.h b/include/numericbuilder.h
index 73bcc2c97..f9ca26f81 100644
--- a/include/numericbuilder.h
+++ b/include/numericbuilder.h
@@ -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
{
diff --git a/src/coremods/core_message.cpp b/src/coremods/core_message.cpp
index 1093aad67..b4404995d 100644
--- a/src/coremods/core_message.cpp
+++ b/src/coremods/core_message.cpp
@@ -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;
}
diff --git a/src/modules/m_anticaps.cpp b/src/modules/m_anticaps.cpp
index 0d224551f..83fa0ecaa 100644
--- a/src/modules/m_anticaps.cpp
+++ b/src/modules/m_anticaps.cpp
@@ -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:
diff --git a/src/modules/m_blockcaps.cpp b/src/modules/m_blockcaps.cpp
index 420163a74..f66a6a763 100644
--- a/src/modules/m_blockcaps.cpp
+++ b/src/modules/m_blockcaps.cpp
@@ -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;
}
}
diff --git a/src/modules/m_blockcolor.cpp b/src/modules/m_blockcolor.cpp
index 52a9a4749..6607073ce 100644
--- a/src/modules/m_blockcolor.cpp
+++ b/src/modules/m_blockcolor.cpp
@@ -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;
}
}
diff --git a/src/modules/m_censor.cpp b/src/modules/m_censor.cpp
index d216bd11f..7c7d12a6d 100644
--- a/src/modules/m_censor.cpp
+++ b/src/modules/m_censor.cpp
@@ -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;
}
diff --git a/src/modules/m_chanfilter.cpp b/src/modules/m_chanfilter.cpp
index 18e2791e6..46e5c1494 100644
--- a/src/modules/m_chanfilter.cpp
+++ b/src/modules/m_chanfilter.cpp
@@ -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;
}
diff --git a/src/modules/m_commonchans.cpp b/src/modules/m_commonchans.cpp
index 60e319aea..1e9ca3fee 100644
--- a/src/modules/m_commonchans.cpp
+++ b/src/modules/m_commonchans.cpp
@@ -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;
}
diff --git a/src/modules/m_delaymsg.cpp b/src/modules/m_delaymsg.cpp
index 84b5c8353..0952cbf96 100644
--- a/src/modules/m_delaymsg.cpp
+++ b/src/modules/m_delaymsg.cpp
@@ -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;
}
}
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp
index 9088ac3fa..e1cc5d451 100644
--- a/src/modules/m_filter.cpp
+++ b/src/modules/m_filter.cpp
@@ -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;
diff --git a/src/modules/m_ircv3_ctctags.cpp b/src/modules/m_ircv3_ctctags.cpp
index 6123d3b31..19917eb79 100644
--- a/src/modules/m_ircv3_ctctags.cpp
+++ b/src/modules/m_ircv3_ctctags.cpp
@@ -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;
}
}
diff --git a/src/modules/m_muteban.cpp b/src/modules/m_muteban.cpp
index fdfd2c701..8006f8152 100644
--- a/src/modules/m_muteban.cpp
+++ b/src/modules/m_muteban.cpp
@@ -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;
}
diff --git a/src/modules/m_noctcp.cpp b/src/modules/m_noctcp.cpp
index f6877f679..4f6545700 100644
--- a/src/modules/m_noctcp.cpp
+++ b/src/modules/m_noctcp.cpp
@@ -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;
diff --git a/src/modules/m_nonotice.cpp b/src/modules/m_nonotice.cpp
index bff5bba2d..4ee5f8bff 100644
--- a/src/modules/m_nonotice.cpp
+++ b/src/modules/m_nonotice.cpp
@@ -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;
}
}
diff --git a/src/modules/m_restrictmsg.cpp b/src/modules/m_restrictmsg.cpp
index b6c82ee76..1bb90a360 100644
--- a/src/modules/m_restrictmsg.cpp
+++ b/src/modules/m_restrictmsg.cpp
@@ -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;
}
diff --git a/src/modules/m_sslmodes.cpp b/src/modules/m_sslmodes.cpp
index e2a5bc930..6ad817c8e 100644
--- a/src/modules/m_sslmodes.cpp
+++ b/src/modules/m_sslmodes.cpp
@@ -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;
}
}