diff options
author | Adam <Adam@anope.org> | 2017-04-06 12:22:52 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2017-04-06 12:22:52 -0400 |
commit | 72bb1b14d372fa6065af77e8b98e8aab5295fe23 (patch) | |
tree | d0e426a88a64b67ba832fcd4648ec1d6f198fc42 /modules | |
parent | 7f5cb607af73a4134a158a14006bdc3e202d0a34 (diff) |
Fix access comparison operators
Diffstat (limited to 'modules')
-rw-r--r-- | modules/chanserv/access.cpp | 22 | ||||
-rw-r--r-- | modules/chanserv/main/chanaccess.cpp | 20 |
2 files changed, 31 insertions, 11 deletions
diff --git a/modules/chanserv/access.cpp b/modules/chanserv/access.cpp index a29524a73..8342e5973 100644 --- a/modules/chanserv/access.cpp +++ b/modules/chanserv/access.cpp @@ -60,20 +60,20 @@ class AccessChanAccessImpl : public AccessChanAccess } } - bool operator>(ChanServ::ChanAccess &other) override + int Compare(ChanAccess *other) override { - if (this->GetSerializableType() != other.GetSerializableType()) - return ChanServ::ChanAccess::operator>(other); - else - return this->GetLevel() > anope_dynamic_static_cast<AccessChanAccess *>(&other)->GetLevel(); - } + if (this->GetSerializableType() != other->GetSerializableType()) + return ChanAccess::Compare(other); - bool operator<(ChanServ::ChanAccess &other) override - { - if (this->GetSerializableType() != other.GetSerializableType()) - return ChanAccess::operator<(other); + int lev = this->GetLevel(); + int theirlev = anope_dynamic_static_cast<AccessChanAccess *>(other)->GetLevel(); + + if (lev > theirlev) + return 1; + else if (lev < theirlev) + return -1; else - return this->GetLevel() < anope_dynamic_static_cast<AccessChanAccess *>(&other)->GetLevel(); + return 0; } }; diff --git a/modules/chanserv/main/chanaccess.cpp b/modules/chanserv/main/chanaccess.cpp index f2b170989..bc2778bc3 100644 --- a/modules/chanserv/main/chanaccess.cpp +++ b/modules/chanserv/main/chanaccess.cpp @@ -110,3 +110,23 @@ bool ChanAccessImpl::Matches(const User *u, NickServ::Account *acc) return false; } + +int ChanAccessImpl::Compare(ChanAccess *other) +{ + const std::vector<ChanServ::Privilege> &privs = ChanServ::service->GetPrivileges(); + for (unsigned int i = privs.size(); i > 0; --i) + { + bool this_p = this->HasPriv(privs[i - 1].name), + other_p = other->HasPriv(privs[i - 1].name); + + if (!this_p && !other_p) + continue; + + if (this_p && !other_p) + return 1; + else if (!this_p && other_p) + return -1; + } + + return 0; +} |