mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-14 08:14:52 +09:00
Review feedback from Cooldude on the first version.
Features.register is renamed to Features.config, and guard also takes a
feature name so a feature without settings needs no config call.
Autofill uses this. Small configs now live at the top of the file that
uses them: death markers, mine depletion, station auto name, and
lawnmower. AFK kick and chat auto reply keep separate files because
they contain functions.
Periods no longer need a restart. A lib can list intervals, which map a
config key to a handler that runs every config[key] seconds. They are
checked once a second with a stateless tick check. AFK kick and death
markers use this and expose their periods on the page.
Guis: receive_update raises on_feature_changed, and control/features.lua
refreshes every player's gui when it fires. Autofill's toolbar button
checks Features.is_enabled, and hiding the button also hides its left
element. Quick actions refresh on the event too.
Commands: add_flags{ feature = ... } ties a command to a feature, and a
new authority denies it while the feature is disabled. The custom help
and quick actions already leave out denied commands. Lawnmower uses this
and is now added as a lib, so its destroy_decoratives handlers are
actually registered.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.6 KiB
Lua
46 lines
1.6 KiB
Lua
--[[-- Command Authorities - 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 Features = require("modules/exp_scenario/features")
|
|
local Roles = require("modules/exp_roles")
|
|
local player_has_permission = Roles.player_has_permission
|
|
|
|
local authorities = {}
|
|
|
|
--- 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)
|
|
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)
|
|
|
|
--- Commands flagged with a feature are denied while it is disabled, see features.lua
|
|
authorities.feature_enabled =
|
|
add(function(player, command)
|
|
local feature = command.flags.feature
|
|
if feature and not Features.is_enabled(feature) then
|
|
return deny{ "exp-commands-authorities_feature.deny" }
|
|
else
|
|
return allow()
|
|
end
|
|
end)
|
|
|
|
Roles.define_permission_trigger("core.admin", function(player, state)
|
|
if state then
|
|
Commands.unlock_system_commands(player.name)
|
|
else
|
|
Commands.lock_system_commands(player.name)
|
|
end
|
|
end)
|
|
|
|
return authorities
|