1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /* $ModDesc: Implements config tags which allow blocking of joins to channels */
19 class ModuleDenyChannels : public Module
27 ModuleDenyChannels(InspIRCd* Me) : Module(Me)
30 Conf = new ConfigReader(ServerInstance);
31 Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash };
32 ServerInstance->Modules->Attach(eventlist, this, 2);
35 virtual void OnRehash(User* user, const std::string ¶m)
38 Conf = new ConfigReader(ServerInstance);
39 /* check for redirect validity and loops/chains */
40 for (int i =0; i < Conf->Enumerate("badchan"); i++)
42 std::string name = Conf->ReadValue("badchan","name",i);
43 std::string redirect = Conf->ReadValue("badchan","redirect",i);
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 (int j =0; j < Conf->Enumerate("badchan"); j++)
57 if (match(redirect, Conf->ReadValue("badchan","name",j)))
59 bool goodchan = false;
60 for (int k =0; k < Conf->Enumerate("goodchan"); k++)
62 if (match(redirect, Conf->ReadValue("goodchan","name",k)))
68 /* <badchan:redirect> is a badchan */
70 user->WriteServ("NOTICE %s :Badchan %s redirects to badchan %s", user->nick.c_str(), name.c_str(), redirect.c_str());
71 throw ModuleException("Badchan redirect loop");
79 virtual ~ModuleDenyChannels()
84 virtual Version GetVersion()
86 return Version(1,2,0,1,VF_VENDOR,API_VERSION);
90 virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
92 for (int j =0; j < Conf->Enumerate("badchan"); j++)
94 if (match(cname, Conf->ReadValue("badchan","name",j)))
96 if (IS_OPER(user) && Conf->ReadFlag("badchan","allowopers",j))
102 std::string reason = Conf->ReadValue("badchan","reason",j);
103 std::string redirect = Conf->ReadValue("badchan","redirect",j);
105 for (int i = 0; i < Conf->Enumerate("goodchan"); i++)
107 if (match(cname, Conf->ReadValue("goodchan", "name", i)))
113 if (ServerInstance->IsChannel(redirect.c_str(), ServerInstance->Config->Limits.ChanMax))
115 /* simple way to avoid potential loops: don't redirect to +L channels */
116 Channel *newchan = ServerInstance->FindChan(redirect);
117 if ((!newchan) || (!(newchan->IsModeSet('L'))))
119 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());
120 Channel::JoinUser(ServerInstance,user,redirect.c_str(),false,"",false,ServerInstance->Time());
125 user->WriteNumeric(926, "%s %s :Channel %s is forbidden: %s",user->nick.c_str(),cname,cname,reason.c_str());
134 MODULE_INIT(ModuleDenyChannels)