Add a web page for configuring scenario features

Features can now be enabled, disabled, and configured from the web UI
while the game is running, without editing Lua files. The first five
features covered are AFK Kick, Chat Auto Reply, Death Markers, Mine
Depletion, and Station Auto Name.

Lua side: module/features.lua holds each feature's defaults, keeps the
overrides from the controller in storage, and patches them onto the
config table in place. Features.guard skips a feature's handlers while
it is disabled. The five config files move from exp_legacy into
exp_scenario/module/config and their control files now read config at
runtime instead of deciding at load which handlers to register. AFK
Kick times are now in minutes.

Controller side: features.ts lists the editable settings and their
defaults. Overrides that differ from the default are stored in
exp_scenario/features.json and guarded by the existing
exp_scenario.config.view/edit permissions. The instance plugin sends
them over rcon on start, on every change, and again after the
controller restarts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-09-28 17:56:14 +00:00
1 parent 46bb15e4a6
commit 88358b23b9
30 files changed
+1226 -89

No files matched your search

+10 -7
View File
@@ -3,8 +3,11 @@ Kicks players when all players on the server are afk
]]
local Async = require("modules/exp_util/async")
local Features = require("modules/exp_scenario/features")
local Storage = require("modules/exp_util/storage")
local config = require("modules.exp_legacy.config.afk_kick")
local config = require("modules/exp_scenario/config/afk_kick")
local ticks_per_minute = 3600
--- @type { last_active: number }
local script_data = { last_active = 0 }
@@ -15,16 +18,16 @@ end)
--- Kicks an afk player, used to add a delay so the gui has time to appear
local afk_kick_player_async =
Async.register(function(player)
if game.tick - script_data.last_active < config.kick_time then return end
if game.tick - script_data.last_active < config.kick_minutes * ticks_per_minute then return end
game.kick_player(player, "AFK while no active players on the server")
end)
--- Check if there is an active player
local function has_active_player()
for _, player in ipairs(game.connected_players) do
if player.afk_time < config.afk_time
if player.afk_time < config.afk_minutes * ticks_per_minute
or config.admin_as_active and player.admin
or config.trust_as_active and player.online_time > config.trust_time
or config.trust_as_active and player.online_time > config.trust_minutes * ticks_per_minute
or config.custom_active_check and config.custom_active_check(player) then
script_data.last_active = game.tick
return true
@@ -40,7 +43,7 @@ local function check_afk_players()
if has_active_player() then return end
-- Check if players should be kicked
if game.tick - script_data.last_active < config.kick_time then return end
if game.tick - script_data.last_active < config.kick_minutes * ticks_per_minute then return end
-- Kick time exceeded, kick all players
for _, player in ipairs(game.connected_players) do
@@ -73,7 +76,7 @@ end
local e = defines.events
return {
return Features.guard(config, {
events = {
[e.on_player_joined_game] = on_player_joined_game,
},
@@ -81,4 +84,4 @@ return {
[config.update_time] = check_afk_players,
},
has_active_player = has_active_player,
}
})
@@ -2,10 +2,9 @@
Adds auto replies to chat messages, as well as chat commands
]]
local Features = require("modules/exp_scenario/features")
local Roles = require("modules/exp_roles")
local config = require("modules.exp_legacy.config.chat_reply")
local prefix = config.command_prefix
local prefix_len = string.len(prefix)
local config = require("modules/exp_scenario/config/chat_auto_reply")
local find = string.find
local sub = string.sub
@@ -16,6 +15,8 @@ local function on_console_chat(event)
if not event.player_index then return end
local player = assert(game.get_player(event.player_index))
local message = event.message:lower():gsub("%s+", "")
local prefix = config.command_prefix
local prefix_len = string.len(prefix)
-- Check if the player can chat commands
local commands_allowed = true
@@ -56,8 +57,8 @@ end
local e = defines.events
return {
return Features.guard(config, {
events = {
[e.on_console_chat] = on_console_chat,
}
}
},
})
+16 -22
View File
@@ -3,8 +3,9 @@ Makes markers on the map where places have died and reclaims items if not recove
]]
local ExpUtil = require("modules/exp_util")
local Features = require("modules/exp_scenario/features")
local Storage = require("modules/exp_util/storage")
local config = require("modules.exp_legacy.config.death_logger")
local config = require("modules/exp_scenario/config/death_markers")
local map_tag_time_format = ExpUtil.format_time_factory{ format = "short", hours = true, minutes = true }
@@ -40,6 +41,7 @@ end
--- Checks that all map tags are present and valid, creating any that are missing
local function check_map_tags()
if not config.show_map_markers then return end
for _, corpse_data in pairs(character_corpses) do
if not corpse_data.tag or not corpse_data.tag.valid then
create_map_tag(corpse_data)
@@ -98,6 +100,7 @@ end
--- Draw lines to the player corpse
--- @param event EventData.on_player_respawned
local function on_player_respawned(event)
if not config.show_line_to_corpse then return end
local index = event.player_index
local player = assert(game.get_player(index))
for _, corpse_data in pairs(character_corpses) do
@@ -122,6 +125,7 @@ end
--- Collect all items from expired character corpses
--- @param event EventData.on_character_corpse_expired
local function on_character_corpse_expired(event)
if not config.collect_corpses then return end
local corpse = event.corpse
local inventory = assert(corpse.get_inventory(defines.inventory.character_corpse))
ExpUtil.transfer_inventory_to_surface{
@@ -132,26 +136,16 @@ local function on_character_corpse_expired(event)
}
end
local on_nth_tick = {}
if config.show_map_markers then
on_nth_tick[config.period_check_map_tags] = check_map_tags
end
local e = defines.events
local events = {
[e.on_player_died] = on_player_died,
[e.on_object_destroyed] = on_object_destroyed,
}
if config.show_line_to_corpse then
events[e.on_player_respawned] = on_player_respawned
end
if config.collect_corpses then
events[e.on_character_corpse_expired] = on_character_corpse_expired
end
return {
on_nth_tick = on_nth_tick,
events = events,
}
return Features.guard(config, {
on_nth_tick = {
[config.period_check_map_tags] = check_map_tags,
},
events = {
[e.on_player_died] = on_player_died,
[e.on_object_destroyed] = on_object_destroyed,
[e.on_player_respawned] = on_player_respawned,
[e.on_character_corpse_expired] = on_character_corpse_expired,
},
})
@@ -3,7 +3,8 @@ Marks mining drills for deconstruction when resources deplete
]]
local Async = require("modules/exp_util/async")
local config = require("modules.exp_legacy.config.miner")
local Features = require("modules/exp_scenario/features")
local config = require("modules/exp_scenario/config/mine_depletion")
local floor = math.floor
@@ -270,8 +271,8 @@ end
local e = defines.events
return {
return Features.guard(config, {
events = {
[e.on_resource_depleted] = on_resource_depleted,
},
}
})
@@ -2,7 +2,8 @@
Automatically name stations when they are placed based on closest resource and direction from spawn
]]
local config = require("modules.exp_legacy.config.station_auto_name")
local Features = require("modules/exp_scenario/features")
local config = require("modules/exp_scenario/config/station_auto_name")
local get_direction do
local directions = {
@@ -98,9 +99,9 @@ end
local e = defines.events
return {
return Features.guard(config, {
events = {
[e.on_built_entity] = rename_station,
[e.on_robot_built_entity] = rename_station,
}
}
},
})