2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7 * Copyright (C) 2005 Craig Edwards <craigedwards@brainbox.cc>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 /* $ModDesc: Implements config tags which allow blocking of joins to channels */
27 class ModuleDenyChannels : public Module
30 ModuleDenyChannels() {
31 Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash };
32 ServerInstance->Modules->Attach(eventlist, this, 2);
35 virtual void OnRehash(User* user)
38 /* check for redirect validity and loops/chains */
39 for (int i =0; i < Conf.Enumerate("badchan"); i++)
41 std::string name = Conf.ReadValue("badchan","name",i);
42 std::string redirect = Conf.ReadValue("badchan","redirect",i);
44 if (!redirect.empty())
47 if (!ServerInstance->IsChannel(redirect.c_str(), ServerInstance->Config->Limits.ChanMax))
50 user->WriteServ("NOTICE %s :Invalid badchan redirect '%s'", user->nick.c_str(), redirect.c_str());
51 throw ModuleException("Invalid badchan redirect, not a channel");
54 for (int j =0; j < Conf.Enumerate("badchan"); j++)
56 if (InspIRCd::Match(redirect, Conf.ReadValue("badchan","name",j)))
58 bool goodchan = false;
59 for (int k =0; k < Conf.Enumerate("goodchan"); k++)
61 if (InspIRCd::Match(redirect, Conf.ReadValue("goodchan","name",k)))
67 /* <badchan:redirect> is a badchan */
69 user->WriteServ("NOTICE %s :Badchan %s redirects to badchan %s", user->nick.c_str(), name.c_str(), redirect.c_str());
70 throw ModuleException("Badchan redirect loop");
78 virtual ~ModuleDenyChannels()
82 virtual Version GetVersion()
84 return Version("Implements config tags which allow blocking of joins to channels", VF_VENDOR);
88 virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
91 for (int j =0; j < Conf.Enumerate("badchan"); j++)
93 if (InspIRCd::Match(cname, Conf.ReadValue("badchan","name",j)))
95 if (IS_OPER(user) && Conf.ReadFlag("badchan","allowopers",j))
97 return MOD_RES_PASSTHRU;
101 std::string reason = Conf.ReadValue("badchan","reason",j);
102 std::string redirect = Conf.ReadValue("badchan","redirect",j);
104 for (int i = 0; i < Conf.Enumerate("goodchan"); i++)
106 if (InspIRCd::Match(cname, Conf.ReadValue("goodchan", "name", i)))
108 return MOD_RES_PASSTHRU;
112 if (ServerInstance->IsChannel(redirect.c_str(), ServerInstance->Config->Limits.ChanMax))
114 /* simple way to avoid potential loops: don't redirect to +L channels */
115 Channel *newchan = ServerInstance->FindChan(redirect);
116 if ((!newchan) || (!(newchan->IsModeSet('L'))))
118 user->WriteNumeric(926, "%s %s :Channel %s is forbidden, redirecting to %s: %s",user->nick.c_str(),cname,cname,redirect.c_str(), reason.c_str());
119 Channel::JoinUser(user,redirect.c_str(),false,"",false,ServerInstance->Time());
124 user->WriteNumeric(926, "%s %s :Channel %s is forbidden: %s",user->nick.c_str(),cname,cname,reason.c_str());
129 return MOD_RES_PASSTHRU;
133 MODULE_INIT(ModuleDenyChannels)