2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 /* $ModDesc: Adds user mode +c, which if set, users must be on a common channel with you to private message you */
24 /** Handles user mode +c
26 class PrivacyMode : public SimpleUserModeHandler
29 PrivacyMode(Module* Creator) : SimpleUserModeHandler(Creator, "deaf_commonchan", 'c') { }
32 class ModulePrivacyMode : public Module
36 ModulePrivacyMode() : pm(this)
38 if (!ServerInstance->Modes->AddMode(&pm))
39 throw ModuleException("Could not add new modes!");
40 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
41 ServerInstance->Modules->Attach(eventlist, this, 2);
45 virtual ~ModulePrivacyMode()
49 virtual Version GetVersion()
51 return Version("Adds user mode +c, which if set, users must be on a common channel with you to private message you", VF_VENDOR);
54 virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
56 if (target_type == TYPE_USER)
58 User* t = (User*)dest;
59 if (!IS_OPER(user) && (t->IsModeSet('c')) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t))
61 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());
65 return MOD_RES_PASSTHRU;
68 virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
70 return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
75 MODULE_INIT(ModulePrivacyMode)