1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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(InspIRCd* Instance, Module* Creator) : ModeHandler(Instance, Creator, 'c', 0, 0, false, MODETYPE_USER, false) { }
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(InspIRCd* Me) : Module(Me), pm(Me, 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()
63 ServerInstance->Modes->DelMode(&pm);
66 virtual Version GetVersion()
68 return Version("$Id$", VF_COMMON|VF_VENDOR, API_VERSION);
71 virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
73 if (target_type == TYPE_USER)
75 User* t = (User*)dest;
76 if (!IS_OPER(user) && (t->IsModeSet('c')) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t))
78 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());
82 return MOD_RES_PASSTHRU;
85 virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
87 return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
92 MODULE_INIT(ModulePrivacyMode)