]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Merge m_noctcp_user into m_noctcp.
authorPeter Powell <petpow@saberuk.com>
Sat, 28 Jul 2018 08:23:14 +0000 (09:23 +0100)
committerPeter Powell <petpow@saberuk.com>
Tue, 18 Sep 2018 11:30:15 +0000 (12:30 +0100)
docs/conf/modules.conf.example
src/modules/m_noctcp.cpp

index 9ee8bf81939c782afe7bd0e4ea4eeecfcbf09550..7823e2d30f5ef138d849d51d2002ef195de3b90c 100644 (file)
 #<module name="nicklock">
 
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
-# 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.
 #<module name="noctcp">
+#
+# The +T user mode is not enabled by default to enable link compatibility
+# with 2.0 servers. You can enable it by uncommenting this:
+#<noctcp enableumode="yes">
 
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 # No kicks module: Adds the +Q channel mode and the Q: extban to deny
index 54960a88ea7511163e071b5d91d6852ec5bc43de..af14c73ec14fa8e4ebc623f27b7339822f29b2df 100644 (file)
 #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<Channel>();
                        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<User>();
+                       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;
        }