summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/access.cpp20
-rw-r--r--src/config.cpp16
2 files changed, 26 insertions, 10 deletions
diff --git a/src/access.cpp b/src/access.cpp
index 622150d16..26622e6d6 100644
--- a/src/access.cpp
+++ b/src/access.cpp
@@ -12,22 +12,29 @@
#include "services.h"
#include "modules.h"
-Privilege::Privilege(const Anope::string &n, const Anope::string &d) : name(n), desc(d)
+Privilege::Privilege(const Anope::string &n, const Anope::string &d, int r) : name(n), desc(d), rank(r)
{
}
-bool Privilege::operator==(const Privilege &other)
+bool Privilege::operator==(const Privilege &other) const
{
return this->name == other.name;
}
std::vector<Privilege> PrivilegeManager::privs;
-void PrivilegeManager::AddPrivilege(Privilege p, int pos, int def)
+void PrivilegeManager::AddPrivilege(Privilege p)
{
- if (pos < 0 || static_cast<size_t>(pos) > privs.size())
- pos = privs.size();
- privs.insert(privs.begin() + pos, p);
+ unsigned i;
+ for (i = 0; i < privs.size(); ++i)
+ {
+ Privilege &priv = privs[i];
+
+ if (priv.rank > p.rank)
+ break;
+ }
+
+ privs.insert(privs.begin() + i, p);
}
void PrivilegeManager::RemovePrivilege(Privilege &p)
@@ -35,6 +42,7 @@ void PrivilegeManager::RemovePrivilege(Privilege &p)
std::vector<Privilege>::iterator it = std::find(privs.begin(), privs.end(), p);
if (it != privs.end())
privs.erase(it);
+
for (registered_channel_map::const_iterator cit = RegisteredChannelList.begin(), cit_end = RegisteredChannelList.end(); cit != cit_end; ++cit)
cit->second->RemoveLevel(p.name);
}
diff --git a/src/config.cpp b/src/config.cpp
index 2bde3863a..63aaf1bf3 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -884,6 +884,7 @@ static bool DoPrivileges(ServerConfig *config, const Anope::string &, const Anop
{
Anope::string name = values[0].GetValue();
Anope::string desc = values[1].GetValue();
+ Anope::string rank = values[2].GetValue();
ValueItem vi(name);
if (!ValidateNotEmpty(config, "privilege", "name", vi))
@@ -892,8 +893,15 @@ static bool DoPrivileges(ServerConfig *config, const Anope::string &, const Anop
vi = ValueItem(desc);
if (!ValidateNotEmpty(config, "privilege", "desc", vi))
throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information.");
+
+ int irank = 0;
+ try
+ {
+ irank = convertTo<int>(rank);
+ }
+ catch (const ConvertException &) { }
- PrivilegeManager::AddPrivilege(Privilege(name, desc));
+ PrivilegeManager::AddPrivilege(Privilege(name, desc, irank));
return true;
}
@@ -1330,9 +1338,9 @@ ConfigItems::ConfigItems(ServerConfig *conf)
{DT_STRING, DT_STRING, DT_STRING, DT_STRING},
InitCommands, DoCommands, DoneCommands},
{"privilege",
- {"name", "desc", ""},
- {"", "", ""},
- {DT_STRING, DT_STRING, DT_STRING},
+ {"name", "desc", "rank", ""},
+ {"", "", "", ""},
+ {DT_STRING, DT_STRING, DT_STRING, DT_STRING},
InitPrivileges, DoPrivileges, DonePrivileges},
{"",
{""},