]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_denychans.cpp
Convert WriteNumeric() calls to pass the parameters of the numeric as method parameters
[user/henk/code/inspircd.git] / src / modules / m_denychans.cpp
index 63f6f51b9da2ac893c72a9374afc3cc6073c06b4..467c8a03b3dfe6f0c02a2ea18506cdc00949c941 100644 (file)
 
 #include "inspircd.h"
 
-/* $ModDesc: Implements config tags which allow blocking of joins to channels */
-
 class ModuleDenyChannels : public Module
 {
+       ChanModeReference redirectmode;
+
  public:
-       void init() CXX11_OVERRIDE
+       ModuleDenyChannels()
+               : redirectmode(this, "redirect")
        {
-               Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void OnRehash(User* user) CXX11_OVERRIDE
+       void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                /* check for redirect validity and loops/chains */
                ConfigTagList tags = ServerInstance->Config->ConfTags("badchan");
@@ -45,10 +44,10 @@ class ModuleDenyChannels : public Module
                        if (!redirect.empty())
                        {
 
-                               if (!ServerInstance->IsChannel(redirect, ServerInstance->Config->Limits.ChanMax))
+                               if (!ServerInstance->IsChannel(redirect))
                                {
-                                       if (user)
-                                               user->WriteNotice("Invalid badchan redirect '" + redirect + "'");
+                                       if (status.srcuser)
+                                               status.srcuser->WriteNotice("Invalid badchan redirect '" + redirect + "'");
                                        throw ModuleException("Invalid badchan redirect, not a channel");
                                }
 
@@ -57,7 +56,7 @@ class ModuleDenyChannels : public Module
                                        if (InspIRCd::Match(redirect, j->second->getString("name")))
                                        {
                                                bool goodchan = false;
-                                               ConfigTagList goodchans = ServerInstance->Config->ConfTags("badchan");
+                                               ConfigTagList goodchans = ServerInstance->Config->ConfTags("goodchan");
                                                for (ConfigIter k = goodchans.first; k != goodchans.second; ++k)
                                                {
                                                        if (InspIRCd::Match(redirect, k->second->getString("name")))
@@ -67,8 +66,8 @@ class ModuleDenyChannels : public Module
                                                if (!goodchan)
                                                {
                                                        /* <badchan:redirect> is a badchan */
-                                                       if (user)
-                                                               user->WriteNotice("Badchan " + name + " redirects to badchan " + redirect);
+                                                       if (status.srcuser)
+                                                               status.srcuser->WriteNotice("Badchan " + name + " redirects to badchan " + redirect);
                                                        throw ModuleException("Badchan redirect loop");
                                                }
                                        }
@@ -108,19 +107,19 @@ class ModuleDenyChannels : public Module
                                                }
                                        }
 
-                                       if (ServerInstance->IsChannel(redirect.c_str(), ServerInstance->Config->Limits.ChanMax))
+                                       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('L'))))
+                                               if ((!newchan) || (!newchan->IsModeSet(redirectmode)))
                                                {
-                                                       user->WriteNumeric(926, "%s %s :Channel %s is forbidden, redirecting to %s: %s",user->nick.c_str(),cname.c_str(),cname.c_str(),redirect.c_str(), reason.c_str());
+                                                       user->WriteNumeric(926, cname, InspIRCd::Format("Channel %s is forbidden, redirecting to %s: %s", cname.c_str(), redirect.c_str(), reason.c_str()));
                                                        Channel::JoinUser(user, redirect);
                                                        return MOD_RES_DENY;
                                                }
                                        }
 
-                                       user->WriteNumeric(926, "%s %s :Channel %s is forbidden: %s",user->nick.c_str(),cname.c_str(),cname.c_str(),reason.c_str());
+                                       user->WriteNumeric(926, cname, InspIRCd::Format("Channel %s is forbidden: %s", cname.c_str(), reason.c_str()));
                                        return MOD_RES_DENY;
                                }
                        }