summaryrefslogtreecommitdiff
path: root/src/modules/m_commonchans.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/m_commonchans.cpp')
-rw-r--r--src/modules/m_commonchans.cpp67
1 files changed, 30 insertions, 37 deletions
diff --git a/src/modules/m_commonchans.cpp b/src/modules/m_commonchans.cpp
index afa17add4..f3c206a44 100644
--- a/src/modules/m_commonchans.cpp
+++ b/src/modules/m_commonchans.cpp
@@ -1,6 +1,7 @@
/*
* InspIRCd -- Internet Relay Chat Daemon
*
+ * Copyright (C) 2019 Peter Powell <petpow@saberuk.com>
* Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
*
* This file is part of InspIRCd. InspIRCd is free software: you can
@@ -18,60 +19,52 @@
#include "inspircd.h"
+#include "modules/ctctags.h"
-/* $ModDesc: Adds user mode +c, which if set, users must be on a common channel with you to private message you */
-
-/** Handles user mode +c
- */
-class PrivacyMode : public SimpleUserModeHandler
+class ModuleCommonChans
+ : public CTCTags::EventListener
+ , public Module
{
- public:
- PrivacyMode(Module* Creator) : SimpleUserModeHandler(Creator, "deaf_commonchan", 'c') { }
-};
+ private:
+ SimpleUserModeHandler mode;
-class ModulePrivacyMode : public Module
-{
- PrivacyMode pm;
- public:
- ModulePrivacyMode() : pm(this)
+ ModResult HandleMessage(User* user, const MessageTarget& target)
{
- }
+ if (target.type != MessageTarget::TYPE_USER)
+ return MOD_RES_PASSTHRU;
- void init()
- {
- ServerInstance->Modules->AddService(pm);
- Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
- ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
+ User* targuser = target.Get<User>();
+ if (!targuser->IsModeSet(mode) || !user->SharesChannelWith(targuser))
+ return MOD_RES_PASSTHRU;
+
+ if (user->HasPrivPermission("users/ignore-commonchans") || user->server->IsULine())
+ return MOD_RES_PASSTHRU;
+
+ user->WriteNumeric(ERR_CANTSENDTOUSER, targuser->nick, "You are not permitted to send private messages to this user (+c is set)");
+ return MOD_RES_DENY;
}
- virtual ~ModulePrivacyMode()
+ public:
+ ModuleCommonChans()
+ : CTCTags::EventListener(this)
+ , mode(this, "deaf_commonchan", 'c')
{
}
- virtual Version GetVersion()
+ Version GetVersion() CXX11_OVERRIDE
{
- return Version("Adds user mode +c, which if set, users must be on a common channel with you to private message you", VF_VENDOR);
+ return Version("Provides user mode +c, requires users to share a common channel with you to private message you", VF_VENDOR);
}
- virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+ ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
{
- if (target_type == TYPE_USER)
- {
- User* t = (User*)dest;
- if (!IS_OPER(user) && (t->IsModeSet('c')) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t))
- {
- user->WriteNumeric(ERR_CANTSENDTOUSER, "%s %s :You are not permitted to send private messages to this user (+c set)", user->nick.c_str(), t->nick.c_str());
- return MOD_RES_DENY;
- }
- }
- return MOD_RES_PASSTHRU;
+ return HandleMessage(user, target);
}
- virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+ ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE
{
- return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
+ return HandleMessage(user, target);
}
};
-
-MODULE_INIT(ModulePrivacyMode)
+MODULE_INIT(ModuleCommonChans)