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
32 Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash };
33 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
36 virtual void OnRehash(User* user)
38 /* check for redirect validity and loops/chains */
39 ConfigTagList tags = ServerInstance->Config->ConfTags("badchan");
40 for (ConfigIter i = tags.first; i != tags.second; ++i)
42 std::string name = i->second->getString("name");
43 std::string redirect = i->second->getString("redirect");
45 if (!redirect.empty())
48 if (!ServerInstance->IsChannel(redirect.c_str(), ServerInstance->Config->Limits.ChanMax))
51 user->WriteServ("NOTICE %s :Invalid badchan redirect '%s'", user->nick.c_str(), redirect.c_str());
52 throw ModuleException("Invalid badchan redirect, not a channel");
55 for (ConfigIter j = tags.first; j != tags.second; ++j)
57 if (InspIRCd::Match(redirect, j->second->getString("name")))
59 bool goodchan = false;
60 ConfigTagList goodchans = ServerInstance->Config->ConfTags("badchan");
61 for (ConfigIter k = goodchans.first; k != goodchans.second; ++k)
63 if (InspIRCd::Match(redirect, k->second->getString("name")))
69 /* <badchan:redirect> is a badchan */
71 user->WriteServ("NOTICE %s :Badchan %s redirects to badchan %s", user->nick.c_str(), name.c_str(), redirect.c_str());
72 throw ModuleException("Badchan redirect loop");
80 virtual ~ModuleDenyChannels()
84 virtual Version GetVersion()
86 return Version("Implements config tags which allow blocking of joins to channels", VF_VENDOR);
90 virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
92 ConfigTagList tags = ServerInstance->Config->ConfTags("badchan");
93 for (ConfigIter j = tags.first; j != tags.second; ++j)
95 if (InspIRCd::Match(cname, j->second->getString("name")))
97 if (IS_OPER(user) && j->second->getBool("allowopers"))
99 return MOD_RES_PASSTHRU;
103 std::string reason = j->second->getString("reason");
104 std::string redirect = j->second->getString("redirect");
106 ConfigTagList goodchans = ServerInstance->Config->ConfTags("goodchan");
107 for (ConfigIter i = goodchans.first; i != goodchans.second; ++i)
109 if (InspIRCd::Match(cname, i->second->getString("name")))
111 return MOD_RES_PASSTHRU;
115 if (ServerInstance->IsChannel(redirect.c_str(), ServerInstance->Config->Limits.ChanMax))
117 /* simple way to avoid potential loops: don't redirect to +L channels */
118 Channel *newchan = ServerInstance->FindChan(redirect);
119 if ((!newchan) || (!(newchan->IsModeSet('L'))))
121 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());
122 Channel::JoinUser(user,redirect.c_str(),false,"",false,ServerInstance->Time());
127 user->WriteNumeric(926, "%s %s :Channel %s is forbidden: %s",user->nick.c_str(),cname,cname,reason.c_str());
132 return MOD_RES_PASSTHRU;
136 MODULE_INIT(ModuleDenyChannels)