summaryrefslogtreecommitdiff
path: root/src/resources/db
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-07-19 20:29:11 +0300
committerAndrei Karas <akaras@inbox.ru>2017-07-19 23:09:35 +0300
commit72dfb51de2bb766d291d2d3134e3f34b679281c7 (patch)
tree07862ac1ef107c4dd774e6844ac6c0550d138e09 /src/resources/db
parent105ac47764066fc05093090ac74694715dd89c50 (diff)
downloadmanaverse-72dfb51de2bb766d291d2d3134e3f34b679281c7.tar.gz
manaverse-72dfb51de2bb766d291d2d3134e3f34b679281c7.tar.bz2
manaverse-72dfb51de2bb766d291d2d3134e3f34b679281c7.tar.xz
manaverse-72dfb51de2bb766d291d2d3134e3f34b679281c7.zip
Add support for loading permissions from groups.xml
Diffstat (limited to 'src/resources/db')
-rw-r--r--src/resources/db/groupdb.cpp72
1 files changed, 69 insertions, 3 deletions
diff --git a/src/resources/db/groupdb.cpp b/src/resources/db/groupdb.cpp
index d75a5f29d..b2e1ca011 100644
--- a/src/resources/db/groupdb.cpp
+++ b/src/resources/db/groupdb.cpp
@@ -60,8 +60,8 @@ void GroupDb::load()
return ServerCommandType::name1; \
else
-static ServerCommandTypeT parseName(const std::string &str,
- const int id)
+static ServerCommandTypeT parseCommand(const std::string &str,
+ const int id)
{
#include "resources/servercommands.inc"
{
@@ -77,6 +77,33 @@ static ServerCommandTypeT parseName(const std::string &str,
#undef servercommand
#undef servercommand2
+#define serverpermissionFirst(name) \
+ if (str == #name) \
+ return ServerPermissionType::name; \
+ else
+#define serverpermission(name) \
+ if (str == #name) \
+ return ServerPermissionType::name; \
+ else
+
+static ServerPermissionTypeT parsePermission(const std::string &str,
+ const int id)
+{
+#include "resources/serverpermissions.inc"
+ {
+ reportAlways("GroupsDb: unknown permission name: "
+ "'%s' in group id '%d'.",
+ str.c_str(),
+ id);
+ }
+
+ return ServerPermissionType::Max;
+}
+
+SERVERPERMISSION_VOID
+#undef serverpermissionFirst
+#undef serverpermission
+
static ServerCommandEnable::Type parseUseFlag(const std::string &str,
const int id)
{
@@ -92,6 +119,10 @@ static ServerCommandEnable::Type parseUseFlag(const std::string &str,
{
return ServerCommandEnable::Both;
}
+ else if (str == "false")
+ {
+ return ServerCommandEnable::No;
+ }
else
{
reportAlways("GroupsDb: unknown use flag: '%s' in group id '%d'."
@@ -119,7 +150,7 @@ static void loadCommands(XmlNodePtr rootNode,
const std::string useStr = XML::getProperty(node,
"use",
"");
- ServerCommandTypeT name = parseName(nameStr, id);
+ ServerCommandTypeT name = parseCommand(nameStr, id);
if (name == ServerCommandType::Max)
continue;
ServerCommandEnable::Type useFlag = parseUseFlag(useStr, id);
@@ -130,6 +161,34 @@ static void loadCommands(XmlNodePtr rootNode,
}
}
+static void loadPermissions(XmlNodePtr rootNode,
+ const int id,
+ GroupInfo *groupInfo) A_NONNULL(3);
+static void loadPermissions(XmlNodePtr rootNode,
+ const int id,
+ GroupInfo *groupInfo)
+{
+ for_each_xml_child_node(node, rootNode)
+ {
+ if (xmlNameEqual(node, "permission"))
+ {
+ const std::string nameStr = XML::getProperty(node,
+ "name",
+ "");
+ ServerPermissionTypeT perm = parsePermission(nameStr, id);
+ if (perm == ServerPermissionType::Max)
+ continue;
+ if (!XML::getBoolProperty(node,
+ "enable",
+ true))
+ {
+ continue;
+ }
+ groupInfo->mPermissions[CAST_SIZE(perm)] = Enable_true;
+ }
+ }
+}
+
static void loadSubNodes(XmlNodePtr groupNode,
const int id,
GroupInfo *groupInfo) A_NONNULL(3);
@@ -141,6 +200,8 @@ static void loadSubNodes(XmlNodePtr groupNode,
{
if (xmlNameEqual(node, "commands"))
loadCommands(node, id, groupInfo);
+ if (xmlNameEqual(node, "permissions"))
+ loadPermissions(node, id, groupInfo);
}
}
@@ -174,6 +235,11 @@ static void parseInherit(XmlNodePtr groupNode,
if (enable != ServerCommandEnable::No)
groupInfo->mCommands[f] = enable;
}
+ for (size_t f = 0; f < CAST_SIZE(ServerPermissionType::Max); f ++)
+ {
+ if (groupInfo2->mPermissions[f] == Enable_true)
+ groupInfo->mPermissions[f] = Enable_true;
+ }
}
}