summaryrefslogtreecommitdiff
path: root/modules/database
diff options
context:
space:
mode:
Diffstat (limited to 'modules/database')
-rw-r--r--modules/database/db_mysql.cpp42
-rw-r--r--modules/database/db_plain.cpp65
2 files changed, 36 insertions, 71 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)
{
diff --git a/modules/database/db_plain.cpp b/modules/database/db_plain.cpp
index 340775e0c..83098ced9 100644
--- a/modules/database/db_plain.cpp
+++ b/modules/database/db_plain.cpp
@@ -179,52 +179,6 @@ static void ReadDatabase(Module *m = NULL)
db.close();
}
-struct ChannelLevel
-{
- ChannelAccess Level;
- Anope::string Name;
-};
-
-ChannelLevel ChannelLevels[] = {
- { CA_ACCESS_LIST, "ACCESS_LIST" },
- { CA_NOKICK, "NOKICK" },
- { CA_FANTASIA, "FANTASIA" },
- { CA_GREET, "GREET" },
- { CA_AUTOVOICE, "AUTOVOICE" },
- { CA_VOICEME, "VOICEME" },
- { CA_VOICE, "VOICE" },
- { CA_INFO, "INFO" },
- { CA_SAY, "SAY" },
- { CA_AUTOHALFOP, "AUTOHALFOP" },
- { CA_HALFOPME, "HALFOPME" },
- { CA_HALFOP, "HALFOP" },
- { CA_KICK, "KICK" },
- { CA_SIGNKICK, "SIGNKICK" },
- { CA_BAN, "BAN" },
- { CA_TOPIC, "TOPIC" },
- { CA_MODE, "MODE" },
- { CA_GETKEY, "GETKEY" },
- { CA_INVITE, "INVITE" },
- { CA_UNBAN, "UNBAN" },
- { CA_AUTOOP, "AUTOOP" },
- { CA_OPDEOPME, "OPDEOPME" },
- { CA_OPDEOP, "OPDEOP" },
- { CA_AUTOPROTECT, "AUTOPROTECT" },
- { CA_AKICK, "AKICK" },
- { CA_BADWORDS, "BADWORDS" },
- { CA_ASSIGN, "ASSIGN" },
- { CA_MEMO, "MEMO" },
- { CA_ACCESS_CHANGE, "ACCESS_CHANGE" },
- { CA_PROTECTME, "PROTECTME" },
- { CA_PROTECT, "PROTECT" },
- { CA_SET, "SET" },
- { CA_AUTOOWNER, "AUTOOWNER" },
- { CA_OWNERME, "OWNERME" },
- { CA_OWNER, "OWNER" },
- { CA_FOUNDER, "FOUNDER" },
- { CA_SIZE, "" }
-};
-
static Anope::string ToString(const std::vector<Anope::string> &strings)
{
Anope::string ret;
@@ -532,9 +486,12 @@ class DBPlain : public Module
else if (key.equals_ci("LEVELS"))
{
for (unsigned j = 0, end = params.size(); j < end; j += 2)
- for (int i = 0; ChannelLevels[i].Level != CA_SIZE; ++i)
- if (params[j].equals_ci(ChannelLevels[i].Name))
- ci->levels[ChannelLevels[i].Level] = params[j + 1].is_number_only() ? convertTo<int16>(params[j + 1]) : 0;
+ {
+ Privilege *p = PrivilegeManager::FindPrivilege(params[j]);
+ if (p == NULL)
+ continue;
+ ci->SetLevel(p->name, params[j + 1].is_number_only() ? convertTo<int16>(params[j + 1]) : 0);
+ }
}
else if (key.equals_ci("FLAGS"))
ci->FromString(params);
@@ -555,7 +512,7 @@ class DBPlain : public Module
{
service_reference<AccessProvider> provider("access/access");
if (!provider)
- throw DatabaseException("Access entry for nonexistant provider " + params[0]);
+ throw DatabaseException("Old access entry for nonexistant provider");
ChanAccess *access = provider->Create();
access->ci = ci;
@@ -799,8 +756,12 @@ class DBPlain : public Module
if (!ci->last_topic.empty())
db_buffer << "MD TOPIC " << ci->last_topic_setter << " " << ci->last_topic_time << " :" << ci->last_topic << endl;
db_buffer << "MD LEVELS";
- for (int j = 0; ChannelLevels[j].Level != CA_SIZE; ++j)
- db_buffer << " " << ChannelLevels[j].Name << " " << ci->levels[ChannelLevels[j].Level];
+ const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
+ for (unsigned i = 0; i < privs.size(); ++i)
+ {
+ const Privilege &p = privs[i];
+ db_buffer << p.name << " " << ci->GetLevel(p.name);
+ }
db_buffer << endl;
if (ci->FlagCount())
db_buffer << "MD FLAGS " << ToString(ci->ToString()) << endl;