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_noctcp.cpp | 49 +++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) (limited to 'src/modules/m_noctcp.cpp') diff --git a/src/modules/m_noctcp.cpp b/src/modules/m_noctcp.cpp index c73f8308e..f288820b8 100644 --- a/src/modules/m_noctcp.cpp +++ b/src/modules/m_noctcp.cpp @@ -61,33 +61,40 @@ class ModuleNoCTCP : public Module if (!details.IsCTCP(ctcpname) || irc::equals(ctcpname, "ACTION")) return MOD_RES_PASSTHRU; - if (target.type == MessageTarget::TYPE_CHANNEL) + switch (target.type) { - if (user->HasPrivPermission("channels/ignore-noctcp")) - return MOD_RES_PASSTHRU; + case MessageTarget::TYPE_CHANNEL: + { + if (user->HasPrivPermission("channels/ignore-noctcp")) + return MOD_RES_PASSTHRU; - Channel* c = target.Get(); - ModResult res = CheckExemption::Call(exemptionprov, user, c, "noctcp"); - if (res == MOD_RES_ALLOW) - return MOD_RES_PASSTHRU; + Channel* c = target.Get(); + ModResult res = CheckExemption::Call(exemptionprov, user, c, "noctcp"); + if (res == MOD_RES_ALLOW) + return MOD_RES_PASSTHRU; - if (!c->GetExtBanStatus(user, 'C').check(!c->IsModeSet(nc))) - { - user->WriteNumeric(ERR_CANNOTSENDTOCHAN, c->name, "Can't send CTCP to channel (+C is set)"); - return MOD_RES_DENY; + if (!c->GetExtBanStatus(user, 'C').check(!c->IsModeSet(nc))) + { + user->WriteNumeric(ERR_CANNOTSENDTOCHAN, c->name, "Can't send CTCP to channel (+C is set)"); + return MOD_RES_DENY; + } + break; } - } - else if (target.type == MessageTarget::TYPE_USER) - { - if (user->HasPrivPermission("users/ignore-noctcp")) - return MOD_RES_PASSTHRU; - - User* u = target.Get(); - if (u->IsModeSet(ncu)) + case MessageTarget::TYPE_USER: { - user->WriteNumeric(ERR_CANTSENDTOUSER, u->nick, "Can't send CTCP to user (+T is set)"); - return MOD_RES_DENY; + if (user->HasPrivPermission("users/ignore-noctcp")) + return MOD_RES_PASSTHRU; + + User* u = target.Get(); + if (u->IsModeSet(ncu)) + { + user->WriteNumeric(ERR_CANTSENDTOUSER, u->nick, "Can't send CTCP to user (+T is set)"); + return MOD_RES_DENY; + } + break; } + case MessageTarget::TYPE_SERVER: + break; } return MOD_RES_PASSTHRU; } -- cgit v1.2.3