diff options
author | Adam <Adam@anope.org> | 2011-08-28 15:46:15 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-09-10 02:05:00 -0400 |
commit | 700a585b1bb38a9dc0ac3e749083250d405488f8 (patch) | |
tree | 8af306bd60778815fe5a137590d3b888213ad231 /modules/database/db_mysql.cpp | |
parent | 62752db4c49a8679b51d5996003fd3a23c2a3f2d (diff) |
Allow modules to add their own channel levels
Diffstat (limited to 'modules/database/db_mysql.cpp')
-rw-r--r-- | modules/database/db_mysql.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/modules/database/db_mysql.cpp b/modules/database/db_mysql.cpp index a90276274..163bb5a44 100644 --- a/modules/database/db_mysql.cpp +++ b/modules/database/db_mysql.cpp @@ -482,7 +482,7 @@ class DBMySQL : public Module continue; } - ci->levels[atoi(r.Get(i, "position").c_str())] = atoi(r.Get(i, "level").c_str()); + ci->SetLevel(r.Get(i, "name"), atoi(r.Get(i, "level").c_str())); } query = "SELECT * FROM `anope_cs_info_metadata`"; @@ -792,7 +792,7 @@ class DBMySQL : public Module ChannelInfo *ci = cs_findchan(params[0]); if (!ci) return; - if (!ci->AccessFor(u).HasPriv(CA_SET) && !u->HasPriv("botserv/administration")) + if (!ci->AccessFor(u).HasPriv("SET") && !u->HasPriv("botserv/administration")) return; if (params[1].equals_ci("BADWORDS") || params[1].equals_ci("BOLDS") || params[1].equals_ci("CAPS") || params[1].equals_ci("COLORS") || params[1].equals_ci("FLOOD") || params[1].equals_ci("REPEAT") || params[1].equals_ci("REVERSES") || params[1].equals_ci("UNDERLINES")) { @@ -843,7 +843,7 @@ class DBMySQL : public Module else if (command->name == "botserv/set" && params.size() > 1) { ChannelInfo *ci = cs_findchan(params[0]); - if (ci && !ci->AccessFor(u).HasPriv(CA_SET) && !u->HasPriv("botserv/administration")) + if (ci && !ci->AccessFor(u).HasPriv("SET") && !u->HasPriv("botserv/administration")) return; BotInfo *bi = NULL; if (!ci) @@ -880,7 +880,7 @@ class DBMySQL : public Module else { ci = cs_findchan(target); - if (!ci || !ci->AccessFor(u).HasPriv(CA_MEMO)) + if (!ci || !ci->AccessFor(u).HasPriv("MEMO")) return; } @@ -1029,27 +1029,27 @@ class DBMySQL : public Module this->RunQuery(query); } - void OnLevelChange(User *u, ChannelInfo *ci, int pos, int what) + void OnLevelChange(User *u, ChannelInfo *ci, const Anope::string &priv, int16 what) { - if (pos >= 0) - { - SQLQuery query("UPDATE `anope_cs_levels` SET `level` = @level WHERE `channel` = @channel AND `position` = @pos"); - query.setValue("level", what); - query.setValue("channel", ci->name); - query.setValue("pos", pos); - this->RunQuery(query); - } - else + SQLQuery query("UPDATE `anope_cs_levels` SET `level` = @level WHERE `channel` = @channel AND `name` = @name ON DUPLICATE KEY UPDATE level=VALUES(level), name=VALUES(name)"); + query.setValue("channel", ci->name); + if (priv == "ALL") { - SQLQuery query("INSERT INTO `anope_cs_levels` (level, channel, position) VALUES(@level, @channel, @pos) ON DUPLICATE KEY UPDATE level=VALUES(level), channel=VALUES(channel), position=VALUES(position)"); - query.setValue("channel", ci->name); - for (int i = 0; i < CA_SIZE; ++i) + const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); + for (unsigned i = 0; i < privs.size(); ++i) { - query.setValue("level", ci->levels[i]); - query.setValue("pos", i); + const Privilege &p = privs[i]; + query.setValue("level", ci->GetLevel(p.name)); + query.setValue("name", p.name); this->RunQuery(query); } } + else + { + query.setValue("level", what); + query.setValue("name", name); + this->RunQuery(query); + } } void OnChanForbidden(ChannelInfo *ci) @@ -1538,7 +1538,11 @@ static void SaveDatabases() me->OnAkickAdd(ci, ak); } +<<<<<<< HEAD me->OnLevelChange(NULL, ci, -1, -1); +======= + me->OnLevelChange(NULL, ci, "ALL", -1); +>>>>>>> 348a3db... Allow modules to add their own channel levels for (unsigned j = 0, end = ci->memos.memos.size(); j < end; ++j) { |