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:37:12 -0500
commit1bdadde68aed5a93225a5a625484505f1126a8a9 (patch)
tree842829f4856e7afd19926eb27f570830d10a6f13
parent39d34f717466875d1f3c0b46c8e99bc9fd2c1532 (diff)
Fixed CanAdd() to use safe iteration and make SNLine::Check really work
-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 20d24ae5d..4f1afb6ec 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 c41e6b1c5..5ab792c92 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;
}
}
@@ -625,6 +624,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)