1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Implements config tags which allow blocking of joins to channels */
18 class ModuleDenyChannels : public Module
21 ModuleDenyChannels() {
22 Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash };
23 ServerInstance->Modules->Attach(eventlist, this, 2);
26 virtual void OnRehash(User* user)
29 /* check for redirect validity and loops/chains */
30 for (int i =0; i < Conf.Enumerate("badchan"); i++)
32 std::string name = Conf.ReadValue("badchan","name",i);
33 std::string redirect = Conf.ReadValue("badchan","redirect",i);
35 if (!redirect.empty())
38 if (!ServerInstance->IsChannel(redirect.c_str(), ServerInstance->Config->Limits.ChanMax))
41 user->WriteServ("NOTICE %s :Invalid badchan redirect '%s'", user->nick.c_str(), redirect.c_str());
42 throw ModuleException("Invalid badchan redirect, not a channel");
45 for (int j =0; j < Conf.Enumerate("badchan"); j++)
47 if (InspIRCd::Match(redirect, Conf.ReadValue("badchan","name",j)))
49 bool goodchan = false;
50 for (int k =0; k < Conf.Enumerate("goodchan"); k++)
52 if (InspIRCd::Match(redirect, Conf.ReadValue("goodchan","name",k)))
58 /* <badchan:redirect> is a badchan */
60 user->WriteServ("NOTICE %s :Badchan %s redirects to badchan %s", user->nick.c_str(), name.c_str(), redirect.c_str());
61 throw ModuleException("Badchan redirect loop");
69 virtual ~ModuleDenyChannels()
73 virtual Version GetVersion()
75 return Version("Implements config tags which allow blocking of joins to channels", VF_VENDOR);
79 virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
82 for (int j =0; j < Conf.Enumerate("badchan"); j++)
84 if (InspIRCd::Match(cname, Conf.ReadValue("badchan","name",j)))
86 if (IS_OPER(user) && Conf.ReadFlag("badchan","allowopers",j))
88 return MOD_RES_PASSTHRU;
92 std::string reason = Conf.ReadValue("badchan","reason",j);
93 std::string redirect = Conf.ReadValue("badchan","redirect",j);
95 for (int i = 0; i < Conf.Enumerate("goodchan"); i++)
97 if (InspIRCd::Match(cname, Conf.ReadValue("goodchan", "name", i)))
99 return MOD_RES_PASSTHRU;
103 if (ServerInstance->IsChannel(redirect.c_str(), ServerInstance->Config->Limits.ChanMax))
105 /* simple way to avoid potential loops: don't redirect to +L channels */
106 Channel *newchan = ServerInstance->FindChan(redirect);
107 if ((!newchan) || (!(newchan->IsModeSet('L'))))
109 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());
110 Channel::JoinUser(user,redirect.c_str(),false,"",false,ServerInstance->Time());
115 user->WriteNumeric(926, "%s %s :Channel %s is forbidden: %s",user->nick.c_str(),cname,cname,reason.c_str());
120 return MOD_RES_PASSTHRU;
124 MODULE_INIT(ModuleDenyChannels)