Plugins: server plugins know each player's role

A server plugin could not see the roles of a dedicated server (data/roles.json), so a plugin that
wanted only moderators to use some of its commands had to keep its own list of SteamIDs. In a
server copy with the server permission, a player table now has role: a read-only {name, rank,
staff}, the role the player has now (the one given them, or the server's default), read from the
server each time. staff is whether the role gives any of the server's commands. It is nil for a
player with no role, for the server itself and on a lobby's host. Each read counts as a server call.

dingosdk_server_plugin_tests reads a given role, the default role and a role given while the
player is on, and checks the table is read-only and a plugin without server is refused;
dingosdk_plugin_tests checks the API on a server copy, and that a player's copy and a plugin
without server cannot read it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hs7xxJDf6SDcQUaXnzmtL5
This commit is contained in:
Robin MoellerandClaude Opus 5.5 committed 2026-10-23 10:43:34 +02:00
1 parent e35e33d66d
commit 71e3460182
6 files changed
+114 -5

No files matched your search

+7
View File
@@ -80,6 +80,13 @@ class ServerGame final : public Game {
host_.set_locks(player, locks, "plugin " + std::string(plugin));
return {};
}
// The role they have (the one given them, or the server's default role), here or not.
std::optional<Role> role(std::uint64_t player) override {
if (!multiplayer::individual_steam_id(player)) return std::nullopt; // the server itself has none
const auto *held = host_.player_role(player);
if (!held) return std::nullopt;
return Role{held->name, held->rank, server::staff(held)};
}
std::vector<ServerPark> server_parks() override {
std::vector<ServerPark> result;
for (auto &p : host_.park_status()) result.push_back({std::move(p.name), std::move(p.map), p.here, p.spawned, p.objects, p.minutes_left});