- }
- else
- {
- std::string reason = j->second->getString("reason");
- std::string redirect = j->second->getString("redirect");
-
- ConfigTagList goodchans = ServerInstance->Config->ConfTags("goodchan");
- for (ConfigIter i = goodchans.first; i != goodchans.second; ++i)
- {
- if (InspIRCd::Match(cname, i->second->getString("name")))
- {
- return MOD_RES_PASSTHRU;
- }
- }
-
- if (ServerInstance->IsChannel(redirect))
- {
- /* simple way to avoid potential loops: don't redirect to +L channels */
- Channel *newchan = ServerInstance->FindChan(redirect);
- if ((!newchan) || (!newchan->IsModeSet(redirectmode)))
- {
- user->WriteNumeric(926, "%s :Channel %s is forbidden, redirecting to %s: %s", cname.c_str(),cname.c_str(),redirect.c_str(), reason.c_str());
- Channel::JoinUser(user, redirect);
- return MOD_RES_DENY;
- }
- }
-
- user->WriteNumeric(926, "%s :Channel %s is forbidden: %s", cname.c_str(),cname.c_str(),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;