]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_banredirect.cpp
Damn strict typing to hell
[user/henk/code/inspircd.git] / src / modules / m_banredirect.cpp
index 3a5acfb342ad579b7944b404c8d7739fbcdcc11e..78cd24233144492b3eee95bc1e03eef75ebf6d74 100644 (file)
  */
 
 #include "inspircd.h"
-#include "mode.h"
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
+#include "u_listmode.h"
 
 /* $ModDesc: Allows an extended ban (+b) syntax redirecting banned users to another channel */
 
@@ -65,7 +62,7 @@ class BanRedirect : public ModeWatcher
                        std::string::iterator start_pos = param.begin();
                        long maxbans = channel->GetMaxBans();
                
-                       if(channel->bans.size() > static_cast<unsigned>(maxbans))
+                       if(adding && (channel->bans.size() > static_cast<unsigned>(maxbans)))
                        {
                                source->WriteServ("478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %d)", source->nick, channel->name, channel->name, maxbans);
                                return false;
@@ -187,7 +184,8 @@ class ModuleBanRedirect : public Module
 {
        BanRedirect* re;
        bool nofollow;
-       
+       Module* ExceptionModule;
+
  public:
        ModuleBanRedirect(InspIRCd* Me)
        : Module(Me)
@@ -197,11 +195,13 @@ class ModuleBanRedirect : public Module
                
                if(!ServerInstance->AddModeWatcher(re))
                        throw ModuleException("Could not add mode watcher");
+
+               OnRehash(NULL, "");
        }
        
        void Implements(char* List)
        {
-               List[I_OnUserPreJoin] = List[I_OnChannelDelete] = List[I_OnCleanup] = 1;
+               List[I_OnRehash] = List[I_OnUserPreJoin] = List[I_OnChannelDelete] = List[I_OnCleanup] = 1;
        }
        
        virtual void OnChannelDelete(chanrec* chan)
@@ -220,9 +220,7 @@ class ModuleBanRedirect : public Module
                        {
                                irc::modestacker modestack(false);
                                StringDeque stackresult;
-                               const char* mode_junk[MAXMODES+1];
-                               userrec* myhorriblefakeuser = new userrec(ServerInstance);
-                               myhorriblefakeuser->SetFd(FD_MAGIC_NUMBER);
+                               const char* mode_junk[MAXMODES+2];
                                
                                mode_junk[0] = chan->name;
                                
@@ -244,16 +242,20 @@ class ModuleBanRedirect : public Module
                                                mode_junk[i+1] = stackresult[i].c_str();
                                        }
                                        
-                                       ServerInstance->SendMode(mode_junk, stackresult.size() + 1, myhorriblefakeuser);
+                                       ServerInstance->SendMode(mode_junk, stackresult.size() + 1, ServerInstance->FakeClient);
                                }
                                
-                               DELETE(myhorriblefakeuser);
                                DELETE(redirects);
                                chan->Shrink("banredirects");
                        }
                }
        }
 
+       virtual void OnRehash(userrec* user, const std::string &param)
+       {
+               ExceptionModule = ServerInstance->FindModule("m_banexception.so");
+       }
+
        virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs)
        {
                /* This prevents recursion when a user sets multiple ban redirects in a chain
@@ -274,6 +276,15 @@ class ModuleBanRedirect : public Module
                                /* This was replaced with user->MakeHostIP() when I had a snprintf(), but MakeHostIP() doesn't seem to add the nick.
                                 * Maybe we should have a GetFullIPHost() or something to match GetFullHost() and GetFullRealHost?
                                 */
+
+                               if (ExceptionModule)
+                               {
+                                       ListModeRequest n(this, ExceptionModule, user, chan);
+                                       /* Users with ban exceptions are allowed to join without being redirected */
+                                       if (n.Send())
+                                               return 0;
+                               }
+
                                std::string ipmask(user->nick);
                                ipmask.append(1, '!').append(user->MakeHostIP());
                                
@@ -291,7 +302,8 @@ class ModuleBanRedirect : public Module
                                                }
                                                else
                                                {
-                                                       user->WriteServ("470 %s :You are banned from %s. You are being automatically redirected to %s", user->nick, chan->name, redir->targetchan.c_str());
+                                                       user->WriteServ("474 %s %s :Cannot join channel (You are banned)", user->nick, chan->name);
+                                                       user->WriteServ("470 %s :You are being automatically redirected to %s", user->nick, redir->targetchan.c_str());
                                                        nofollow = true;
                                                        chanrec::JoinUser(ServerInstance, user, redir->targetchan.c_str(), false, "", ServerInstance->Time(true));
                                                        nofollow = false;
@@ -314,29 +326,12 @@ class ModuleBanRedirect : public Module
        {
                return Version(1, 0, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
        }
-};
-
-
-class ModuleBanRedirectFactory : public ModuleFactory
-{
- public:
-       ModuleBanRedirectFactory()
-       {
-       }
        
-       ~ModuleBanRedirectFactory()
+       Priority Prioritize()
        {
+               return (Priority)ServerInstance->PriorityBefore("m_banexception.so");
        }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleBanRedirect(Me);
-       }
-       
 };
 
 
-extern "C" DllExport void * init_module( void )
-{
-       return new ModuleBanRedirectFactory;
-}
+MODULE_INIT(ModuleBanRedirect)