diff options
author | Adam <Adam@anope.org> | 2012-02-22 18:12:02 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-02-22 18:12:02 -0500 |
commit | 3850b073ddf610415de54dced9ff134397779676 (patch) | |
tree | c1a464fba432a7a79535fac4c05cc46f8f19901e /modules/pseudoclients/operserv.cpp | |
parent | 81e50dd1f404c9bad008fe1b569dad134df91125 (diff) |
Added regex support for many commands, such as akill, sqline, snline,
all of the */list commands, etc.
Also extended the ability of akill to match a full nick!user@host and
real name of users.
Diffstat (limited to 'modules/pseudoclients/operserv.cpp')
-rw-r--r-- | modules/pseudoclients/operserv.cpp | 99 |
1 files changed, 58 insertions, 41 deletions
diff --git a/modules/pseudoclients/operserv.cpp b/modules/pseudoclients/operserv.cpp index aeaa7e3c7..0224547eb 100644 --- a/modules/pseudoclients/operserv.cpp +++ b/modules/pseudoclients/operserv.cpp @@ -22,9 +22,9 @@ class SGLineManager : public XLineManager void OnMatch(User *u, XLine *x) anope_override { + this->Send(u, x); if (u) u->Kill(Config->OperServ, x->Reason); - this->Send(u, x); } void OnExpire(XLine *x) anope_override @@ -34,6 +34,11 @@ class SGLineManager : public XLineManager void Send(User *u, XLine *x) anope_override { + ircdproto->SendAkill(u, x); + } + + void SendDel(XLine *x) anope_override + { try { if (!ircd->szline) @@ -41,29 +46,50 @@ class SGLineManager : public XLineManager else if (x->GetUser() != "*") throw SocketException("Can not ZLine a username"); sockaddrs(x->GetHost()); - ircdproto->SendSZLine(u, x); + ircdproto->SendSZLineDel(x); } catch (const SocketException &) { - ircdproto->SendAkill(u, x); + ircdproto->SendAkillDel(x); } } - void SendDel(XLine *x) anope_override + bool Check(User *u, XLine *x) anope_override { - try + if (x->regex) { - if (!ircd->szline) - throw SocketException("SZLine is not supported"); - else if (x->GetUser() != "*") - throw SocketException("Can not ZLine a username"); - sockaddrs(x->GetHost()); - ircdproto->SendSZLineDel(x); + Anope::string uh = u->GetIdent() + "@" + u->host, nuhr = u->nick + "!" + uh + "#" + u->realname; + if (x->regex->Matches(uh) || x->regex->Matches(nuhr)) + return true; + + return false; } - catch (const SocketException &) + + if (!x->GetNick().empty() && !Anope::Match(u->nick, x->GetNick())) + return false; + + if (!x->GetUser().empty() && !Anope::Match(u->GetIdent(), x->GetUser())) + return false; + + if (!x->GetReal().empty() && !Anope::Match(u->realname, x->GetReal())) + return false; + + if (!x->GetHost().empty()) { - ircdproto->SendAkillDel(x); + try + { + cidr cidr_ip(x->GetHost()); + sockaddrs ip(u->ip); + if (cidr_ip.match(ip)) + return true; + } + catch (const SocketException &) { } } + + if (x->GetHost().empty() || Anope::Match(u->host, x->GetHost())) + return true; + + return false; } }; @@ -74,13 +100,13 @@ class SQLineManager : public XLineManager void OnMatch(User *u, XLine *x) anope_override { + this->Send(u, x); + if (u) { Anope::string reason = "Q-Lined: " + x->Reason; u->Kill(Config->OperServ, reason); } - - this->Send(u, x); } void OnExpire(XLine *x) anope_override @@ -98,12 +124,18 @@ class SQLineManager : public XLineManager ircdproto->SendSQLineDel(x); } + bool Check(User *u, XLine *x) anope_override + { + if (x->regex) + return x->regex->Matches(u->nick); + return Anope::Match(u->nick, x->Mask); + } + bool CheckChannel(Channel *c) { - if (ircd->chansqline) - for (std::vector<XLine *>::const_iterator it = this->GetList().begin(), it_end = this->GetList().end(); it != it_end; ++it) - if (Anope::Match(c->name, (*it)->Mask)) - return true; + for (std::vector<XLine *>::const_iterator it = this->GetList().begin(), it_end = this->GetList().end(); it != it_end; ++it) + if (Anope::Match(c->name, (*it)->Mask, false, true)) + return true; return false; } }; @@ -115,12 +147,13 @@ class SNLineManager : public XLineManager void OnMatch(User *u, XLine *x) anope_override { + this->Send(u, x); + if (u) { Anope::string reason = "G-Lined: " + x->Reason; u->Kill(Config->OperServ, reason); } - this->Send(u, x); } void OnExpire(XLine *x) anope_override @@ -138,27 +171,11 @@ class SNLineManager : public XLineManager ircdproto->SendSGLineDel(x); } - XLine *Check(User *u) anope_override + bool Check(User *u, XLine *x) anope_override { - for (unsigned i = this->GetList().size(); i > 0; --i) - { - XLine *x = this->GetList()[i - 1]; - - if (x->Expires && x->Expires < Anope::CurTime) - { - this->OnExpire(x); - this->DelXLine(x); - continue; - } - - if (Anope::Match(u->realname, x->Mask)) - { - this->OnMatch(u, x); - return x; - } - } - - return NULL; + if (x->regex) + return x->regex->Matches(u->realname); + return Anope::Match(u->realname, x->Mask, false, true); } }; @@ -237,7 +254,7 @@ class OperServCore : public Module void OnUserNickChange(User *u, const Anope::string &oldnick) anope_override { if (ircd->sqline && !u->HasMode(UMODE_OPER)) - this->sqlines.Check(u); + this->sqlines.CheckAllXLines(u); } EventReturn OnCheckKick(User *u, ChannelInfo *ci, bool &kick) anope_override |