mirror of
https://github.com/anope/anope.git
synced 2026-06-27 20:26:38 +02:00
Added os_forbid
This commit is contained in:
@@ -17,6 +17,77 @@
|
||||
|
||||
static service_reference<SessionService> sessionservice("session");
|
||||
|
||||
class MySessionService : public SessionService
|
||||
{
|
||||
SessionMap Sessions;
|
||||
ExceptionVector Exceptions;
|
||||
public:
|
||||
MySessionService(Module *m) : SessionService(m) { }
|
||||
|
||||
void AddException(Exception *e)
|
||||
{
|
||||
this->Exceptions.push_back(e);
|
||||
}
|
||||
|
||||
void DelException(Exception *e)
|
||||
{
|
||||
ExceptionVector::iterator it = std::find(this->Exceptions.begin(), this->Exceptions.end(), e);
|
||||
if (it != this->Exceptions.end())
|
||||
this->Exceptions.erase(it);
|
||||
}
|
||||
|
||||
Exception *FindException(User *u)
|
||||
{
|
||||
for (std::vector<Exception *>::const_iterator it = this->Exceptions.begin(), it_end = this->Exceptions.end(); it != it_end; ++it)
|
||||
{
|
||||
Exception *e = *it;
|
||||
if (Anope::Match(u->host, e->mask) || (u->ip() && Anope::Match(u->ip.addr(), e->mask)))
|
||||
return e;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Exception *FindException(const Anope::string &host)
|
||||
{
|
||||
for (std::vector<Exception *>::const_iterator it = this->Exceptions.begin(), it_end = this->Exceptions.end(); it != it_end; ++it)
|
||||
{
|
||||
Exception *e = *it;
|
||||
if (Anope::Match(host, e->mask))
|
||||
return e;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ExceptionVector &GetExceptions()
|
||||
{
|
||||
return this->Exceptions;
|
||||
}
|
||||
|
||||
void AddSession(Session *s)
|
||||
{
|
||||
this->Sessions[s->host] = s;
|
||||
}
|
||||
|
||||
void DelSession(Session *s)
|
||||
{
|
||||
this->Sessions.erase(s->host);
|
||||
}
|
||||
|
||||
Session *FindSession(const Anope::string &mask)
|
||||
{
|
||||
SessionMap::iterator it = this->Sessions.find(mask);
|
||||
if (it != this->Sessions.end())
|
||||
return it->second;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SessionMap &GetSessions()
|
||||
{
|
||||
return this->Sessions;
|
||||
}
|
||||
};
|
||||
|
||||
class ExpireTimer : public Timer
|
||||
{
|
||||
public:
|
||||
@@ -566,14 +637,14 @@ class CommandOSException : public Command
|
||||
|
||||
class OSSession : public Module
|
||||
{
|
||||
SessionService ss;
|
||||
MySessionService ss;
|
||||
ExpireTimer expiretimer;
|
||||
CommandOSSession commandossession;
|
||||
CommandOSException commandosexception;
|
||||
|
||||
void AddSession(User *u, bool exempt)
|
||||
{
|
||||
Session *session = sessionservice->FindSession(u->host);
|
||||
Session *session = this->ss.FindSession(u->host);
|
||||
|
||||
if (session)
|
||||
{
|
||||
@@ -581,7 +652,7 @@ class OSSession : public Module
|
||||
if (Config->DefSessionLimit && session->count >= Config->DefSessionLimit)
|
||||
{
|
||||
kill = true;
|
||||
Exception *exception = sessionservice->FindException(u);
|
||||
Exception *exception = this->ss.FindException(u);
|
||||
if (exception)
|
||||
{
|
||||
kill = false;
|
||||
@@ -625,13 +696,13 @@ class OSSession : public Module
|
||||
session->count = 1;
|
||||
session->hits = 0;
|
||||
|
||||
sessionservice->AddSession(session);
|
||||
this->ss.AddSession(session);
|
||||
}
|
||||
}
|
||||
|
||||
void DelSession(User *u)
|
||||
{
|
||||
Session *session = sessionservice->FindSession(u->host);
|
||||
Session *session = this->ss.FindSession(u->host);
|
||||
if (!session)
|
||||
{
|
||||
if (debug)
|
||||
@@ -645,7 +716,7 @@ class OSSession : public Module
|
||||
return;
|
||||
}
|
||||
|
||||
sessionservice->DelSession(session);
|
||||
this->ss.DelSession(session);
|
||||
delete session;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user