Move the scenario onto exp_roles and remove the legacy role system

Every call site of expcore.roles now uses exp_roles, and the legacy module,
its config, and the glue which refreshed guis on role events are deleted.
Where a file only renamed the require and the permission strings the change is
mechanical; the rest:

- Jail is now "give the Jail role" and unjail "take it away". The role has a
  higher priority than every other so holding it suppresses them, which is
  what stashing and restoring the roles was for.
- The command role authority derives exp_scenario.command.<name> from the
  command name, and the role parsers use player_outranks rather than comparing
  indexes with their own root check.
- The admin and spectator triggers, and the gui refresh on role changes, live
  in exp_scenario/control/roles.lua; the system commands trigger stays with
  the command authority.
- The player list warn button is keyed on create_warning, the permission
  the command behind it already required, and report on create_report. Both
  were keyed on names no role held, so only root ever saw them.
- The warps and tasks configs say exp_roles where they said expcore.roles.
- The role tables the readme and player list read are replaced by
  get_player_names and get_roles.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-08-19 11:36:58 +00:00
co-authored by Claude Fable 5
parent eb715cc176
commit 7034f17b5d
53 changed files with 204 additions and 1776 deletions
@@ -1,26 +1,28 @@
--[[-- Command Authorities - Roles
Adds a permission authority for exp roles
Adds a permission authority which checks the clusterio permission for a command
]]
local Commands = require("modules/exp_commands")
local add, allow, deny = Commands.add_permission_authority, Commands.status.success, Commands.status.unauthorised
local Roles = require("modules/exp_legacy/expcore/roles")
local player_allowed = Roles.player_allowed
local Roles = require("modules/exp_roles")
local player_has_permission = Roles.player_has_permission
local authorities = {}
--- If a command has the flag "character_only" then the command can only be used outside of remote view
--- Every command requires the permission `exp_scenario.command.<name>`, with
--- hyphens replaced by underscores, see permissions.ts for their definitions
authorities.exp_permission =
add(function(player, command)
if not player_allowed(player, command.flags.exp_permission or ("command/" .. command.name)) then
local permission = "exp_scenario.command." .. command.name:gsub("%-", "_")
if not player_has_permission(player, permission) then
return deny{ "exp-commands-authorities_role.deny" }
else
return allow()
end
end)
Roles.define_flag_trigger("is_system", function(player, state)
Roles.define_permission_trigger("exp_scenario.player.system_commands", function(player, state)
if state then
Commands.unlock_system_commands(player.name)
else
+1 -1
View File
@@ -8,6 +8,6 @@ local add_static, add_dynamic = Commands.add_rcon_static, Commands.add_rcon_dyna
add_static("Gui", require("modules/exp_gui"))
add_static("Group", require("modules.exp_legacy.expcore.permission_groups"))
add_static("Roles", require("modules.exp_legacy.expcore.roles"))
add_static("Roles", require("modules/exp_roles"))
add_static("Datastore", require("modules.exp_legacy.expcore.datastore"))
add_static("External", require("modules.exp_legacy.expcore.external"))
+25 -21
View File
@@ -1,4 +1,3 @@
--[[-- Command Types - Roles
The data types that are used with exp_roles
A lower role index indicates it is more privileged
@@ -11,28 +10,42 @@ Adds parsers for:
lower_role_player_alive
]]
local ExpUtil = require("modules/exp_util")
local auto_complete = ExpUtil.auto_complete
local Commands = require("modules/exp_commands")
local add, parse = Commands.add_data_type, Commands.parse_input
local valid, invalid = Commands.status.success, Commands.status.invalid_input
local Roles = require("modules.exp_legacy.expcore.roles")
local highest_role = Roles.get_player_highest_role
local Roles = require("modules/exp_roles")
local player_outranks = Roles.player_outranks
local types = {} --- @class (partial) Commands.types
--- A role defined by exp roles
types.role = add("role", Commands.types.key_of(Roles.config.roles))
--- A role known to exp roles, matched on its name
types.role =
add("role", function(input)
local names = {}
for index, role in ipairs(Roles.get_roles()) do
names[index] = role.name
end
local name = auto_complete(names, input)
if name == nil then
return invalid{ "exp-commands-parse.string-options", table.concat(names, ", ") }
else
return valid(Roles.get_role(name))
end
end)
--- A role which is lower than the players highest role
types.lower_role =
add("lower_role", function(input, player)
local success, status, result = parse(input, player, types.role)
if not success then return status, result end
--- @cast result any TODO role is not a defined type
--- @cast result ExpRoles.Role
local player_highest = highest_role(player)
local is_root = Roles.config.internal.root == player_highest.name
if not is_root and player_highest.index >= result.index then
if not Roles.player_outranks_role(player, result) then
return invalid{ "exp-commands-parse_role.lower-role" }
else
return valid(result)
@@ -46,10 +59,7 @@ types.lower_role_player =
if not success then return status, result end
--- @cast result LuaPlayer
local other_highest = highest_role(result)
local player_highest = highest_role(player)
local is_root = Roles.config.internal.root == player_highest.name
if not is_root and player_highest.index >= other_highest.index then
if not player_outranks(player, result) then
return invalid{ "exp-commands-parse_role.lower-role-player" }
else
return valid(result)
@@ -63,10 +73,7 @@ types.lower_role_player_online =
if not success then return status, result end
--- @cast result LuaPlayer
local other_highest = highest_role(result)
local player_highest = highest_role(player)
local is_root = Roles.config.internal.root == player_highest.name
if not is_root and player_highest.index >= other_highest.index then
if not player_outranks(player, result) then
return invalid{ "exp-commands-parse_role.lower-role-player" }
else
return valid(result)
@@ -80,10 +87,7 @@ types.lower_role_player_alive =
if not success then return status, result end
--- @cast result LuaPlayer
local other_highest = highest_role(result)
local player_highest = highest_role(player)
local is_root = Roles.config.internal.root == player_highest.name
if not is_root and player_highest.index >= other_highest.index then
if not player_outranks(player, result) then
return invalid{ "exp-commands-parse_role.lower-role-player" }
else
return valid(result)
+3 -3
View File
@@ -4,8 +4,8 @@ Adds a command that allows players to kill themselves and others
local Commands = require("modules/exp_commands")
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local highest_role = Roles.get_player_highest_role
local Roles = require("modules/exp_roles")
local player_outranks = Roles.player_outranks
--- Kills yourself or another player.
Commands.new("kill", { "exp-commands_kill.description" })
@@ -20,7 +20,7 @@ Commands.new("kill", { "exp-commands_kill.description" })
if other_player == nil then
-- Can only be nil if the target is the player and they are already dead
return Commands.status.error{ "exp-commands_kill.already-dead" }
elseif (other_player == player) or (highest_role(player).index < highest_role(other_player).index) then
elseif other_player == player or player_outranks(player, other_player) then
-- You can always kill yourself or can kill lower role players
if script.active_mods["space-age"] then
other_player.surface.create_entity{ name = "lightning", position = { other_player.position.x, other_player.position.y - 16 }, target = other_player.character }
@@ -11,7 +11,7 @@ local expand_area = AABB.expand
local Commands = require("modules/exp_commands")
local format_player_name = Commands.format_player_name_locale
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local Roles = require("modules/exp_roles")
local EntityProtection = require("modules.exp_legacy.modules.control.protection") --- @dep modules.control.protection
local format_string = string.format
+3 -3
View File
@@ -6,8 +6,8 @@ local Commands = require("modules/exp_commands")
local format_player_name = Commands.format_player_name_locale
local parse_input = Commands.parse_input
local Roles = require("modules.exp_legacy.expcore.roles")
local player_has_flag = Roles.player_has_flag
local Roles = require("modules/exp_roles")
local player_has_permission = Roles.player_has_permission
local Reports = require("modules.exp_legacy.modules.control.reports") --- @dep modules.control.reports
@@ -20,7 +20,7 @@ local function reportable_player(input, player)
if not success then return status, result end
--- @cast result LuaPlayer
if player_has_flag(input, "report-immune") then
if player_has_permission(input, "exp_scenario.bypass.reports") then
return Commands.status.invalid_input{ "exp-commands_reports.player-immune" }
elseif player == input then
return Commands.status.invalid_input{ "exp-commands_reports.self-report" }
+6 -6
View File
@@ -6,8 +6,8 @@ local Commands = require("modules/exp_commands")
local format_player_name = Commands.format_player_name_locale
local format_text = Commands.format_rich_text_color_locale
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local get_roles_ordered = Roles.get_roles_ordered
local Roles = require("modules/exp_roles")
local get_roles = Roles.get_roles
local get_player_roles = Roles.get_player_roles
--- Assigns a role to a player
@@ -18,7 +18,7 @@ Commands.new("assign-role", { "exp-commands_roles.description-assign" })
:add_flags{ "admin_only" }
:register(function(player, other_player, role)
--- @cast other_player LuaPlayer
--- @cast role any -- TODO
--- @cast role ExpRoles.Role
Roles.assign_player(other_player, role, player.name)
end)
@@ -30,7 +30,7 @@ Commands.new("unassign-role", { "exp-commands_roles.description-unassign" })
:add_flags{ "admin_only" }
:register(function(player, other_player, role)
--- @cast other_player LuaPlayer
--- @cast role any -- TODO
--- @cast role ExpRoles.Role
Roles.unassign_player(other_player, role, player.name)
end)
@@ -40,7 +40,7 @@ Commands.new("get-roles", { "exp-commands_roles.description-get" })
:add_aliases{ "roles" }
:register(function(player, other_player)
--- @cast other_player LuaPlayer?
local roles = get_roles_ordered()
local roles = get_roles()
local roles_formatted = { "" } --- @type LocalisedString
local response = { "exp-commands_roles.list-roles", roles_formatted } --[[@as LocalisedString]]
if other_player then
@@ -50,7 +50,7 @@ Commands.new("get-roles", { "exp-commands_roles.description-get" })
end
for index, role in ipairs(roles) do
local role_name = format_text(role.name, role.custom_color or Commands.color.white)
local role_name = format_text(role.name, role.color or Commands.color.white)
roles_formatted[index + 1] = { "exp-commands_roles.list-element", role_name }
end
+3 -3
View File
@@ -7,8 +7,8 @@ local teleport_player = ExpUtil.teleport_player
local Commands = require("modules/exp_commands")
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local player_allowed = Roles.player_allowed
local Roles = require("modules/exp_roles")
local player_has_permission = Roles.player_has_permission
--- @class ExpCommands_Teleport.commands
local commands = {}
@@ -85,7 +85,7 @@ commands.spawn = Commands.new("spawn", { "exp-commands_teleport.description-spaw
if not teleport_player(player, game.surfaces.nauvis, { 0, 0 }, "dismount") then
return Commands.status.error{ "exp-commands_teleport.unavailable" }
end
elseif player_allowed(player, "command/spawn/always") then
elseif player_has_permission(player, "exp_scenario.command.spawn.always") then
if not teleport_player(other_player, game.surfaces.nauvis, { 0, 0 }, "dismount") then
return Commands.status.error{ "exp-commands_teleport.unavailable" }
end