mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-08-13 00:45:11 +09:00
Clusterio already stores roles, the permissions they grant, and which user holds which role, along with a web UI for all three. What it does not have is the properties a role only needs in game, or a way for an instance to learn about any of it, since role and user updates are only sent to control connections. This plugin fills both gaps. The controller keeps a record per role holding the order, priority, short hand, tag, colour and auto assign threshold, created automatically for any role which does not have one. It then rebroadcasts roles and assignments on its own events so instances can follow them. The lua module presents the same interface the legacy expcore.roles module did, so the call sites can be moved over without being rewritten. Permission checks translate the legacy action strings using the same mapping exp_scenario defines. Two things replace features the legacy system had: - Priority replaces disallow. Only the roles with the highest priority a player holds are considered, so Jail can suppress every other role including the default one, without needing to take roles away first. - Assignments made in game are applied locally and then sent to the controller, which keeps assign_player synchronous for callers. A role which should never leave this map, such as one earned from time on the map, is assigned with assign_player_local instead. Roles earned from online time across the cluster are granted by the controller from the threshold on the role, using the online time clusterio already tracks. Nothing requires this plugin yet; moving the call sites off expcore.roles and removing the legacy config is left for a follow up. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
78 lines
2.0 KiB
TypeScript
78 lines
2.0 KiB
TypeScript
import * as lib from "@clusterio/lib";
|
|
import * as messages from "./messages";
|
|
|
|
declare module "@clusterio/lib" {
|
|
export interface InstanceConfigFields {
|
|
"exp_roles.sync_mode": "disabled" | "enabled" | "bidirectional";
|
|
}
|
|
}
|
|
|
|
lib.definePermission({
|
|
name: "exp_roles.role.list",
|
|
title: "List In Game Roles",
|
|
description: "List the in game properties of all roles.",
|
|
grantByDefault: true,
|
|
});
|
|
lib.definePermission({
|
|
name: "exp_roles.role.subscribe",
|
|
title: "Subscribe to In Game Role Updates",
|
|
description: "Receive updates when the in game properties of a role change.",
|
|
grantByDefault: true,
|
|
});
|
|
lib.definePermission({
|
|
name: "exp_roles.role.update",
|
|
title: "Update In Game Roles",
|
|
description: "Modify the in game properties of a role, such as its order and colour.",
|
|
});
|
|
|
|
lib.definePermission({
|
|
name: "exp_roles.assignment.list",
|
|
title: "List Role Assignments",
|
|
description: "List the roles held by each player in game.",
|
|
grantByDefault: true,
|
|
});
|
|
lib.definePermission({
|
|
name: "exp_roles.assignment.subscribe",
|
|
title: "Subscribe to Role Assignment Updates",
|
|
description: "Receive updates when the roles held by a player change.",
|
|
grantByDefault: true,
|
|
});
|
|
|
|
export const plugin: lib.PluginDeclaration = {
|
|
name: "exp_roles",
|
|
title: "ExpGaming - Roles",
|
|
description: "Clusterio plugin providing syncing of in game roles",
|
|
|
|
features: [
|
|
"SavePatching",
|
|
"ScriptCommands",
|
|
],
|
|
|
|
messages: [
|
|
messages.RoleUpdatedEvent,
|
|
messages.AssignmentUpdatedEvent,
|
|
|
|
messages.RoleListRequest,
|
|
messages.RoleMetaUpdateRequest,
|
|
|
|
messages.AssignmentListRequest,
|
|
messages.AssignmentUpdateRequest,
|
|
],
|
|
|
|
instanceEntrypoint: "./dist/node/instance",
|
|
instanceConfigFields: {
|
|
"exp_roles.sync_mode": {
|
|
description: "Synchronize in game roles with the controller",
|
|
type: "string",
|
|
enum: ["disabled", "enabled", "bidirectional"],
|
|
initialValue: "bidirectional",
|
|
},
|
|
},
|
|
|
|
controllerEntrypoint: "./dist/node/controller",
|
|
controllerConfigFields: {
|
|
},
|
|
|
|
webEntrypoint: "./web",
|
|
};
|