mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
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:
1 parent
96210373f3
commit
e74065a493
35 files changed
+1259
-2090
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -89,7 +89,7 @@ export class ControllerPlugin extends BaseControllerPlugin {
|
||||
|
||||
for (let entry of this.players.values()) {
|
||||
if (entry.playerCode === playerCode && entry.expires > Date.now()) {
|
||||
let verifyCode = await generateCode(this.controller.config.get("player_auth.code_length") as number);
|
||||
let verifyCode = await generateCode(this.controller.config.get("player_auth.code_length"));
|
||||
let secret = Buffer.from(this.controller.config.get("controller.auth_secret"), "base64");
|
||||
let verifyToken = jwt.sign(
|
||||
{
|
||||
@@ -173,8 +173,8 @@ export class ControllerPlugin extends BaseControllerPlugin {
|
||||
}
|
||||
|
||||
async handleFetchPlayerCodeRequest(request: FetchPlayerCodeRequest) {
|
||||
let playerCode = await generateCode(this.controller.config.get("player_auth.code_length") as number);
|
||||
let expires = Date.now() + (this.controller.config.get("player_auth.code_timeout") as number) * 1000;
|
||||
let playerCode = await generateCode(this.controller.config.get("player_auth.code_length"));
|
||||
let expires = Date.now() + this.controller.config.get("player_auth.code_timeout") * 1000;
|
||||
this.players.set(request.player, { playerCode, verifyCode: null, expires });
|
||||
return { player_code: playerCode, controller_url: this.controller.getControllerUrl() };
|
||||
}
|
||||
|
||||
+23
-19
@@ -1,24 +1,15 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as messages from "./messages";
|
||||
|
||||
class ControllerConfigGroup extends lib.PluginConfigGroup {}
|
||||
ControllerConfigGroup.defaultAccess = ["controller", "host", "control"];
|
||||
ControllerConfigGroup.groupName = "player_auth";
|
||||
ControllerConfigGroup.define({
|
||||
name: "code_length",
|
||||
title: "Code Length",
|
||||
description: "Length in characters of the generated codes.",
|
||||
type: "number",
|
||||
initial_value: 6,
|
||||
});
|
||||
ControllerConfigGroup.define({
|
||||
name: "code_timeout",
|
||||
title: "Code Timeout",
|
||||
description: "Time in seconds for the generated codes to stay valid.",
|
||||
type: "number",
|
||||
initial_value: 120,
|
||||
});
|
||||
ControllerConfigGroup.finalize();
|
||||
declare module "@clusterio/lib" {
|
||||
export interface InstanceConfigFields {
|
||||
"player_auth.load_plugin": boolean;
|
||||
}
|
||||
export interface ControllerConfigFields {
|
||||
"player_auth.code_length": number;
|
||||
"player_auth.code_timeout": number;
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
name: "player_auth",
|
||||
@@ -27,7 +18,20 @@ export default {
|
||||
controllerEntrypoint: "dist/plugin/controller",
|
||||
instanceEntrypoint: "dist/plugin/instance",
|
||||
webEntrypoint: "./web",
|
||||
ControllerConfigGroup,
|
||||
controllerConfigFields: {
|
||||
"player_auth.code_length": {
|
||||
title: "Code Length",
|
||||
description: "Length in characters of the generated codes.",
|
||||
type: "number",
|
||||
initialValue: 6,
|
||||
},
|
||||
"player_auth.code_timeout": {
|
||||
title: "Code Timeout",
|
||||
description: "Time in seconds for the generated codes to stay valid.",
|
||||
type: "number",
|
||||
initialValue: 120,
|
||||
},
|
||||
},
|
||||
|
||||
messages: [
|
||||
messages.FetchPlayerCodeRequest,
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
|
||||
class InstanceConfigGroup extends lib.PluginConfigGroup {}
|
||||
InstanceConfigGroup.defaultAccess = ["controller", "host", "control"];
|
||||
InstanceConfigGroup.groupName = "statistics_exporter";
|
||||
InstanceConfigGroup.define({
|
||||
name: "command_timeout",
|
||||
title: "Command Timeout",
|
||||
description: "Timeout in seconds of the metrics command before returning results from the previous invocation.",
|
||||
type: "number",
|
||||
initial_value: 1,
|
||||
});
|
||||
InstanceConfigGroup.finalize();
|
||||
declare module "@clusterio/lib" {
|
||||
export interface InstanceConfigFields {
|
||||
"statistics_exporter.command_timeout": number;
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
name: "statistics_exporter",
|
||||
@@ -19,5 +13,13 @@ export default {
|
||||
"Provides in-game item/fluid production, builds, kills, and pollution "+
|
||||
"statistics to the cluster's Prometheus endpoint.",
|
||||
instanceEntrypoint: "dist/plugin/instance",
|
||||
InstanceConfigGroup,
|
||||
instanceConfigFields: {
|
||||
"statistics_exporter.command_timeout": {
|
||||
title: "Command Timeout",
|
||||
description:
|
||||
"Timeout in seconds of the metrics command before returning results from the previous invocation.",
|
||||
type: "number",
|
||||
initialValue: 1,
|
||||
},
|
||||
},
|
||||
} satisfies lib.PluginDeclaration;
|
||||
@@ -109,7 +109,7 @@ export class InstancePlugin extends BaseInstancePlugin {
|
||||
// take a long time for the command to go through if the command
|
||||
// stream is overloaded. Should the timeout be exceeded the
|
||||
// previous values for the metrics will end up being sent to controller.
|
||||
let timeout = this.instance.config.get("statistics_exporter.command_timeout") as number * 1000;
|
||||
let timeout = this.instance.config.get("statistics_exporter.command_timeout") * 1000;
|
||||
await lib.timeout(this.gatherMetrics(), timeout, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ export class ControllerPlugin extends BaseControllerPlugin {
|
||||
let count = dole.doleDivider({
|
||||
object: { name: item.name, count: item.count, instanceId, instanceName },
|
||||
items: this.items,
|
||||
logItemTransfers: this.controller.config.get("subspace_storage.log_item_transfers") as boolean,
|
||||
logItemTransfers: this.controller.config.get("subspace_storage.log_item_transfers"),
|
||||
logger: this.logger,
|
||||
});
|
||||
if (count > 0) {
|
||||
|
||||
@@ -1,37 +1,15 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as messages from "./messages";
|
||||
|
||||
class ControllerConfigGroup extends lib.PluginConfigGroup {}
|
||||
ControllerConfigGroup.defaultAccess = ["controller", "host", "control"];
|
||||
ControllerConfigGroup.groupName = "subspace_storage";
|
||||
ControllerConfigGroup.define({
|
||||
name: "division_method",
|
||||
title: "Division Method",
|
||||
description: "Method for dividing resource requests between instances.",
|
||||
type: "string",
|
||||
enum: ["simple", "dole", "neural_dole"],
|
||||
initial_value: "simple",
|
||||
});
|
||||
ControllerConfigGroup.define({
|
||||
name: "log_item_transfers",
|
||||
title: "Log Item Transfers",
|
||||
description: "Spam controller console with item transfers done.",
|
||||
type: "boolean",
|
||||
initial_value: false,
|
||||
});
|
||||
ControllerConfigGroup.finalize();
|
||||
|
||||
class InstanceConfigGroup extends lib.PluginConfigGroup {}
|
||||
InstanceConfigGroup.defaultAccess = ["controller", "host", "control"];
|
||||
InstanceConfigGroup.groupName = "subspace_storage";
|
||||
InstanceConfigGroup.define({
|
||||
name: "log_item_transfers",
|
||||
title: "Log Item Transfers",
|
||||
description: "Spam host console with item transfers done.",
|
||||
type: "boolean",
|
||||
initial_value: false,
|
||||
});
|
||||
InstanceConfigGroup.finalize();
|
||||
declare module "@clusterio/lib" {
|
||||
export interface ControllerConfigFields {
|
||||
"subspace_storage.division_method": "simple" | "dole" | "neural_dole";
|
||||
"subspace_storage.log_item_transfers": boolean;
|
||||
}
|
||||
export interface InstanceConfigFields {
|
||||
"subspace_storage.log_item_transfers": boolean;
|
||||
}
|
||||
}
|
||||
|
||||
lib.definePermission({
|
||||
name: "subspace_storage.storage.view",
|
||||
@@ -45,10 +23,31 @@ export default {
|
||||
title: "Subspace Storage",
|
||||
description: "Provides shared storage across instances for the Subspace Storage mod",
|
||||
instanceEntrypoint: "dist/plugin/instance",
|
||||
InstanceConfigGroup,
|
||||
instanceConfigFields: {
|
||||
"subspace_storage.log_item_transfers": {
|
||||
title: "Log Item Transfers",
|
||||
description: "Spam host console with item transfers done.",
|
||||
type: "boolean",
|
||||
initialValue: false,
|
||||
},
|
||||
},
|
||||
|
||||
controllerEntrypoint: "dist/plugin/controller",
|
||||
ControllerConfigGroup,
|
||||
controllerConfigFields: {
|
||||
"subspace_storage.division_method": {
|
||||
title: "Division Method",
|
||||
description: "Method for dividing resource requests between instances.",
|
||||
type: "string",
|
||||
enum: ["simple", "dole", "neural_dole"],
|
||||
initialValue: "simple",
|
||||
},
|
||||
"subspace_storage.log_item_transfers": {
|
||||
title: "Log Item Transfers",
|
||||
description: "Spam controller console with item transfers done.",
|
||||
type: "boolean",
|
||||
initialValue: false,
|
||||
},
|
||||
},
|
||||
|
||||
messages: [
|
||||
messages.PlaceEvent,
|
||||
|
||||
Reference in new issue
Block a user