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 * ---------------------------------------------------
19 /* $ModDesc: Provides support for ircu style usermode +d (deaf to channel messages and channel notices) */
21 /** User mode +d - filter out channel messages and channel notices
23 class User_d : public ModeHandler
26 User_d(InspIRCd* Instance) : ModeHandler(Instance, 'd', 0, 0, false, MODETYPE_USER, false) { }
28 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
32 if (!dest->IsModeSet('d'))
34 dest->SetMode('d',true);
35 return MODEACTION_ALLOW;
40 if (dest->IsModeSet('d'))
42 dest->SetMode('d',false);
43 return MODEACTION_ALLOW;
46 return MODEACTION_DENY;
50 class ModuleDeaf : public Module
54 ModuleDeaf(InspIRCd* Me)
57 m1 = new User_d(ServerInstance);
58 if (!ServerInstance->AddMode(m1, 'd'))
59 throw ModuleException("Could not add new modes!");
62 void Implements(char* List)
64 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnBuildExemptList] = 1;
67 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
69 return PreText(user, dest, target_type, text, status, exempt_list);
72 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
74 return PreText(user, dest, target_type, text, status, exempt_list);
77 virtual void OnBuildExemptList(MessageType message_type, chanrec* chan, userrec* sender, char status, CUList &exempt_list)
83 ulist = chan->GetOppedUsers();
86 ulist = chan->GetHalfoppedUsers();
89 ulist = chan->GetVoicedUsers();
92 ulist = chan->GetUsers();
96 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
98 if (IS_LOCAL(i->second))
100 if (i->second->IsModeSet('d'))
102 exempt_list[i->second] = i->second;
108 virtual int PreText(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
110 if ((target_type == TYPE_CHANNEL) & (IS_LOCAL(user)))
112 chanrec* chan = (chanrec*)dest;
115 this->OnBuildExemptList(MSG_PRIVMSG, chan, user, status, exempt_list);
121 virtual ~ModuleDeaf()
123 ServerInstance->Modes->DelMode(m1);
127 virtual Version GetVersion()
129 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
135 class ModuleDeafFactory : public ModuleFactory
146 virtual Module * CreateModule(InspIRCd* Me)
148 return new ModuleDeaf(Me);
154 extern "C" void * init_module( void )
156 return new ModuleDeafFactory;