Files
bbassieandClaude Fable 5.1 30f1b5ea75 Declare permissions on the plugin declaration
Clusterio #988 added a permissions array to PluginDeclaration and a
type level Permissions registry, and made checkPermission and the web
UI hasPermission helpers take PermissionName. Move the definePermission
calls of exp_groups and exp_scenario into the declaration and add the
names to the registry so the web pages type check. The browser
tsconfigs include index.ts so the augmentation is visible to the web
bundle, matching the in-repo plugins.

The exp_scenario table keeps its tuple form and derives the name union
from it, so a new row is still one line. Seed role permissions are typed
as PermissionName, so a typo in seed.ts is now a compile error rather
than a warning at seed time. The tests register the declared
permissions through registerPluginPermissions instead of importing
permissions.ts for its side effect.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-11 23:27:17 +00:00

130 lines
12 KiB
TypeScript

import type * as lib from "@clusterio/lib";
/**
* Permissions checked by the scenario in game through exp_roles.
*
* Commands are checked as `exp_scenario.command.<name>` with hyphens replaced by
* underscores, see module/commands/_authorities.lua. Everything else is checked
* by name at its call site.
*/
type Definition<Name extends string = string> = readonly [name: Name, title: string, description: string, grantByDefault?: boolean];
const definitions = [
["exp_scenario.bypass.deconstruction_log", "Deconstruction log bypass", "Be excluded from the deconstruction log."],
["exp_scenario.bypass.entity_protection", "Bypass entity protection", "Remove entities that the protection filter would block."],
["exp_scenario.bypass.nuke_protection", "Bypass nuke protection", "Use nukes without the nuke protection restrictions."],
["exp_scenario.bypass.reports", "Report immune", "Be immune to being reported by other players."],
["exp_scenario.chat.commands", "Chat commands", "Use the chat command prefix to trigger auto replies."],
["exp_scenario.command._ipc", "/_ipc", "Send an IPC message on the selected channel."],
["exp_scenario.command._rcon", "/_rcon", "Execute arbitrary code within a custom environment."],
["exp_scenario.command._sudo", "/_sudo", "Run a command as another player."],
["exp_scenario.command.admin_chat", "/admin-chat", "Sends a message in chat that only admins can see."],
["exp_scenario.command.artillery", "/artillery", "Automaticly select enemy target with artillery."],
["exp_scenario.command.assign_role", "/assign-role", "Assigns a role lower than your own to a player."],
["exp_scenario.command.bring", "/bring", "Teleports a player to you."],
["exp_scenario.command.clear_blueprints", "/clear-blueprints", "Clear all blueprints."],
["exp_scenario.command.clear_blueprints_surface", "/clear-blueprints-surface", "Clear all blueprints on the current surface."],
["exp_scenario.command.clear_ground_items", "/clear-ground-items", "Clear all items on the ground."],
["exp_scenario.command.clear_inventory", "/clear-inventory", "Clear a player's inventory, moving all items to spawn."],
["exp_scenario.command.clear_pollution", "/clear-pollution", "Clear pollution from your current surface, or another surface."],
["exp_scenario.command.clear_reports", "/clear-reports", "Clears all reports from a player or just the report from one player."],
["exp_scenario.command.collectdata", "/collectdata", "Collect data for RCON usage."],
["exp_scenario.command.commands", "/commands", "List and search all commands for a keyword.", true],
["exp_scenario.command.connect", "/connect", "Connect to another server.", true],
["exp_scenario.command.connect_all", "/connect-all", "Connect all players to another server."],
["exp_scenario.command.connect_player", "/connect-player", "Connect a player to a different server."],
["exp_scenario.command.create_report", "/create-report", "Reports a player and notifies moderators.", true],
["exp_scenario.command.data_preference", "/data-preference", "Allows you to set/get your data saving preference.", true],
["exp_scenario.command.debug", "/debug", "Opens the debug gui."],
["exp_scenario.command.follow", "/follow", "Start following a player in spectator."],
["exp_scenario.command.get_home", "/get-home", "Returns your current home location."],
["exp_scenario.command.get_reports", "/get-reports", "List the reports against a player, or against every player."],
["exp_scenario.command.get_roles", "/get-roles", "Get all roles that a player has, if no player provided it lists all roles.", true],
["exp_scenario.command.goto", "/goto", "Teleports you to a player."],
["exp_scenario.command.home", "/home", "Teleports you to your home location."],
["exp_scenario.command.jail", "/jail", "Puts a player into jail, which suppresses all of their other roles."],
["exp_scenario.command.kill", "/kill", "Kills yourself or another player."],
["exp_scenario.command.kill.always", "/kill (any player)", "Kill any player, not just yourself."],
["exp_scenario.command.kill_enemies", "/kill-enemies", "Kill all enemy units."],
["exp_scenario.command.lawnmower", "/lawnmower", "Clean up biter corpse, decoratives and nuclear hole."],
["exp_scenario.command.locate", "/locate", "Opens remote view at the location of the player's last location.", true],
["exp_scenario.command.me", "/me", "Sends an action message in the chat."],
["exp_scenario.command.protect_area", "/protect-area", "Toggles area protection selection, hold shift to remove protection."],
["exp_scenario.command.protect_entity", "/protect-entity", "Toggles entity protection selection, hold shift to remove protection."],
["exp_scenario.command.protect_tag", "/protect-tag", "Toggles protected tag mode, edit and create protected map tags."],
["exp_scenario.command.rainbow", "/rainbow", "Sends an rainbow message in the chat."],
["exp_scenario.command.ratio", "/ratio", "Get the input and output ratios of the selected machine.", true],
["exp_scenario.command.remove_enemies", "/remove-enemies", "Remove all enemy spawners."],
["exp_scenario.command.remove_join_message", "/remove-join-message", "Removes you custom join message."],
["exp_scenario.command.repair", "/repair", "Repairs entities on your force around you."],
["exp_scenario.command.research_all", "/research-all", "Research all technology for your force, or another force."],
["exp_scenario.command.return", "/return", "Teleports you to previous location."],
["exp_scenario.command.save_data", "/save-data", "Writes all your player data to a file on your computer.", true],
["exp_scenario.command.save_quickbar", "/save-quickbar", "Saves your Quickbar preset items to file."],
["exp_scenario.command.search", "/search", "Display players sorted by the quantity of an item held and playtime."],
["exp_scenario.command.search_amount", "/search-amount", "Display players sorted by the quantity of an item held."],
["exp_scenario.command.search_online", "/search-online", "Display online players sorted by item count and playtime."],
["exp_scenario.command.search_recent", "/search-recent", "Display players who hold an item sorted by join time."],
["exp_scenario.command.server_ups", "/server-ups", "Toggle the server UPS display.", true],
["exp_scenario.command.set_always_day", "/set-always-day", "Set always day for your current surface, or another surface."],
["exp_scenario.command.set_bot_queue", "/set-bot-queue", "Get / Set the construction bot queue limits."],
["exp_scenario.command.set_cheat_mode", "/set-cheat-mode", "Set cheat mode for your player, or another player."],
["exp_scenario.command.set_friendly_fire", "/set-friendly-fire", "Set friendly fire for your force, or another force."],
["exp_scenario.command.set_game_speed", "/set-game-speed", "Set or get the current game speed."],
["exp_scenario.command.set_home", "/set-home", "Sets your home location to your current position."],
["exp_scenario.command.set_join_message", "/set-join-message", "Sets / Gets your custom join message."],
["exp_scenario.command.set_pollution_enabled", "/set-pollution-enabled", "Set polution enabled state for this game."],
["exp_scenario.command.set_trains_to_automatic", "/set-trains-to-automatic", "Set all trains without passengers to automatic."],
["exp_scenario.command.spawn", "/spawn", "Teleport to spawn."],
["exp_scenario.command.spawn.always", "/spawn (any player)", "Teleport any player to spawn, not just yourself."],
["exp_scenario.command.spectate", "/spectate", "Toggles spectator mode."],
["exp_scenario.command.tag", "/tag", "Sets your player tag.", true],
["exp_scenario.command.tag_clear", "/tag-clear", "Clears your tag. Or another player if you are admin.", true],
["exp_scenario.command.tag_clear.always", "/tag-clear (any player)", "Clear the tag of any player, not just your own."],
["exp_scenario.command.tag_color", "/tag-color", "Sets your player tag color."],
["exp_scenario.command.teleport", "/teleport", "Teleports a player to another player."],
["exp_scenario.command.unassign_role", "/unassign-role", "Unassigns a role lower than your own from a player."],
["exp_scenario.command.unjail", "/unjail", "Removes a player from jail, restoring their other roles."],
["exp_scenario.command.vlayer_info", "/vlayer-info", "Print all vlayer information."],
["exp_scenario.command.waterfill", "/waterfill", "Replace tiles with shallow water."],
["exp_scenario.decon.fast_trees", "Fast tree deconstruction", "Trees and rocks marked for deconstruction are removed instantly, when enabled from the toolbar."],
["exp_scenario.decon.standard", "Standard deconstruction", "Mark entities placed by other players for deconstruction."],
["exp_scenario.gui.autofill", "Autofill", "Open the autofill GUI, which fills placed entities from your inventory.", true],
["exp_scenario.gui.bonus", "Bonus", "Open the bonus GUI to adjust your personal bonuses."],
["exp_scenario.gui.module", "Module inserter", "Open the module inserter GUI.", true],
["exp_scenario.gui.player_list", "Player list", "Open the player list GUI.", true],
["exp_scenario.gui.player_list.ban", "Player list: ban", "Ban a player from the cluster via the player list."],
["exp_scenario.gui.player_list.kick", "Player list: kick", "Kick a player from the server via the player list."],
["exp_scenario.gui.playerdata", "Player statistics", "Open the player statistics GUI."],
["exp_scenario.gui.production", "Production statistics", "Open the production statistics GUI.", true],
["exp_scenario.gui.readme", "Readme", "Open the server readme GUI.", true],
["exp_scenario.gui.research", "Research milestones", "Open the research milestones GUI.", true],
["exp_scenario.gui.rocket_info", "Rocket info", "Open the rocket info GUI.", true],
["exp_scenario.gui.rocket_info.remote_launch", "Rocket info: remote launch", "Launch rockets remotely from the rocket info GUI."],
["exp_scenario.gui.rocket_info.toggle_active", "Rocket info: toggle active", "Toggle whether a silo launches automatically."],
["exp_scenario.gui.science_info", "Science production", "Open the science production GUI.", true],
["exp_scenario.gui.surveillance", "Surveillance", "Open the surveillance GUI showing remote camera views."],
["exp_scenario.gui.task_list", "Task list", "Open the task list GUI.", true],
["exp_scenario.gui.task_list.add", "Task list: add", "Add new tasks to the task list."],
["exp_scenario.gui.task_list.edit", "Task list: edit", "Edit and remove existing tasks on the task list."],
["exp_scenario.gui.tool", "Quick actions", "Open the quick actions GUI."],
["exp_scenario.gui.vlayer", "Virtual layer", "Open the virtual layer GUI.", true],
["exp_scenario.gui.vlayer_edit", "Virtual layer: edit", "Use the edit controls in the virtual layer GUI."],
["exp_scenario.gui.warp_list", "Warp list", "Open the warp list GUI and warp between locations.", true],
["exp_scenario.gui.warp_list.add", "Warp list: add", "Add new warp points to the warp list."],
["exp_scenario.gui.warp_list.bypass_cooldown", "Warp list: bypass cooldown", "Warp without waiting for the warp cooldown."],
["exp_scenario.gui.warp_list.bypass_proximity", "Warp list: bypass proximity", "Warp without standing near a warp point."],
["exp_scenario.gui.warp_list.edit", "Warp list: edit", "Edit and remove existing warp points."],
["exp_scenario.player.admin", "Factorio admin", "Be promoted to Factorio admin while holding a role with this permission."],
["exp_scenario.player.instant_respawn", "Instant respawn", "Respawn after two seconds instead of the default delay."],
["exp_scenario.player.spectator", "Spectator", "Remove the zoom to world noise effect, as Factorio does for spectators."],
] as const satisfies readonly Definition[];
/** Name of a permission defined by the scenario, added to lib.Permissions in index.ts. */
export type ScenarioPermissionName = (typeof definitions)[number][0];
export const permissions = definitions.map((definition: Definition<ScenarioPermissionName>): lib.PermissionDefinition => {
const [name, title, description, grantByDefault] = definition;
return { name, title, description, grantByDefault };
});