Add bidirectional sync to admin and ban list (#709)

* Add bidirectional sync to admin and ban list

* Add tests

* Response to comments

* Skip broken tests from change of default value
This commit is contained in:
Cooldude2606 authored and GitHub committed 2024-12-23 18:58:44 +00:00
1 parent 91c1d2e6c6
commit 16bc651afc
10 files changed
+571 -52

No files matched your search

+29 -12
View File
@@ -334,9 +334,9 @@ export interface InstanceConfigFields {
"factorio.settings": Record<string, unknown>;
"factorio.verbose_logging": boolean;
"factorio.strip_paths": boolean;
"factorio.sync_adminlist": boolean;
"factorio.sync_whitelist": boolean;
"factorio.sync_banlist": boolean;
"factorio.sync_adminlist": "enabled" | "disabled" | "bidirectional";
"factorio.sync_whitelist": "enabled" | "disabled" | "bidirectional";
"factorio.sync_banlist": "enabled" | "disabled" | "bidirectional";
"factorio.max_concurrent_commands": number;
}
@@ -347,6 +347,20 @@ export interface InstanceConfigFields {
*/
export class InstanceConfig extends classes.Config<InstanceConfigFields> {
declare static fromJSON: (json: classes.ConfigSchema, location: classes.ConfigLocation) => InstanceConfig;
static migrations(config: Static<typeof this.jsonSchema>) {
function boolToEnableDisable(name: string) {
if (config.hasOwnProperty(name) && typeof config[name] === "boolean") {
config[name] = config[name] ? "enabled" : "disabled";
}
}
boolToEnableDisable("factorio.sync_adminlist");
boolToEnableDisable("factorio.sync_whitelist");
boolToEnableDisable("factorio.sync_banlist");
return config;
}
static fieldDefinitions: classes.ConfigDefs<InstanceConfigFields> = {
"instance.name": {
type: "string",
@@ -481,19 +495,22 @@ export class InstanceConfig extends classes.Config<InstanceConfigFields> {
initialValue: true,
},
"factorio.sync_adminlist": {
description: "Synchronize adminlist with controller",
type: "boolean",
initialValue: true,
description: "Synchronize adminlist with the controller",
type: "string",
enum: ["disabled", "enabled", "bidirectional"],
initialValue: "bidirectional",
},
"factorio.sync_whitelist": {
description: "Synchronize whitelist with controller",
type: "boolean",
initialValue: true,
description: "Synchronize whitelist with the controller",
type: "string",
enum: ["disabled", "enabled"], // TODO: Implement bidirectional
initialValue: "enabled",
},
"factorio.sync_banlist": {
description: "Synchronize banlist with controller",
type: "boolean",
initialValue: true,
description: "Synchronize banlist with the controller",
type: "string",
enum: ["disabled", "enabled", "bidirectional"],
initialValue: "bidirectional",
},
"factorio.max_concurrent_commands": {
description: "Maximum number of RCON commands trasmitted in parallel",
+3 -3
View File
@@ -864,7 +864,7 @@ export class InstanceDetailsChangedEvent {
export class InstanceBanlistUpdateEvent {
declare ["constructor"]: typeof InstanceBanlistUpdateEvent;
static type = "event" as const;
static src = ["controller", "host"] as const;
static src = ["controller", "host", "instance"] as const;
static dst = "instance" as const;
constructor(
@@ -887,7 +887,7 @@ export class InstanceBanlistUpdateEvent {
export class InstanceAdminlistUpdateEvent {
declare ["constructor"]: typeof InstanceAdminlistUpdateEvent;
static type = "event" as const;
static src = ["controller", "host"] as const;
static src = ["controller", "host", "instance"] as const;
static dst = "instance" as const;
constructor(
@@ -908,7 +908,7 @@ export class InstanceAdminlistUpdateEvent {
export class InstanceWhitelistUpdateEvent {
declare ["constructor"]: typeof InstanceWhitelistUpdateEvent;
static type = "event" as const;
static src = ["controller", "host"] as const;
static src = ["controller", "host", "instance"] as const;
static dst = "instance" as const;
constructor(
+4 -3
View File
@@ -53,13 +53,14 @@ export type PluginWebpackEnvInfo = PluginDeclaration & {
* Information about the event.
*/
export interface PlayerEvent {
type: "join" | "leave" | "import";
/** Name of the player that joined/left */
type: "join" | "leave" | "import" | "promote" | "demote" | "ban" | "unban" | "whitelisted" | "unwhitelisted";
/** Name of the player that caused the event */
name: string,
/**
* Only present for type "leave". Reason for player leaving the
* Only present for type "leave" and "ban". Reason for player leaving the
* game, one of the possible reasons in defines.disconnect_reason
* or "server_quit" if the server exits while the player is online.
* When type is "ban" this is the reason given for the ban.
*/
reason?: string;
/**