summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-01-09 13:37:12 -0500
committerAdam <Adam@anope.org>2011-01-09 13:38:15 -0500
commit07528ea8f29422dd1dc66c4c7b8e5454fe53037d (patch)
tree6199c393a2b992ed2e147caa811c873226a24d2a
parentce8a069eb57e20b62170faf1127228724ff2cdf0 (diff)
Fixed CanAdd() to use safe iteration and make SNLine::Check really work
(cherry picked from commit 1bdadde68aed5a93225a5a625484505f1126a8a9)
-rw-r--r--include/operserv.h2
-rw-r--r--src/operserv.cpp30
2 files changed, 29 insertions, 3 deletions
diff --git a/include/operserv.h b/include/operserv.h
index 79d907c33..f40815a45 100644
--- a/include/operserv.h
+++ b/include/operserv.h
@@ -215,6 +215,8 @@ class SNLineManager : public XLineManager
void OnExpire(XLine *x);
void Send(XLine *x);
+
+ XLine *Check(User *u);
};
class SQLineManager : public XLineManager
diff --git a/src/operserv.cpp b/src/operserv.cpp
index 3e1f6b7bd..610d24e61 100644
--- a/src/operserv.cpp
+++ b/src/operserv.cpp
@@ -364,9 +364,9 @@ std::pair<int, XLine *> XLineManager::CanAdd(const Anope::string &mask, time_t e
ret.first = 0;
ret.second = NULL;
- for (unsigned i = 0, end = this->GetCount(); i < end; ++i)
+ for (unsigned i = this->GetCount(); i > 0; --i)
{
- XLine *x = this->GetEntry(i);
+ XLine *x = this->GetEntry(i - 1);
ret.second = x;
if (x->Mask.equals_ci(mask))
@@ -392,7 +392,6 @@ std::pair<int, XLine *> XLineManager::CanAdd(const Anope::string &mask, time_t e
else if (Anope::Match(x->Mask, mask) && (!expires || x->Expires <= expires))
{
this->DelXLine(x);
- --i;
}
}
@@ -636,6 +635,31 @@ void SNLineManager::Send(XLine *x)
ircdproto->SendSGLine(x);
}
+XLine *SNLineManager::Check(User *u)
+{
+ for (unsigned i = this->XLines.size(); i > 0; --i)
+ {
+ XLine *x = this->XLines[i - 1];
+
+ if (x->Expires && x->Expires < Anope::CurTime)
+ {
+ this->OnExpire(x);
+ this->Del(x);
+ delete x;
+ this->XLines.erase(XLines.begin() + i - 1);
+ continue;
+ }
+
+ if (Anope::Match(u->realname, x->Mask))
+ {
+ this->OnMatch(u, x);
+ return x;
+ }
+ }
+
+ return NULL;
+}
+
XLine *SQLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason)
{
if (mask.find_first_not_of("*") == Anope::string::npos)