diff options
author | Adam <Adam@anope.org> | 2011-12-15 01:14:13 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-12-15 01:14:13 -0500 |
commit | 9ea030d0600624095204af192e99c16e2d78a42e (patch) | |
tree | 403d8c07c4788f8921955d164bbc07b473cfd3be | |
parent | ad14c8145b8090aee0f4946b3b503786b6f8d1fb (diff) |
Fixed access comparators
-rw-r--r-- | include/access.h | 10 | ||||
-rw-r--r-- | modules/commands/cs_access.cpp | 2 | ||||
-rw-r--r-- | modules/commands/cs_flags.cpp | 2 | ||||
-rw-r--r-- | modules/commands/cs_xop.cpp | 2 | ||||
-rw-r--r-- | src/access.cpp | 88 |
5 files changed, 80 insertions, 24 deletions
diff --git a/include/access.h b/include/access.h index b993ee0d8..b0567b73f 100644 --- a/include/access.h +++ b/include/access.h @@ -55,14 +55,14 @@ class CoreExport ChanAccess : public Serializable static void unserialize(serialized_data &); virtual bool Matches(User *u, NickCore *nc) = 0; - virtual bool HasPriv(const Anope::string &name) = 0; + virtual bool HasPriv(const Anope::string &name) const = 0; virtual Anope::string Serialize() = 0; virtual void Unserialize(const Anope::string &data) = 0; - bool operator>(ChanAccess &other); - bool operator<(ChanAccess &other); - bool operator>=(ChanAccess &other); - bool operator<=(ChanAccess &other); + bool operator>(const ChanAccess &other) const; + bool operator<(const ChanAccess &other) const; + bool operator>=(const ChanAccess &other) const; + bool operator<=(const ChanAccess &other) const; }; class CoreExport AccessGroup : public std::vector<ChanAccess *> diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index bda726276..68a367701 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -40,7 +40,7 @@ class AccessChanAccess : public ChanAccess return false; } - bool HasPriv(const Anope::string &name) + bool HasPriv(const Anope::string &name) const { return this->ci->GetLevel(name) != ACCESS_INVALID && this->level >= this->ci->GetLevel(name); } diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp index e81589968..3003855e7 100644 --- a/modules/commands/cs_flags.cpp +++ b/modules/commands/cs_flags.cpp @@ -33,7 +33,7 @@ class FlagsChanAccess : public ChanAccess return false; } - bool HasPriv(const Anope::string &priv) + bool HasPriv(const Anope::string &priv) const { std::map<Anope::string, char>::iterator it = defaultFlags.find(priv); if (it != defaultFlags.end() && this->flags.count(it->second) > 0) diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp index 9279688a6..cbbd2a615 100644 --- a/modules/commands/cs_xop.cpp +++ b/modules/commands/cs_xop.cpp @@ -108,7 +108,7 @@ class XOPChanAccess : public ChanAccess return false; } - bool HasPriv(const Anope::string &priv) + bool HasPriv(const Anope::string &priv) const { for (int i = 0; xopAccess[i].type != XOP_UNKNOWN; ++i) { diff --git a/src/access.cpp b/src/access.cpp index 7b15f335a..622150d16 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -112,25 +112,45 @@ void ChanAccess::unserialize(serialized_data &data) ci->AddAccess(access); } -bool ChanAccess::operator>(ChanAccess &other) +bool ChanAccess::operator>(const ChanAccess &other) const { const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) - if (this->HasPriv(privs[i - 1].name) && !other.HasPriv(privs[i - 1].name)) + { + bool this_p = this->HasPriv(privs[i - 1].name), + other_p = other.HasPriv(privs[i - 1].name); + + if (!this_p && !other_p) + continue; + else if (this_p && !other_p) return true; + else + return false; + } + return false; } -bool ChanAccess::operator<(ChanAccess &other) +bool ChanAccess::operator<(const ChanAccess &other) const { const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) - if (!this->HasPriv(privs[i - 1].name) && other.HasPriv(privs[i - 1].name)) + { + bool this_p = this->HasPriv(privs[i - 1].name), + other_p = other.HasPriv(privs[i - 1].name); + + if (!this_p && !other_p) + continue; + else if (!this_p && other_p) return true; + else + return false; + } + return false; } -bool ChanAccess::operator>=(ChanAccess &other) +bool ChanAccess::operator>=(const ChanAccess &other) const { const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) @@ -138,14 +158,18 @@ bool ChanAccess::operator>=(ChanAccess &other) bool this_p = this->HasPriv(privs[i - 1].name), other_p = other.HasPriv(privs[i - 1].name); - if ((this_p && !other_p) || (this_p && other_p)) + if (!this_p && !other_p) + continue; + else if (!this_p && other_p) + return false; + else return true; } - return false; + return true; } -bool ChanAccess::operator<=(ChanAccess &other) +bool ChanAccess::operator<=(const ChanAccess &other) const { const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) @@ -153,11 +177,15 @@ bool ChanAccess::operator<=(ChanAccess &other) bool this_p = this->HasPriv(privs[i - 1].name), other_p = other.HasPriv(privs[i - 1].name); - if ((!this_p && other_p) || (this_p && other_p)) + if (!this_p && !other_p) + continue; + else if (this_p && !other_p) + return false; + else return true; } - return false; + return true; } AccessGroup::AccessGroup() : std::vector<ChanAccess *>() @@ -211,8 +239,18 @@ bool AccessGroup::operator>(const AccessGroup &other) const return false; const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) - if (this->HasPriv(privs[i - 1].name) && !other.HasPriv(privs[i - 1].name)) + { + bool this_p = this->HasPriv(privs[i - 1].name), + other_p = other.HasPriv(privs[i - 1].name); + + if (!this_p && !other_p) + continue; + else if (this_p && !other_p) return true; + else + return false; + } + return false; } @@ -228,8 +266,18 @@ bool AccessGroup::operator<(const AccessGroup &other) const return false; const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) - if (!this->HasPriv(privs[i - 1].name) && other.HasPriv(privs[i - 1].name)) + { + bool this_p = this->HasPriv(privs[i - 1].name), + other_p = other.HasPriv(privs[i - 1].name); + + if (!this_p && !other_p) + continue; + else if (!this_p && other_p) return true; + else + return false; + } + return false; } @@ -249,11 +297,15 @@ bool AccessGroup::operator>=(const AccessGroup &other) const bool this_p = this->HasPriv(privs[i - 1].name), other_p = other.HasPriv(privs[i - 1].name); - if ((this_p && !other_p) || (this_p && other_p)) + if (!this_p && !other_p) + continue; + else if (other_p && !this_p) + return false; + else return true; } - return false; + return true; } bool AccessGroup::operator<=(const AccessGroup &other) const @@ -272,10 +324,14 @@ bool AccessGroup::operator<=(const AccessGroup &other) const bool this_p = this->HasPriv(privs[i - 1].name), other_p = other.HasPriv(privs[i - 1].name); - if ((!this_p && other_p) || (this_p && other_p)) + if (!this_p && !other_p) + continue; + else if (this_p && !other_p) + return false; + else return true; } - return false; + return true; } |