1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Adds user mode +c, which if set, users must be on a common channel with you to private message you */
18 /** Handles user mode +c
20 class PrivacyMode : public ModeHandler
23 PrivacyMode(Module* Creator) : ModeHandler(Creator, "deaf_commonchan", 'c', PARAM_NONE, MODETYPE_USER) { }
25 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
29 if (!dest->IsModeSet('c'))
31 dest->SetMode('c',true);
32 return MODEACTION_ALLOW;
37 if (dest->IsModeSet('c'))
39 dest->SetMode('c',false);
40 return MODEACTION_ALLOW;
44 return MODEACTION_DENY;
48 class ModulePrivacyMode : public Module
52 ModulePrivacyMode() : pm(this)
54 if (!ServerInstance->Modes->AddMode(&pm))
55 throw ModuleException("Could not add new modes!");
56 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
57 ServerInstance->Modules->Attach(eventlist, this, 2);
61 virtual ~ModulePrivacyMode()
65 virtual Version GetVersion()
67 return Version("Adds user mode +c, which if set, users must be on a common channel with you to private message you", VF_VENDOR);
70 virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
72 if (target_type == TYPE_USER)
74 User* t = (User*)dest;
75 if (!IS_OPER(user) && (t->IsModeSet('c')) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t))
77 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());
81 return MOD_RES_PASSTHRU;
84 virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
86 return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
91 MODULE_INIT(ModulePrivacyMode)