summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2019-05-11 14:55:20 +0100
committerPeter Powell <petpow@saberuk.com>2019-05-11 14:55:20 +0100
commit90541be8d666483cc802db35ed321b50d7c5f1dc (patch)
tree6fd8629d365af3ac9e2398a380b7a8117ca3876c
parent31340d50a4053c681614583ecdd5e8c6ba373d69 (diff)
Move message access checks to OnUserPre{Tag,}Message.
This allows modules to override them if necessary. Fixes #1619.
-rw-r--r--src/coremods/core_message.cpp66
-rw-r--r--src/modules/m_ircv3_ctctags.cpp61
2 files changed, 67 insertions, 60 deletions
diff --git a/src/coremods/core_message.cpp b/src/coremods/core_message.cpp
index a17157bad..8a2779a4f 100644
--- a/src/coremods/core_message.cpp
+++ b/src/coremods/core_message.cpp
@@ -138,8 +138,6 @@ class CommandMessage : public Command
{
private:
const MessageType msgtype;
- ChanModeReference moderatedmode;
- ChanModeReference noextmsgmode;
CmdResult HandleChannelTarget(User* source, const Params& parameters, const char* target, PrefixMode* pm)
{
@@ -151,32 +149,6 @@ class CommandMessage : public Command
return CMD_FAILURE;
}
- if (IS_LOCAL(source))
- {
- if (chan->IsModeSet(noextmsgmode) && !chan->HasUser(source))
- {
- // The noextmsg mode is set and the source is not in the channel.
- source->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (no external messages)");
- return CMD_FAILURE;
- }
-
- bool no_chan_priv = chan->GetPrefixValue(source) < VOICE_VALUE;
- if (no_chan_priv && chan->IsModeSet(moderatedmode))
- {
- // The moderated mode is set and the source has no status rank.
- source->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (+m is set)");
- return CMD_FAILURE;
- }
-
- if (no_chan_priv && ServerInstance->Config->RestrictBannedUsers != ServerConfig::BUT_NORMAL && chan->IsBanned(source))
- {
- // The source is banned in the channel and restrictbannedusers is enabled.
- if (ServerInstance->Config->RestrictBannedUsers == ServerConfig::BUT_RESTRICT_NOTIFY)
- source->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're banned)");
- return CMD_FAILURE;
- }
- }
-
// Fire the pre-message events.
MessageTarget msgtarget(chan, pm ? pm->GetPrefix() : 0);
MessageDetailsImpl msgdetails(msgtype, parameters[1], parameters.GetTags());
@@ -300,8 +272,6 @@ class CommandMessage : public Command
CommandMessage(Module* parent, MessageType mt)
: Command(parent, ClientProtocol::Messages::Privmsg::CommandStrFromMsgType(mt), 2, 2)
, msgtype(mt)
- , moderatedmode(parent, "moderated")
- , noextmsgmode(parent, "noextmsg")
{
syntax = "<target>[,<target>]+ :<message>";
}
@@ -413,13 +383,49 @@ class ModuleCoreMessage : public Module
CommandMessage cmdprivmsg;
CommandMessage cmdnotice;
CommandSQuery cmdsquery;
+ ChanModeReference moderatedmode;
+ ChanModeReference noextmsgmode;
public:
ModuleCoreMessage()
: cmdprivmsg(this, MSG_PRIVMSG)
, cmdnotice(this, MSG_NOTICE)
, cmdsquery(this)
+ , moderatedmode(this, "moderated")
+ , noextmsgmode(this, "noextmsg")
+ {
+ }
+
+ ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
{
+ if (!IS_LOCAL(user) || target.type != MessageTarget::TYPE_CHANNEL)
+ return MOD_RES_PASSTHRU;
+
+ Channel* chan = target.Get<Channel>();
+ 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)");
+ return MOD_RES_DENY;
+ }
+
+ bool no_chan_priv = chan->GetPrefixValue(user) < VOICE_VALUE;
+ 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)");
+ return MOD_RES_DENY;
+ }
+
+ if (no_chan_priv && ServerInstance->Config->RestrictBannedUsers != ServerConfig::BUT_NORMAL && chan->IsBanned(user))
+ {
+ // 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)");
+ return MOD_RES_DENY;
+ }
+
+ return MOD_RES_PASSTHRU;
}
Version GetVersion() CXX11_OVERRIDE
diff --git a/src/modules/m_ircv3_ctctags.cpp b/src/modules/m_ircv3_ctctags.cpp
index 70ffb54a8..e46646703 100644
--- a/src/modules/m_ircv3_ctctags.cpp
+++ b/src/modules/m_ircv3_ctctags.cpp
@@ -26,8 +26,6 @@ class CommandTagMsg : public Command
{
private:
Cap::Capability& cap;
- ChanModeReference moderatedmode;
- ChanModeReference noextmsgmode;
Events::ModuleEventProvider tagevprov;
ClientProtocol::EventProvider msgevprov;
@@ -70,32 +68,6 @@ class CommandTagMsg : public Command
return CMD_FAILURE;
}
- if (IS_LOCAL(source))
- {
- if (chan->IsModeSet(noextmsgmode) && !chan->HasUser(source))
- {
- // The noextmsg mode is set and the source is not in the channel.
- source->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (no external messages)");
- return CMD_FAILURE;
- }
-
- bool no_chan_priv = chan->GetPrefixValue(source) < VOICE_VALUE;
- if (no_chan_priv && chan->IsModeSet(moderatedmode))
- {
- // The moderated mode is set and the source has no status rank.
- source->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (+m is set)");
- return CMD_FAILURE;
- }
-
- if (no_chan_priv && ServerInstance->Config->RestrictBannedUsers != ServerConfig::BUT_NORMAL && chan->IsBanned(source))
- {
- // The source is banned in the channel and restrictbannedusers is enabled.
- if (ServerInstance->Config->RestrictBannedUsers == ServerConfig::BUT_RESTRICT_NOTIFY)
- source->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're banned)");
- return CMD_FAILURE;
- }
- }
-
// Fire the pre-message events.
MessageTarget msgtarget(chan, pm ? pm->GetPrefix() : 0);
CTCTags::TagMessageDetails msgdetails(parameters.GetTags());
@@ -223,8 +195,6 @@ class CommandTagMsg : public Command
CommandTagMsg(Module* Creator, Cap::Capability& Cap)
: Command(Creator, "TAGMSG", 1)
, cap(Cap)
- , moderatedmode(Creator, "moderated")
- , noextmsgmode(Creator, "noextmsg")
, tagevprov(Creator, "event/tagmsg")
, msgevprov(Creator, "TAGMSG")
{
@@ -307,6 +277,8 @@ class ModuleIRCv3CTCTags
Cap::Capability cap;
CommandTagMsg cmd;
C2CTags c2ctags;
+ ChanModeReference moderatedmode;
+ ChanModeReference noextmsgmode;
ModResult CopyClientTags(const ClientProtocol::TagMap& tags_in, ClientProtocol::TagMap& tags_out)
{
@@ -325,6 +297,8 @@ class ModuleIRCv3CTCTags
, cap(this, "message-tags")
, cmd(this, cap)
, c2ctags(this, cap)
+ , moderatedmode(this, "moderated")
+ , noextmsgmode(this, "noextmsg")
{
}
@@ -335,6 +309,33 @@ class ModuleIRCv3CTCTags
ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE
{
+ if (IS_LOCAL(user) && target.type == MessageTarget::TYPE_CHANNEL)
+ {
+ Channel* chan = target.Get<Channel>();
+ 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)");
+ return MOD_RES_DENY;
+ }
+
+ bool no_chan_priv = chan->GetPrefixValue(user) < VOICE_VALUE;
+ 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)");
+ return MOD_RES_DENY;
+ }
+
+ if (no_chan_priv && ServerInstance->Config->RestrictBannedUsers != ServerConfig::BUT_NORMAL && chan->IsBanned(user))
+ {
+ // 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)");
+ return MOD_RES_DENY;
+ }
+ }
+
return CopyClientTags(details.tags_in, details.tags_out);
}