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: 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(Module* Creator) : ModeHandler(Creator, "deaf", 'd', PARAM_NONE, MODETYPE_USER) { }
25 ModeAction OnModeChange(User* source, User* dest, Channel* 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.c_str(), dest->nick.c_str());
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 std::string deaf_bypasschars;
53 std::string deaf_bypasschars_uline;
59 if (!ServerInstance->Modes->AddMode(&m1))
60 throw ModuleException("Could not add new modes!");
63 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash };
64 ServerInstance->Modules->Attach(eventlist, this, 3);
68 virtual void OnRehash(User* user)
71 deaf_bypasschars = conf.ReadValue("deaf", "bypasschars", 0);
72 deaf_bypasschars_uline = conf.ReadValue("deaf", "bypasscharsuline", 0);
75 virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
77 if (target_type == TYPE_CHANNEL)
79 Channel* chan = (Channel*)dest;
81 this->BuildDeafList(MSG_NOTICE, chan, user, status, text, exempt_list);
84 return MOD_RES_PASSTHRU;
87 virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
89 if (target_type == TYPE_CHANNEL)
91 Channel* chan = (Channel*)dest;
93 this->BuildDeafList(MSG_PRIVMSG, chan, user, status, text, exempt_list);
96 return MOD_RES_PASSTHRU;
99 virtual void BuildDeafList(MessageType message_type, Channel* chan, User* sender, char status, const std::string &text, CUList &exempt_list)
101 const UserMembList *ulist = chan->GetUsers();
103 bool is_bypasschar, is_bypasschar_avail;
104 bool is_bypasschar_uline, is_bypasschar_uline_avail;
106 is_bypasschar = is_bypasschar_avail = is_bypasschar_uline = is_bypasschar_uline_avail = 0;
107 if (!deaf_bypasschars.empty())
109 is_bypasschar_avail = 1;
110 if (deaf_bypasschars.find(text[0], 0) != std::string::npos)
113 if (!deaf_bypasschars_uline.empty())
115 is_bypasschar_uline_avail = 1;
116 if (deaf_bypasschars_uline.find(text[0], 0) != std::string::npos)
117 is_bypasschar_uline = 1;
121 * If we have no bypasschars_uline in config, and this is a bypasschar (regular)
122 * Than it is obviously going to get through +d, no build required
124 if (!is_bypasschar_uline_avail && is_bypasschar)
127 for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
130 if (!i->first->IsModeSet('d'))
131 continue; /* deliver message */
132 /* matched both U-line only and regular bypasses */
133 if (is_bypasschar && is_bypasschar_uline)
134 continue; /* deliver message */
136 is_a_uline = ServerInstance->ULine(i->first->server);
137 /* matched a U-line only bypass */
138 if (is_bypasschar_uline && is_a_uline)
139 continue; /* deliver message */
140 /* matched a regular bypass */
141 if (is_bypasschar && !is_a_uline)
142 continue; /* deliver message */
144 if (status && !strchr(chan->GetAllPrefixChars(i->first), status))
147 /* don't deliver message! */
148 exempt_list.insert(i->first);
152 virtual ~ModuleDeaf()
156 virtual Version GetVersion()
158 return Version("Provides support for ircu style usermode +d (deaf to channel messages and channel notices)", VF_COMMON|VF_VENDOR);
163 MODULE_INIT(ModuleDeaf)