From 0378d0f5826cfcd506595e60a44bf4af89d78bf8 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sat, 28 Jul 2018 09:23:14 +0100 Subject: [PATCH] Merge m_noctcp_user into m_noctcp. --- docs/conf/modules.conf.example | 8 ++++++-- src/modules/m_noctcp.cpp | 37 ++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/docs/conf/modules.conf.example b/docs/conf/modules.conf.example index 9ee8bf819..7823e2d30 100644 --- a/docs/conf/modules.conf.example +++ b/docs/conf/modules.conf.example @@ -1340,9 +1340,13 @@ # #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# -# No CTCP module: Adds the channel mode +C to block CTCPs and extban -# 'C' to block CTCPs sent by specific users. +# No CTCP module: Adds the channel mode +C and user mode +T to block +# CTCPs and extban 'C' to block CTCPs sent by specific users. # +# +# The +T user mode is not enabled by default to enable link compatibility +# with 2.0 servers. You can enable it by uncommenting this: +# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # No kicks module: Adds the +Q channel mode and the Q: extban to deny diff --git a/src/modules/m_noctcp.cpp b/src/modules/m_noctcp.cpp index 54960a88e..af14c73ec 100644 --- a/src/modules/m_noctcp.cpp +++ b/src/modules/m_noctcp.cpp @@ -22,31 +22,47 @@ #include "inspircd.h" #include "modules/exemption.h" +class NoCTCPUser : public SimpleUserModeHandler +{ +public: + NoCTCPUser(Module* Creator) + : SimpleUserModeHandler(Creator, "u_noctcp", 'T') + { + if (!ServerInstance->Config->ConfValue("noctcp")->getBool("enableumode")) + DisableAutoRegister(); + } +}; + class ModuleNoCTCP : public Module { CheckExemption::EventProvider exemptionprov; SimpleChannelModeHandler nc; + NoCTCPUser ncu; public: ModuleNoCTCP() : exemptionprov(this) , nc(this, "noctcp", 'C') + , ncu(this) { } Version GetVersion() CXX11_OVERRIDE { - return Version("Provides channel mode +C to block CTCPs", VF_VENDOR); + return Version("Provides user mode +T and channel mode +C to block CTCPs", VF_VENDOR); } ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if ((target.type == MessageTarget::TYPE_CHANNEL) && (IS_LOCAL(user))) - { - std::string ctcpname; - if (!details.IsCTCP(ctcpname) || irc::equals(ctcpname, "ACTION")) - return MOD_RES_PASSTHRU; + if (!IS_LOCAL(user)) + return MOD_RES_PASSTHRU; + std::string ctcpname; + if (!details.IsCTCP(ctcpname) || irc::equals(ctcpname, "ACTION")) + return MOD_RES_PASSTHRU; + + if (target.type == MessageTarget::TYPE_CHANNEL) + { Channel* c = target.Get(); ModResult res = CheckExemption::Call(exemptionprov, user, c, "noctcp"); if (res == MOD_RES_ALLOW) @@ -58,6 +74,15 @@ class ModuleNoCTCP : public Module return MOD_RES_DENY; } } + else if (target.type == MessageTarget::TYPE_USER) + { + User* u = target.Get(); + if (u->IsModeSet(ncu)) + { + user->WriteNumeric(ERR_CANTSENDTOUSER, u->nick, "Can't send CTCP to user (+T set)"); + return MOD_RES_PASSTHRU; + } + } return MOD_RES_PASSTHRU; } -- 2.39.2