1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
32 if (!dest->IsModeSet('d'))
34 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());
35 dest->SetMode('d',true);
36 return MODEACTION_ALLOW;
41 if (dest->IsModeSet('d'))
43 dest->SetMode('d',false);
44 return MODEACTION_ALLOW;
47 return MODEACTION_DENY;
51 class ModuleDeaf : public Module
55 std::string deaf_bypasschars;
56 std::string deaf_bypasschars_uline;
59 ModuleDeaf(InspIRCd* Me)
62 m1 = new User_d(ServerInstance);
63 if (!ServerInstance->Modes->AddMode(m1))
64 throw ModuleException("Could not add new modes!");
67 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash, I_OnBuildExemptList };
68 ServerInstance->Modules->Attach(eventlist, this, 4);
72 virtual void OnRehash(User* user, const std::string&)
74 ConfigReader* conf = new ConfigReader(ServerInstance);
75 deaf_bypasschars = conf->ReadValue("deaf", "bypasschars", 0);
76 deaf_bypasschars_uline = conf->ReadValue("deaf", "bypasscharsuline", 0);
81 virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
83 if (target_type == TYPE_CHANNEL)
85 Channel* chan = (Channel*)dest;
87 this->BuildDeafList(MSG_NOTICE, chan, user, status, text, exempt_list);
93 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
95 if (target_type == TYPE_CHANNEL)
97 Channel* chan = (Channel*)dest;
99 this->BuildDeafList(MSG_PRIVMSG, chan, user, status, text, exempt_list);
105 virtual void OnBuildExemptList(MessageType message_type, Channel* chan, User* sender, char status, CUList &exempt_list, const std::string &text)
107 BuildDeafList(message_type, chan, sender, status, text, exempt_list);
110 virtual void BuildDeafList(MessageType message_type, Channel* chan, User* sender, char status, const std::string &text, CUList &exempt_list)
112 CUList *ulist = chan->GetUsers();
114 bool is_bypasschar, is_bypasschar_avail;
115 bool is_bypasschar_uline, is_bypasschar_uline_avail;
117 is_bypasschar = is_bypasschar_avail = is_bypasschar_uline = is_bypasschar_uline_avail = 0;
118 if (!deaf_bypasschars.empty())
120 is_bypasschar_avail = 1;
121 if (deaf_bypasschars.find(text[0], 0) != std::string::npos)
124 if (!deaf_bypasschars_uline.empty())
126 is_bypasschar_uline_avail = 1;
127 if (deaf_bypasschars_uline.find(text[0], 0) != std::string::npos)
128 is_bypasschar_uline = 1;
132 * If we have no bypasschars_uline in config, and this is a bypasschar (regular)
133 * Than it is obviously going to get through +d, no build required
135 if (!is_bypasschar_uline_avail && is_bypasschar)
138 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
141 if (!i->first->IsModeSet('d'))
142 continue; /* deliver message */
143 /* matched both U-line only and regular bypasses */
144 if (is_bypasschar && is_bypasschar_uline)
145 continue; /* deliver message */
147 is_a_uline = ServerInstance->ULine(i->first->server);
148 /* matched a U-line only bypass */
149 if (is_bypasschar_uline && is_a_uline)
150 continue; /* deliver message */
151 /* matched a regular bypass */
152 if (is_bypasschar && !is_a_uline)
153 continue; /* deliver message */
155 if (status && !strchr(chan->GetAllPrefixChars(i->first), status))
158 /* don't deliver message! */
159 exempt_list[i->first] = i->first->nick;
163 virtual ~ModuleDeaf()
165 ServerInstance->Modes->DelMode(m1);
169 virtual Version GetVersion()
171 return Version(1,2,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
176 MODULE_INIT(ModuleDeaf)