Remove config groups

Refactor away the config group concept and simplyfy the way config
fields are defined.  Fields are defined directly as properties of the
static field fieldDefinitions on the class itself with a separate
interface to declare the types of fields.

This makes it possible to easily make accessing the config fields type
checked in a way that lets plugins extend the interfaces with their own
config options by adding additional fields to the interface via
declation merging.
This commit is contained in:
Hornwitser committed 2024-01-09 02:19:07 +01:00
1 parent 96210373f3
commit e74065a493
35 files changed
+1259 -2090

No files matched your search

+1 -1
View File
@@ -62,7 +62,7 @@ export class ControllerPlugin extends BaseControllerPlugin {
}
if (["unknown", "stopped"].includes(instance.status)) {
let timeout = this.controller.config.get("inventory_sync.player_lock_timeout") as number * 1000;
let timeout = this.controller.config.get("inventory_sync.player_lock_timeout") * 1000;
for (let acquisitonRecord of this.acquiredPlayers.values()) {
if (acquisitonRecord.instanceId === instanceId && !acquisitonRecord.expires) {
acquisitonRecord.expires = Date.now() + timeout;
+27 -26
View File
@@ -1,30 +1,14 @@
import * as lib from "@clusterio/lib";
import * as messages from "./messages";
class ControllerConfigGroup extends lib.PluginConfigGroup { }
ControllerConfigGroup.defaultAccess = ["controller", "host", "control"];
ControllerConfigGroup.groupName = "inventory_sync";
ControllerConfigGroup.define({
name: "player_lock_timeout",
title: "Player Lock Timeout",
description:
"Time in seconds before the lock on a player inventory expires after an instance stops or is disconnected",
type: "number",
initial_value: 60,
});
ControllerConfigGroup.finalize();
class InstanceConfigGroup extends lib.PluginConfigGroup { }
InstanceConfigGroup.defaultAccess = ["controller", "host", "control"];
InstanceConfigGroup.groupName = "inventory_sync";
InstanceConfigGroup.define({
name: "rcon_chunk_size",
title: "Rcon inventory chunk size",
description: "Divide inventories into multiple chunks before sending with rcon to prevent blocking the pipe",
type: "number",
initial_value: 1000,
});
InstanceConfigGroup.finalize();
declare module "@clusterio/lib" {
export interface InstanceConfigFields {
"inventory_sync.rcon_chunk_size": number;
}
export interface ControllerConfigFields {
"inventory_sync.player_lock_timeout": number;
}
}
lib.definePermission({
name: "inventory_sync.inventory.view",
@@ -39,10 +23,27 @@ export default {
description: "Synchronizes players inventories between instances",
instanceEntrypoint: "dist/plugin/instance",
InstanceConfigGroup,
instanceConfigFields: {
"inventory_sync.rcon_chunk_size": {
title: "Rcon inventory chunk size",
description:
"Divide inventories into chunks of this size before sending with rcon to prevent blocking the pipe",
type: "number",
initialValue: 1000,
},
},
controllerEntrypoint: "dist/plugin/controller",
ControllerConfigGroup,
controllerConfigFields: {
"inventory_sync.player_lock_timeout": {
title: "Player Lock Timeout",
description:
"Time in seconds before the lock on a player inventory expires after an instance stops " +
"or is disconnected",
type: "number",
initialValue: 60,
},
},
messages: [
messages.AcquireRequest,
+1 -1
View File
@@ -177,7 +177,7 @@ export class InstancePlugin extends BaseInstancePlugin {
return;
}
const chunkSize = this.instance.config.get("inventory_sync.rcon_chunk_size") as number;
const chunkSize = this.instance.config.get("inventory_sync.rcon_chunk_size");
const chunks = chunkify(chunkSize, JSON.stringify(response.playerData));
this.logger.verbose(`Sending inventory for ${playerName} in ${chunks.length} chunks`);
for (let i = 0; i < chunks.length; i++) {