]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
And, just because I can. The one pointless one-liner of the evening. :p
[user/henk/code/inspircd.git] / src / channels.cpp
index fbec272b37623b826ac5bd42206b695e22c084b9..f169efb87db31e766d17c7cc9926d3389370db1e 100644 (file)
@@ -451,29 +451,53 @@ bool Channel::IsBanned(User* user)
        return false;
 }
 
-bool Channel::IsExtBanned(User *user, char type)
+bool Channel::IsExtBanned(const std::string &str, char type)
 {
-       // XXX. do we need events?
-       char mask[MAXBUF];
+       int MOD_RESULT = 0;
+       FOREACH_RESULT(I_OnCheckStringExtBan, OnCheckStringExtBan(str, this, type));
+
+       if (MOD_RESULT == -1)
+               return true;
+       else if (MOD_RESULT == 0)
+       {
+               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(!)
+                       std::string maskptr = i->data.substr(2);
+                       ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
 
-       snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
+                       if (match(str, maskptr))
+                               return true;
+               }
+       }
+
+       return false;
+}
 
-       for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
+bool Channel::IsExtBanned(User *user, char type)
+{
+       int MOD_RESULT = 0;
+       FOREACH_RESULT(I_OnCheckExtBan, OnCheckExtBan(user, this, type));
+
+       if (MOD_RESULT == -1)
+               return true;
+       else if (MOD_RESULT == 0)
        {
-               if (i->data[0] != type || i->data[1] != ':')
-                       continue;
+               char mask[MAXBUF];
+               snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
 
-               // Iterate past char and : to get to the mask without doing a data copy(!)
-               std::string maskptr = i->data.substr(2);
+               // XXX: we should probably hook cloaked hosts in here somehow too..
+               if (this->IsExtBanned(mask, type))
+                       return true;
 
-               /* 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)))
-               {
+               if (this->IsExtBanned(user->GetFullHost(), type))
+                       return true;
+
+               if (this->IsExtBanned(user->GetFullRealHost(), type))
                        return true;
-               }
        }
 
        return false;
@@ -485,15 +509,9 @@ bool Channel::IsExtBanned(User *user, char type)
  *
  * XXX: bleh, string copy of reason, fixme! -- w00t
  */
-long Channel::PartUser(User *user, const char* reason)
+long Channel::PartUser(User *user, std::string &reason)
 {
        bool silent = false;
-       std::string freason;
-
-       if (reason)
-               freason = reason;
-       else
-               freason = "";
 
        if (!user)
                return this->GetUserCounter();
@@ -501,10 +519,10 @@ long Channel::PartUser(User *user, const char* reason)
        UCListIter i = user->chans.find(this);
        if (i != user->chans.end())
        {
-               FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, freason, silent));
+               FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent));
 
                if (!silent)
-                       this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason ? " :" : "", reason ? reason : "");
+                       this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : ":", reason.c_str());
 
                user->chans.erase(i);
                this->RemoveAllPrefixes(user);