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 /** User mode +d - filter out channel messages and channel notices
26 class User_d : public ModeHandler
29 User_d(Module* Creator) : ModeHandler(Creator, "deaf", 'd', PARAM_NONE, MODETYPE_USER) { }
31 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
33 if (adding == dest->IsModeSet(this))
34 return MODEACTION_DENY;
37 dest->WriteNotice("*** 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 " + dest->nick + " -d.");
39 dest->SetMode(this, adding);
40 return MODEACTION_ALLOW;
44 class ModuleDeaf : public Module
47 std::string deaf_bypasschars;
48 std::string deaf_bypasschars_uline;
56 void init() CXX11_OVERRIDE
58 ServerInstance->Modules->AddService(m1);
61 Implementation eventlist[] = { I_OnUserPreMessage, I_OnRehash };
62 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
65 void OnRehash(User* user) CXX11_OVERRIDE
67 ConfigTag* tag = ServerInstance->Config->ConfValue("deaf");
68 deaf_bypasschars = tag->getString("bypasschars");
69 deaf_bypasschars_uline = tag->getString("bypasscharsuline");
72 ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
74 if (target_type == TYPE_CHANNEL)
76 Channel* chan = (Channel*)dest;
78 this->BuildDeafList(msgtype, chan, user, status, text, exempt_list);
81 return MOD_RES_PASSTHRU;
84 void BuildDeafList(MessageType message_type, Channel* chan, User* sender, char status, const std::string &text, CUList &exempt_list)
86 const UserMembList *ulist = chan->GetUsers();
88 bool is_bypasschar, is_bypasschar_avail;
89 bool is_bypasschar_uline, is_bypasschar_uline_avail;
91 is_bypasschar = is_bypasschar_avail = is_bypasschar_uline = is_bypasschar_uline_avail = 0;
92 if (!deaf_bypasschars.empty())
94 is_bypasschar_avail = 1;
95 if (deaf_bypasschars.find(text[0], 0) != std::string::npos)
98 if (!deaf_bypasschars_uline.empty())
100 is_bypasschar_uline_avail = 1;
101 if (deaf_bypasschars_uline.find(text[0], 0) != std::string::npos)
102 is_bypasschar_uline = 1;
106 * If we have no bypasschars_uline in config, and this is a bypasschar (regular)
107 * Than it is obviously going to get through +d, no build required
109 if (!is_bypasschar_uline_avail && is_bypasschar)
112 for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
115 if (!i->first->IsModeSet(m1))
116 continue; /* deliver message */
117 /* matched both U-line only and regular bypasses */
118 if (is_bypasschar && is_bypasschar_uline)
119 continue; /* deliver message */
121 is_a_uline = ServerInstance->ULine(i->first->server);
122 /* matched a U-line only bypass */
123 if (is_bypasschar_uline && is_a_uline)
124 continue; /* deliver message */
125 /* matched a regular bypass */
126 if (is_bypasschar && !is_a_uline)
127 continue; /* deliver message */
129 if (status && !strchr(chan->GetAllPrefixChars(i->first), status))
132 /* don't deliver message! */
133 exempt_list.insert(i->first);
137 Version GetVersion() CXX11_OVERRIDE
139 return Version("Provides usermode +d to block channel messages and channel notices", VF_VENDOR);
143 MODULE_INIT(ModuleDeaf)