Files
DarkflameServer/dCommon/Permissions.h
Aaron Kimbrell e213a7aeff feat: web dashboard and playground work
The NexusDashboard-parity dashboard (dDashboardServer) and everything built on it on the experimental branch:
accounts, characters, properties and moderation tools, permissions shared with in-game slash commands, economy
reports, World 3D and property 3D views with client scenery, scheduled events (features, vanity changes, live
events, announcements, restarts), vanity files and events, the CDClient browser, the message inspector with saved
captures, chat filter tools, community challenges, live ops, the AI moderator helper, and the server-side changes
they need.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:30:43 -05:00

62 lines
2.7 KiB
C++

#pragma once
#include <cstdint>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "json.hpp"
/**
* What each GM level may do on the dashboard, and in the game for the slash commands paired with a permission. Every
* permission has a default minimum GM level; server owners can change it without rebuilding, on the Permissions page
* or with permission_<name>=<level> in dashboardconfig.ini (or the dashboard's PERMISSION_<NAME> environment
* variable). A level set on the page beats the file. Levels are 1-9, and GM 9 can always do everything, so an operator
* can never lock themselves out.
* The dashboard owns these settings. The other servers (the worlds, for their slash commands) read the values the
* dashboard stored in the database (ConfigSync), so every server sees the same levels and picks up changes when its
* settings reload.
*/
namespace Permissions {
constexpr uint8_t MIN_LEVEL = 1; // the lowest level a staff permission can be given to: players (GM 0) never get them
constexpr uint8_t PLAYER_LEVEL = 0; // what players can do (their own characters, leaderboards, the API) can be set this low
constexpr uint8_t MAX_LEVEL = 9;
// The server that owns the permission_* settings, and the file its values are stored under
constexpr std::string_view CONFIG_FILE = "dashboardconfig.ini";
constexpr std::string_view PREFIX = "permission_";
struct Permission {
std::string key; // lower_snake_case; the config setting is permission_<key>
std::string category;
std::string title;
std::string description;
uint8_t defaultLevel;
bool locked{}; // always the default (managing permissions themselves)
uint8_t minLevel{ MIN_LEVEL }; // the lowest level it can be set to: PLAYER_LEVEL for what players do
};
const std::vector<Permission>& All();
const Permission* Find(const std::string& key);
std::string ConfigName(const std::string& key);
inline bool IsPermissionSetting(std::string_view name) {
return name.starts_with(PREFIX);
}
// The minimum GM level for a permission right now; unknown permissions need more than GM 9 (nobody)
uint8_t Level(const std::string& key);
bool Allowed(uint8_t gmLevel, const std::string& key);
// characters_view for anyone's character, or own_characters for the viewer's own (account 0 owns nothing)
bool CanViewCharacter(uint8_t gmLevel, uint32_t viewerAccountId, uint32_t ownerAccountId);
// {key: bool} for every permission, for templates and scripts
nlohmann::json ForLevel(uint8_t gmLevel);
// Pure: the level a config value gives a permission (bad or out-of-range values fall back to the default)
uint8_t Resolve(const Permission& permission, const std::string& configValue);
}