diff options
-rw-r--r-- | data/chanserv.example.conf | 40 | ||||
-rw-r--r-- | include/access.h | 7 | ||||
-rw-r--r-- | src/access.cpp | 20 | ||||
-rw-r--r-- | src/config.cpp | 16 |
4 files changed, 69 insertions, 14 deletions
diff --git a/data/chanserv.example.conf b/data/chanserv.example.conf index 3ebf2672e..6889c2b29 100644 --- a/data/chanserv.example.conf +++ b/data/chanserv.example.conf @@ -177,7 +177,9 @@ chanserv * ChanServ privilege configuration. * * ChanServ privileges are used to determine who has what access in channels. By default the core has its own - * set of levels it uses for various ChanServ commands, which are defined below. + * set of levels it uses for various ChanServ commands, which are defined below. Privilege ranks are used to + * determine how powerful privileges are relative to each other, which is used by Anope to determine who has greater + * access in a channel. * * If you loaded cs_access, you may define a level for the privilege, which is used by chanserv/access and chanserv/levels. * The levels defined will be used as the default levels for newly registered channels. @@ -203,6 +205,7 @@ privilege { name = "ACCESS_CHANGE" desc = "Allowed to modify the access list" + rank = 290 level = 10 flag = "f" } @@ -218,6 +221,7 @@ privilege { name = "ACCESS_LIST" desc = "Allowed to view the access list" + rank = 10 level = 10 flag = "f" } @@ -233,6 +237,7 @@ privilege { name = "AKICK" desc = "Allowed to use the AKICK command" + rank = 250 level = 10 flag = "K" } @@ -248,6 +253,7 @@ privilege { name = "ASSIGN" desc = "Allowed to assign/unassign a bot" + rank = 270 level = "founder" flag = "s" } @@ -263,6 +269,7 @@ privilege { name = "AUTOHALFOP" desc = "Automatic mode +h" + rank = 100 level = 4 flag = "H" } @@ -278,6 +285,7 @@ privilege { name = "AUTOOP" desc = "Automatic channel operator status" + rank = 210 level = 5 flag = "O" } @@ -293,6 +301,7 @@ privilege { name = "AUTOOWNER" desc = "Automatic mode +q" + rank = 330 level = 9999 flag = "Q" } @@ -308,6 +317,7 @@ privilege { name = "AUTOPROTECT" desc = "Automatic mode +a" + rank = 240 level = 10 flag = "A" } @@ -323,6 +333,7 @@ privilege { name = "AUTOVOICE" desc = "Automatic mode +v" + rank = 50 level = 3 flag = "V" } @@ -338,6 +349,7 @@ privilege { name = "BADWORDS" desc = "Allowed to modify channel badwords list" + rank = 260 level = 10 flag = "K" } @@ -353,6 +365,7 @@ privilege { name = "BAN" desc = "Allowed to use ban users" + rank = 150 level = 4 flag = "b" } @@ -368,6 +381,7 @@ privilege { name = "FANTASIA" desc = "Allowed to use fantasy commands" + rank = 30 level = 3 flag = "c" } @@ -386,6 +400,7 @@ privilege { name = "FOUNDER" desc = "Allowed to issue commands restricted to channel founders" + rank = 360 level = "founder" flag = "F" } @@ -402,6 +417,7 @@ privilege { name = "GETKEY" desc = "Allowed to use GETKEY command" + rank = 180 level = 5 flag = "G" } @@ -417,6 +433,7 @@ privilege { name = "GREET" desc = "Greet message displayede on join" + rank = 40 level = 5 flag = "g" } @@ -433,6 +450,7 @@ privilege { name = "HALFOP" desc = "Allowed to (de)halfop users" + rank = 120 level = 5 flag = "h" } @@ -449,6 +467,7 @@ privilege { name = "HALFOPME" desc = "Allowed to (de)halfop him/herself" + rank = 110 level = 4 flag = "h" } @@ -465,6 +484,7 @@ privilege { name = "INFO" desc = "Allowed to get full INFO output" + rank = 80 level = 9999 flag = "I" } @@ -481,6 +501,7 @@ privilege { name = "INVITE" desc = "Allowed to use the INVITE command" + rank = 190 level = 5 flag = "i" } @@ -496,6 +517,7 @@ privilege { name = "KICK" desc = "Allowed to use the KICK command" + rank = 130 level = 4 flag = "k" } @@ -512,6 +534,7 @@ privilege { name = "MEMO" desc = "Allowed to read channel memos" + rank = 280 level = 10 flag = "m" } @@ -528,6 +551,7 @@ privilege { name = "MODE" desc = "Allowed to use the MODE command" + rank = 170 level = 5 flag = "s" } @@ -543,6 +567,7 @@ privilege { name = "NOKICK" desc = "Prevents users being kicked by Services" + rank = 20 level = 1 flag = "N" } @@ -559,6 +584,7 @@ privilege { name = "OPDEOP" desc = "Allowed to (de)op users" + rank = 230 level = 5 flag = "o" } @@ -575,6 +601,7 @@ privilege { name = "OPDEOPME" desc = "Allowed to (de)op him/herself" + rank = 220 level = 5 flag = "o" } @@ -591,6 +618,7 @@ privilege { name = "OWNER" desc = "Allowed to (de)owner users" + rank = 350 level = "founder" flag = "q" } @@ -607,6 +635,7 @@ privilege { name = "OWNERME" desc = "Allowed to (de)owner him/herself" + rank = 340 level = "9999" flag = "q" } @@ -623,6 +652,7 @@ privilege { name = "PROTECT" desc = "Allowed to (de)protect users" + rank = 310 level = 9999 flag = "a" } @@ -639,6 +669,7 @@ privilege { name = "PROTECTME" desc = "Allowed to (de)protect him/herself" + rank = 300 level = 10 flag = "a" } @@ -655,6 +686,7 @@ privilege { name = "SAY" desc = "Allowed to use SAY and ACT commands" + rank = 90 level = 5 flag = "B" } @@ -673,6 +705,7 @@ privilege { name = "SET" desc = "Allowed to set channel settings" + rank = 320 level = 9999 flag = "s" } @@ -689,6 +722,7 @@ privilege { name = "SIGNKICK" desc = "No signed kick when SIGNKICK LEVEL is used" + rank = 140 level = 9999 flag = "K" } @@ -704,6 +738,7 @@ privilege { name = "TOPIC" desc = "Allowed to change channel topics" + rank = 160 level = 5 flag = "t" } @@ -719,6 +754,7 @@ privilege { name = "UNBAN" desc = "Allowed to unban users" + rank = 200 level = 4 flag = "u" } @@ -735,6 +771,7 @@ privilege { name = "VOICE" desc = "Allowed to (de)voice users" + rank = 70 level = 4 flag = "v" } @@ -751,6 +788,7 @@ privilege { name = "VOICEME" desc = "Allowed to (de)voice him/herself" + rank = 60 level = 3 flag = "v" } diff --git a/include/access.h b/include/access.h index b0567b73f..64e0971c9 100644 --- a/include/access.h +++ b/include/access.h @@ -11,16 +11,17 @@ struct CoreExport Privilege { Anope::string name; Anope::string desc; + int rank; - Privilege(const Anope::string &n, const Anope::string &d); - bool operator==(const Privilege &other); + Privilege(const Anope::string &n, const Anope::string &d, int r); + bool operator==(const Privilege &other) const; }; class CoreExport PrivilegeManager { static std::vector<Privilege> privs; public: - static void AddPrivilege(Privilege p, int pos = -1, int def = 0); + static void AddPrivilege(Privilege p); static void RemovePrivilege(Privilege &p); static Privilege *FindPrivilege(const Anope::string &name); static std::vector<Privilege> &GetPrivileges(); 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}, {"", {""}, |