2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2006, 2008 Craig Edwards <craigedwards@brainbox.cc>
5 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2006-2007 Dennis Friis <peavey@inspircd.org>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /* $ModDesc: Provides support for ircu style usermode +d (deaf to channel messages and channel notices) */
26 /** User mode +d - filter out channel messages and channel notices
28 class User_d : public ModeHandler
31 User_d(Module* Creator) : ModeHandler(Creator, "deaf", 'd', PARAM_NONE, MODETYPE_USER) { }
33 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
37 if (!dest->IsModeSet('d'))
39 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());
40 dest->SetMode('d',true);
41 return MODEACTION_ALLOW;
46 if (dest->IsModeSet('d'))
48 dest->SetMode('d',false);
49 return MODEACTION_ALLOW;
52 return MODEACTION_DENY;
56 class ModuleDeaf : public Module
60 std::string deaf_bypasschars;
61 std::string deaf_bypasschars_uline;
67 if (!ServerInstance->Modes->AddMode(&m1))
68 throw ModuleException("Could not add new modes!");
71 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash };
72 ServerInstance->Modules->Attach(eventlist, this, 3);
76 virtual void OnRehash(User* user)
79 deaf_bypasschars = conf.ReadValue("deaf", "bypasschars", 0);
80 deaf_bypasschars_uline = conf.ReadValue("deaf", "bypasscharsuline", 0);
83 virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
85 if (target_type == TYPE_CHANNEL)
87 Channel* chan = (Channel*)dest;
89 this->BuildDeafList(MSG_NOTICE, chan, user, status, text, exempt_list);
92 return MOD_RES_PASSTHRU;
95 virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
97 if (target_type == TYPE_CHANNEL)
99 Channel* chan = (Channel*)dest;
101 this->BuildDeafList(MSG_PRIVMSG, chan, user, status, text, exempt_list);
104 return MOD_RES_PASSTHRU;
107 virtual void BuildDeafList(MessageType message_type, Channel* chan, User* sender, char status, const std::string &text, CUList &exempt_list)
109 const UserMembList *ulist = chan->GetUsers();
111 bool is_bypasschar, is_bypasschar_avail;
112 bool is_bypasschar_uline, is_bypasschar_uline_avail;
114 is_bypasschar = is_bypasschar_avail = is_bypasschar_uline = is_bypasschar_uline_avail = 0;
115 if (!deaf_bypasschars.empty())
117 is_bypasschar_avail = 1;
118 if (deaf_bypasschars.find(text[0], 0) != std::string::npos)
121 if (!deaf_bypasschars_uline.empty())
123 is_bypasschar_uline_avail = 1;
124 if (deaf_bypasschars_uline.find(text[0], 0) != std::string::npos)
125 is_bypasschar_uline = 1;
129 * If we have no bypasschars_uline in config, and this is a bypasschar (regular)
130 * Than it is obviously going to get through +d, no build required
132 if (!is_bypasschar_uline_avail && is_bypasschar)
135 for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
138 if (!i->first->IsModeSet('d'))
139 continue; /* deliver message */
140 /* matched both U-line only and regular bypasses */
141 if (is_bypasschar && is_bypasschar_uline)
142 continue; /* deliver message */
144 is_a_uline = ServerInstance->ULine(i->first->server);
145 /* matched a U-line only bypass */
146 if (is_bypasschar_uline && is_a_uline)
147 continue; /* deliver message */
148 /* matched a regular bypass */
149 if (is_bypasschar && !is_a_uline)
150 continue; /* deliver message */
152 if (status && !strchr(chan->GetAllPrefixChars(i->first), status))
155 /* don't deliver message! */
156 exempt_list.insert(i->first);
160 virtual ~ModuleDeaf()
164 virtual Version GetVersion()
166 return Version("Provides support for ircu style usermode +d (deaf to channel messages and channel notices)", VF_VENDOR);
171 MODULE_INIT(ModuleDeaf)