]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add chanrec::IsBanned() so that we dont have to keep walking the banlist in various...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 2 Sep 2006 14:09:45 +0000 (14:09 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 2 Sep 2006 14:09:45 +0000 (14:09 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5099 e03df62e-2008-0410-955e-edbf42e46eb7

include/channels.h
src/channels.cpp
src/modules/m_override.cpp
src/modules/m_timedbans.cpp

index 14e06d40fc5b71183b8ad2426a712a8356eb4d12..d0d2215506cc3421a21bd79fcdef27a8a623bbd8 100644 (file)
@@ -527,6 +527,12 @@ class chanrec : public Extensible
         */
        void SetPrefix(userrec* user, char prefix, unsigned int prefix_rank, bool adding);
 
+       /** Check if a user is banned on this channel
+        * @param user A user to check against the banlist
+        * @returns True if the user given is banned
+        */
+       bool IsBanned(userrec* user);
+
        /** Destructor for chanrec
         */
        virtual ~chanrec() { /* stub */ }
index 5c3bb266f15e9e242e7f7f827e168ca7d20416f9..dab5188442324df41993ebd6f19e82aca7b21929 100644 (file)
@@ -318,17 +318,10 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo
                                        sprintf(mask,"%s!%s@%s",user->nick, user->ident, user->GetIPString());
                                        if (!MOD_RESULT)
                                        {
-                                               for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
+                                               if (Ptr->IsBanned(user))
                                                {
-                                                       /* This allows CIDR ban matching
-                                                        * 
-                                                        *        Full masked host                      Full unmasked host                   IP with/without CIDR
-                                                        */
-                                                       if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
-                                                       {
-                                                               user->WriteServ("474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name);
-                                                               return NULL;
-                                                       }
+                                                       user->WriteServ("474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name);
+                                                       return NULL;
                                                }
                                        }
                                }
@@ -442,6 +435,25 @@ chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr,ucrec *a,userrec* u
        return Ptr;
 }
 
+bool chanrec::IsBanned(userrec* user)
+{
+       char mask[MAXBUF];
+       sprintf(mask,"%s!%s@%s",user->nick, user->ident, user->GetIPString());
+       for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
+       {
+               /* This allows CIDR ban matching
+                * 
+                *        Full masked host                      Full unmasked host                   IP with/without CIDR
+                */
+               if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
+               {
+                       return true;
+               }
+
+       }
+       return false;
+}
+
 /* chanrec::PartUser
  * remove a channel from a users record, and remove the record from the hash
  * if the channel has become empty
index 342e42829ecf8ecab19fe2d2be5c461d0caa899b..7dd58d8c29255bc0202fb6614e192020eec835b3 100644 (file)
@@ -231,17 +231,12 @@ class ModuleOverride : public Module
 
                                if (CanOverride(user,"BANWALK"))
                                {
-                                       for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
+                                       if (chan->IsBanned(user))
                                        {
-                                               char mask[MAXBUF];
-                                               sprintf(mask,"%s!%s@%s",user->nick, user->ident, user->GetIPString());
-                                               if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
+                                               if (NoisyOverride)
                                                {
-                                                       if (NoisyOverride)
-                                                       {
-                                                               chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass channel bans on %s", cname, user->nick,i->data);
-                                                               ServerInstance->SNO->WriteToSnoMask('O',"%s used oper-override to bypass channel bans on %s", cname, user->nick, i->data);
-                                                       }
+                                                       chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass channel ban", cname, user->nick);
+                                                       ServerInstance->SNO->WriteToSnoMask('O',"%s used oper-override to bypass channel ban", cname, user->nick);
                                                }
                                        }
                                        return -1;
index 8639aa7df16a9b3c3261e0a580bf8564250aeed5..08da114a694999056c6c53d9f3d98382e3ee8aed 100644 (file)
@@ -64,13 +64,10 @@ class cmd_tban : public command_t
                                        user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid ban mask");
                                        return;
                                }
-                               for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
+                               if (channel->IsBanned(user))
                                {
-                                       if (!strcasecmp(i->data,parameters[2]))
-                                       {
-                                               user->WriteServ("NOTICE "+std::string(user->nick)+" :The ban "+std::string(parameters[2])+" is already on the banlist of "+std::string(parameters[0]));
-                                               return;
-                                       }
+                                       user->WriteServ("NOTICE "+std::string(user->nick)+" :The ban "+std::string(parameters[2])+" is already on the banlist of "+std::string(parameters[0]));
+                                       return;
                                }
                                TimedBan T;
                                std::string channelname = parameters[0];