From 7ad534c1af4578a0d46742c4b6b00a5a33afb63f Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Mon, 24 Jun 2019 11:10:17 -0500 Subject: Replace large if/else blocks for target.type with switches (#1668). --- src/modules/m_silence.cpp | 52 ++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'src/modules/m_silence.cpp') diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp index 87b70dfa4..1e73bda27 100644 --- a/src/modules/m_silence.cpp +++ b/src/modules/m_silence.cpp @@ -384,32 +384,38 @@ class ModuleSilence bool is_ctcp = details.IsCTCP(ctcpname) && !irc::equals(ctcpname, "ACTION"); SilenceEntry::SilenceFlags flag = SilenceEntry::SF_NONE; - if (target.type == MessageTarget::TYPE_CHANNEL) - { - if (is_ctcp) - flag = SilenceEntry::SF_CTCP_CHANNEL; - else if (details.type == MSG_NOTICE) - flag = SilenceEntry::SF_NOTICE_CHANNEL; - else if (details.type == MSG_PRIVMSG) - flag = SilenceEntry::SF_PRIVMSG_CHANNEL; - - return BuildChannelExempts(user, target.Get(), flag, details.exemptions); - } - - if (target.type == MessageTarget::TYPE_USER) + switch (target.type) { - if (is_ctcp) - flag = SilenceEntry::SF_CTCP_USER; - else if (details.type == MSG_NOTICE) - flag = SilenceEntry::SF_NOTICE_USER; - else if (details.type == MSG_PRIVMSG) - flag = SilenceEntry::SF_PRIVMSG_USER; - - if (!CanReceiveMessage(user, target.Get(), flag)) + case MessageTarget::TYPE_CHANNEL: + { + if (is_ctcp) + flag = SilenceEntry::SF_CTCP_CHANNEL; + else if (details.type == MSG_NOTICE) + flag = SilenceEntry::SF_NOTICE_CHANNEL; + else if (details.type == MSG_PRIVMSG) + flag = SilenceEntry::SF_PRIVMSG_CHANNEL; + + return BuildChannelExempts(user, target.Get(), flag, details.exemptions); + break; + } + case MessageTarget::TYPE_USER: { - details.echo_original = true; - return MOD_RES_DENY; + if (is_ctcp) + flag = SilenceEntry::SF_CTCP_USER; + else if (details.type == MSG_NOTICE) + flag = SilenceEntry::SF_NOTICE_USER; + else if (details.type == MSG_PRIVMSG) + flag = SilenceEntry::SF_PRIVMSG_USER; + + if (!CanReceiveMessage(user, target.Get(), flag)) + { + details.echo_original = true; + return MOD_RES_DENY; + } + break; } + case MessageTarget::TYPE_SERVER: + break; } return MOD_RES_PASSTHRU; -- cgit v1.3.1-10-gc9f91