1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides support for ircu style usermode +d (deaf to channel messages and channel notices) */
18 /** User mode +d - filter out channel messages and channel notices
20 class User_d : public ModeHandler
23 User_d(InspIRCd* Instance) : ModeHandler(Instance, 'd', 0, 0, false, MODETYPE_USER, false) { }
25 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
29 if (!dest->IsModeSet('d'))
31 dest->WriteServ("NOTICE %s :*** You have enabled usermode +d, deaf mode. This mode means you WILL NOT receive any messages from any channels you are in. If you did NOT mean to do this, use /mode %s -d.", dest->nick, dest->nick);
32 dest->SetMode('d',true);
33 return MODEACTION_ALLOW;
38 if (dest->IsModeSet('d'))
40 dest->SetMode('d',false);
41 return MODEACTION_ALLOW;
44 return MODEACTION_DENY;
48 class ModuleDeaf : public Module
52 ModuleDeaf(InspIRCd* Me)
55 m1 = new User_d(ServerInstance);
56 if (!ServerInstance->AddMode(m1, 'd'))
57 throw ModuleException("Could not add new modes!");
60 void Implements(char* List)
62 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnBuildExemptList] = 1;
65 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
67 return PreText(user, dest, target_type, text, status, exempt_list);
70 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
72 return PreText(user, dest, target_type, text, status, exempt_list);
75 virtual void OnBuildExemptList(MessageType message_type, chanrec* chan, userrec* sender, char status, CUList &exempt_list)
81 ulist = chan->GetOppedUsers();
84 ulist = chan->GetHalfoppedUsers();
87 ulist = chan->GetVoicedUsers();
90 ulist = chan->GetUsers();
94 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
96 if (IS_LOCAL(i->first))
98 if (i->first->IsModeSet('d'))
100 exempt_list[i->first] = i->first->nick;
106 virtual int PreText(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
108 if (target_type == TYPE_CHANNEL)
110 chanrec* chan = (chanrec*)dest;
114 this->OnBuildExemptList(MSG_PRIVMSG, chan, user, status, exempt_list);
120 virtual ~ModuleDeaf()
122 ServerInstance->Modes->DelMode(m1);
126 virtual Version GetVersion()
128 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
133 MODULE_INIT(ModuleDeaf)