- }
- else
- {
- std::string reason = Conf.ReadValue("badchan","reason",j);
- std::string redirect = Conf.ReadValue("badchan","redirect",j);
-
- for (int i = 0; i < Conf.Enumerate("goodchan"); i++)
- {
- if (InspIRCd::Match(cname, Conf.ReadValue("goodchan", "name", i)))
- {
- return MOD_RES_PASSTHRU;
- }
- }
-
- if (ServerInstance->IsChannel(redirect.c_str(), ServerInstance->Config->Limits.ChanMax))
- {
- /* simple way to avoid potential loops: don't redirect to +L channels */
- Channel *newchan = ServerInstance->FindChan(redirect);
- if ((!newchan) || (!(newchan->IsModeSet('L'))))
- {
- 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());
- Channel::JoinUser(user,redirect.c_str(),false,"",false,ServerInstance->Time());
- return MOD_RES_DENY;
- }
- }
-
- user->WriteNumeric(926, "%s %s :Channel %s is forbidden: %s",user->nick.c_str(),cname,cname,reason.c_str());
- return MOD_RES_DENY;
- }
+
+ // If there is no redirect chan, the user has enabled the antiredirect mode, or
+ // the target channel redirects elsewhere we just tell the user and deny the join.
+ Channel* target = NULL;
+ if (badchan.redirect.empty() || user->IsModeSet(antiredirectmode)
+ || ((target = ServerInstance->FindChan(badchan.redirect)) && target->IsModeSet(redirectmode)))
+ {
+ user->WriteNumeric(ERR_BADCHANNEL, cname, InspIRCd::Format("Channel %s is forbidden: %s",
+ cname.c_str(), badchan.reason.c_str()));
+ return MOD_RES_DENY;