]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/xline.cpp
Comments
[user/henk/code/inspircd.git] / src / xline.cpp
index 028067794fb5f34db689653387cfd5d860ac4ff4..56bd029d7a754b8fefb9f9b3dd8ef1daa35c4d00 100644 (file)
@@ -73,10 +73,18 @@ void XLineManager::CheckELines()
        {
                User* u = (User*)(*u2);
 
-               for (LookupIter i = ELines.begin(); i != ELines.end(); i++)
+               /* This uses safe iteration to ensure that if a line expires here, it doenst trash the iterator */
+               LookupIter safei;
+
+               for (LookupIter i = ELines.begin(); i != ELines.end(); )
                {
+                       safei = i;
+                       safei++;
+
                        XLine *e = i->second;
                        u->exempt = e->Matches(u);
+
+                       i = safei;
                }
        }
 }
@@ -89,6 +97,21 @@ XLineLookup* XLineManager::GetAll(const std::string &type)
        if (n == lookup_lines.end())
                return NULL;
 
+       LookupIter safei;
+       const time_t current = ServerInstance->Time();
+
+       /* Expire any dead ones, before sending */
+       for (LookupIter x = n->second.begin(); x != n->second.end(); )
+       {
+               safei = x;
+               safei++;
+               if (x->second->duration && current > x->second->expiry)
+               {
+                       ExpireLine(n, x);
+               }
+               x = safei;
+       }
+
        return &(n->second);
 }
 
@@ -195,19 +218,30 @@ XLine* XLineManager::MatchesLine(const std::string &type, User* user)
 
        const time_t current = ServerInstance->Time();
 
-       for (LookupIter i = x->second.begin(); i != x->second.end(); i++)
+       LookupIter safei;
+
+       for (LookupIter i = x->second.begin(); i != x->second.end(); )
        {
+               safei = i;
+               safei++;
+
                if (i->second->Matches(user))
                {
-                       if (current > i->second->expiry)
+                       if (i->second->duration && current > i->second->expiry)
                        {
                                /* Expire the line, return nothing */
                                ExpireLine(x, i);
-                               return NULL;
+                               /* Continue, there may be another that matches
+                                * (thanks aquanight)
+                                */
+                               i = safei;
+                               continue;
                        }
                        else
                                return i->second;
                }
+
+               i = safei;
        }
        return NULL;
 }
@@ -221,19 +255,28 @@ XLine* XLineManager::MatchesLine(const std::string &type, const std::string &pat
 
        const time_t current = ServerInstance->Time();
 
-       for (LookupIter i = x->second.begin(); i != x->second.end(); i++)
+        LookupIter safei;
+
+       for (LookupIter i = x->second.begin(); i != x->second.end(); )
        {
+               safei = i;
+               safei++;
+
                if (i->second->Matches(pattern))
                {
-                       if (current > i->second->expiry)
+                       if (i->second->duration && current > i->second->expiry)
                        {
                                /* Expire the line, return nothing */
                                ExpireLine(x, i);
-                               return NULL;
+                               /* See above */
+                               i = safei;
+                               continue;
                        }
                        else
                                return i->second;
                }
+
+               i = safei;
        }
        return NULL;
 }
@@ -275,25 +318,33 @@ void XLineManager::ApplyLines()
        pending_lines.clear();
 }
 
-/* k: 216
- * g: 223
- * q: 217
- * z: 223
- * e: 223
- */
-
 void XLineManager::InvokeStats(const std::string &type, int numeric, User* user, string_list &results)
 {
        std::string sn = ServerInstance->Config->ServerName;
 
        ContainerIter n = lookup_lines.find(type);
 
+       time_t current = ServerInstance->Time();
+
+       LookupIter safei;
+
        if (n != lookup_lines.end())
        {
                XLineLookup& list = n->second;
-               for (LookupIter i = list.begin(); i != list.end(); i++)
-                       results.push_back(sn+" "+ConvToStr(numeric)+" "+user->nick+" :"+i->second->Displayable()+" "+
+               for (LookupIter i = list.begin(); i != list.end(); )
+               {
+                       safei = i;
+                       safei++;
+
+                       if (i->second->duration && current > i->second->expiry)
+                       {
+                               ExpireLine(n, i);
+                       }
+                       else
+                               results.push_back(sn+" "+ConvToStr(numeric)+" "+user->nick+" :"+i->second->Displayable()+" "+
                                        ConvToStr(i->second->set_time)+" "+ConvToStr(i->second->duration)+" "+std::string(i->second->source)+" :"+(i->second->reason));
+                       i = safei;
+               }
        }
 }
 
@@ -432,8 +483,8 @@ bool QLine::Matches(User *u)
 
 void QLine::Apply(User* u)
 {       
-       /* Can we force the user to their uid here instead? */
-       DefaultApply(u, "Q");
+       /* Force to uuid on apply of qline, no need to disconnect any more :) */
+       u->ForceNickChange(u->uuid);
 }