summaryrefslogtreecommitdiff
path: root/src/resources/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources/db')
-rw-r--r--src/resources/db/groupdb.cpp30
-rw-r--r--src/resources/db/groupdb.h3
2 files changed, 33 insertions, 0 deletions
diff --git a/src/resources/db/groupdb.cpp b/src/resources/db/groupdb.cpp
index 1d1d1bffa..d8dc1117f 100644
--- a/src/resources/db/groupdb.cpp
+++ b/src/resources/db/groupdb.cpp
@@ -22,6 +22,10 @@
#include "configuration.h"
+#include "being/localplayer.h"
+
+#include "net/net.h"
+
#include "utils/checkutils.h"
#include "resources/beingcommon.h"
@@ -400,6 +404,32 @@ const GroupInfo *GroupDb::getGroup(const int id)
return (*it).second;
}
+bool GroupDb::isAllowCommand(const ServerCommandTypeT command)
+{
+ const int groupId = localPlayer->getGroupId();
+ const GroupInfo *const group = GroupDb::getGroup(groupId);
+ if (group == nullptr)
+ return false;
+
+#ifdef TMWA_SUPPORT
+ // allow any commands for legacy if group > 0
+ if (Net::getNetworkType() == ServerType::TMWATHENA &&
+ localPlayer != nullptr &&
+ localPlayer->isGM())
+ {
+ return true;
+ }
+#endif
+ if (group->mPermissions[CAST_SIZE(ServerPermissionType::all_commands)] ==
+ Enable_true)
+ {
+ return true;
+ }
+ const ServerCommandEnable::Type enabled =
+ group->mCommands[CAST_SIZE(command)];
+ return (enabled & ServerCommandEnable::Self) != 0;
+}
+
#ifdef UNITTESTS
GroupDb::GroupInfos &GroupDb::getGroups()
{
diff --git a/src/resources/db/groupdb.h b/src/resources/db/groupdb.h
index f447baa96..19a186911 100644
--- a/src/resources/db/groupdb.h
+++ b/src/resources/db/groupdb.h
@@ -21,6 +21,8 @@
#ifndef RESOURCES_DB_GROUPDB_H
#define RESOURCES_DB_GROUPDB_H
+#include "enums/resources/servercommandtype.h"
+
#include "enums/simpletypes/skiperror.h"
#include <map>
@@ -44,6 +46,7 @@ namespace GroupDb
bool getHighlightName(const int id) A_WARN_UNUSED;
const std::string &getBadge(const int id) A_WARN_UNUSED;
const GroupInfo *getGroup(const int id) A_WARN_UNUSED RETURNS_NONNULL;
+ bool isAllowCommand(const ServerCommandTypeT command);
typedef std::map<int, GroupInfo*> GroupInfos;
typedef GroupInfos::iterator GroupInfosIter;