From eab1a42e07130197fdcbf84fd29f3eb60ed8bb7c Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Sat, 11 Jul 2026 23:04:42 +0100 Subject: [PATCH] Make showing the connect address a config option --- plugins/player_auth/controller.ts | 3 ++- plugins/player_auth/index.ts | 7 +++++++ plugins/player_auth/messages.ts | 14 +++++++++----- plugins/player_auth/test/plugin.js | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/plugins/player_auth/controller.ts b/plugins/player_auth/controller.ts index 50667d3a..57485482 100644 --- a/plugins/player_auth/controller.ts +++ b/plugins/player_auth/controller.ts @@ -66,10 +66,11 @@ export class ControllerPlugin extends BaseControllerPlugin { : host.publicAddress; const settings = instance.config.get("factorio.settings"); + const includeAddress = this.controller.config.get("player_auth.show_connect_address"); servers.push({ name: settings["name"] as string || "unnamed server", factorioVersion: instance.factorioVersion, - address, + address: includeAddress ? address : undefined, }); } diff --git a/plugins/player_auth/index.ts b/plugins/player_auth/index.ts index 79fa909d..f8d860b1 100644 --- a/plugins/player_auth/index.ts +++ b/plugins/player_auth/index.ts @@ -8,6 +8,7 @@ declare module "@clusterio/lib" { export interface ControllerConfigFields { "player_auth.code_length": number; "player_auth.code_timeout": number; + "player_auth.show_connect_address": boolean; } } @@ -31,6 +32,12 @@ export const plugin: lib.PluginDeclaration = { type: "number", initialValue: 120, }, + "player_auth.show_connect_address": { + title: "Show Connect Address", + description: "Show server connect addresses to unauthenticated users.", + type: "boolean", + initialValue: false, + }, }, features: [ diff --git a/plugins/player_auth/messages.ts b/plugins/player_auth/messages.ts index 653438da..6d0f0e4e 100644 --- a/plugins/player_auth/messages.ts +++ b/plugins/player_auth/messages.ts @@ -5,21 +5,25 @@ export class PlayerAuthServer { static jsonSchema = Type.Object({ name: Type.String(), - address: Type.String(), + address: Type.Optional(Type.String()), factorioVersion: Type.Optional(Type.String()), }); constructor( public name: string, - public address: string, + public address?: string, public factorioVersion?: string, ) {} toJSON(): Static { - if (this.factorioVersion === undefined) { - return { name: this.name, address: this.address }; + const json = { name: this.name } as Static; + if (this.address !== undefined) { + json.address = this.address; } - return { name: this.name, address: this.address, factorioVersion: this.factorioVersion }; + if (this.factorioVersion !== undefined) { + json.factorioVersion = this.address; + } + return json; } static fromJSON(json: Static) { diff --git a/plugins/player_auth/test/plugin.js b/plugins/player_auth/test/plugin.js index 079b4b4f..dda21aa2 100644 --- a/plugins/player_auth/test/plugin.js +++ b/plugins/player_auth/test/plugin.js @@ -26,7 +26,7 @@ describe("player_auth", function() { it("should be round trip json serialisable", function() { testRoundTripJsonSerialisable(PlayerAuthServer, testMatrix( ["server1", "server2"], // name - ["127.0.0.1", "10.0.0.1:1234"], // address + [undefined, "127.0.0.1", "10.0.0.1:1234"], // address [undefined, "1.1.0", "2.0.0"], // version )); });