]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
The start of extended bans infrastructure: syntax is e.g. +b n:w00tdiff@*, bans of...
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 4 Apr 2008 21:43:21 +0000 (21:43 +0000)
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 4 Apr 2008 21:43:21 +0000 (21:43 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9337 e03df62e-2008-0410-955e-edbf42e46eb7

include/channels.h
src/channels.cpp
src/mode.cpp
src/modules/m_foobar.cpp

index 693f429f4966f5814dcc91fe3a989d8b5b8b1759..bf025ec560f8ff693589a28dfb77115d67f7daed 100644 (file)
@@ -528,6 +528,13 @@ class CoreExport Channel : public Extensible
         */
        bool IsBanned(User* user);
 
+       /** Check whether an extban of a given type matches
+        * a given user for this channel.
+        * @param u The user to match bans against
+        * @param type The type of extban to check
+        */
+       bool IsExtBanned(User *u, char type);
+
        /** Clears the cached max bans value
         */
        void ResetMaxBans();
index c03a69ace9222a66d3a95cd8b42859069c69e21e..5dde871177d7355f0a1a8a8f85b18154d44262ff 100644 (file)
@@ -450,6 +450,38 @@ bool Channel::IsBanned(User* user)
        return false;
 }
 
+bool Channel::IsExtBanned(User *user, char type)
+{
+       // XXX. do we need events?
+       char mask[MAXBUF];
+       char *maskptr;
+
+       snprintf(mask, MAXBUF, "%s!%s@%s", user->nick, user->ident, user->GetIPString());
+
+       for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
+       {
+               if (i->data[0] != type || i->data[1] != ':')
+                       continue;
+
+               // Iterate past char and : to get to the mask without doing a data copy(!)
+               maskptr = i->data;
+               maskptr++; // past the char
+               maskptr++; // past the :
+printf("realmask: %s\n", maskptr);
+
+               /* This allows CIDR ban matching
+                * 
+                *        Full masked host                             Full unmasked host                     IP with/without CIDR
+                */
+               if ((match(user->GetFullHost(), maskptr)) || (match(user->GetFullRealHost(), maskptr)) || (match(mask, maskptr, true)))
+               {
+                       return true;
+               }
+       }
+
+       return false;
+}
+
 /* Channel::PartUser
  * remove a channel from a users record, and return the number of users left.
  * Therefore, if this function returns 0 the caller should delete the Channel.
index 83aff70cf56400a4e64d29d89dc26cc196f65948..6805c348c8629cf7e53167dc978abea91a93d1a9 100644 (file)
@@ -705,12 +705,12 @@ void ModeParser::CleanMask(std::string &mask)
        std::string::size_type pos_of_pling = mask.find_first_of('!');
        std::string::size_type pos_of_at = mask.find_first_of('@');
        std::string::size_type pos_of_dot = mask.find_first_of('.');
-       std::string::size_type pos_of_colon = mask.find_first_of(':'); /* Because ipv6 addresses are colon delimited */
+       std::string::size_type pos_of_colons = mask.find("::"); /* Because ipv6 addresses are colon delimited -- double so it treats extban as nick */
 
        if ((pos_of_pling == std::string::npos) && (pos_of_at == std::string::npos))
        {
-               /* Just a nick, or just a host */
-               if ((pos_of_dot == std::string::npos) && (pos_of_colon == std::string::npos))
+               /* Just a nick, or just a host - or clearly ipv6 (starting with :) */
+               if ((pos_of_dot == std::string::npos) && (pos_of_colons == std::string::npos) && mask[0] != ':')
                {
                        /* It has no '.' in it, it must be a nick. */
                        mask.append("!*@*");
index 4917dd50196678220e6c0e9c6c9e0105c295c46d..d9254c4359d38d385028a5a45f957a1b93a1bcce 100644 (file)
@@ -35,8 +35,8 @@ class ModuleFoobar : public Module
                // The constructor just makes a copy of the server class
        
                
-               Implementation eventlist[] = { I_OnUserConnect, I_OnUserQuit, I_OnUserJoin, I_OnUserPart };
-               ServerInstance->Modules->Attach(eventlist, this, 4);
+               Implementation eventlist[] = { I_OnUserConnect, I_OnUserQuit, I_OnUserJoin, I_OnUserPart, I_OnUserPreJoin };
+               ServerInstance->Modules->Attach(eventlist, this, 5);
        }
        
        virtual ~ModuleFoobar()
@@ -86,6 +86,13 @@ class ModuleFoobar : public Module
                ServerInstance->Logs->Log("m_foobar",DEBUG,"Foobar: User "+b+" parted "+c);
        }
 
+       virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs)
+       {
+               if (chan->IsExtBanned(user, 'n'))
+                       return 1;
+
+               return 0;
+       }
 };