Enable the player proxy by default and give lobbies an empty save

The player proxy now listens on 34197 by default. New hosts default to
the port range 34200-34299 so they don't hand that port to instances,
and the controller logs an error and runs without the proxy if the port
is taken, as hosts with the old range only skip it when the controller
already holds it.

Lobby instances start the save lobby.zip, created on first start as a
one tile map with no autoplace and with the freeplay scenario replaced by
an empty one. This uses the new chooseSave instance hook, which lets
plugins pick or create the save to start, and setSaveScenario from
@clusterio/host, which sets the scenario the save patcher keeps loading.
Map gen settings can't use a width and height of 0 for this, as Factorio
takes 0 to mean an unlimited map.

The address players reach the proxy on moves from lobby.public_address
to controller.player_proxy_public_address. When it's set the player_auth
login page lists it once for the instances behind the proxy instead of
their own addresses, and lobbies with player_auth loaded get a button
that opens the web interface login dialog.
This commit is contained in:
Danielv123 committed 2026-10-29 20:54:11 +01:00
1 parent 3ae486143d
commit a5bd43637e
23 files changed
+391 -121

No files matched your search

+1
View File
@@ -34,5 +34,6 @@ Defaults to `120`.
Show the address to connect to for each server in the server list on the login page of the web interface, made up of host.public_address and the game port of the instance.
This list is visible to anyone who can reach the web interface, so leave it off if you don't want unauthenticated users to see where the servers are.
If `controller.player_proxy_public_address` is set the list shows that address once for all instances without an `instance.player_proxy_port`, as they are reached through the [player proxy](../../docs/player-proxy.md), and the proxy address with the dedicated port for the others.
Defaults to `false`.
+30 -5
View File
@@ -46,6 +46,13 @@ export default async function loadControllerPlugin(context: ControllerPluginCont
controller.app.get("/api/player_auth/servers", (req: Request, res: Response) => {
const servers: Static<typeof PlayerAuthServer.jsonSchema>[] = [];
const includeAddress = controller.config.get("player_auth.show_connect_address");
// When players are meant to connect through the player proxy, instances without a dedicated proxy
// port are only reachable through its main port, which is listed once for all of them.
const proxyAddress = controller.config.get("controller.player_proxy_public_address")
? controller.getPlayerProxyAddress()
: undefined;
const proxiedVersions = new Set<string | undefined>();
for (const instance of controller.instances.values()) {
const pluginLoaded = instance.config.get("player_auth.load_plugin");
@@ -59,16 +66,34 @@ export default async function loadControllerPlugin(context: ControllerPluginCont
continue;
}
const address = instance.gamePort !== undefined
? `${host.publicAddress}:${instance.gamePort}`
: host.publicAddress;
let address: string | undefined;
if (proxyAddress) {
const proxyPort = instance.config.get("instance.player_proxy_port");
if (proxyPort === null) {
proxiedVersions.add(instance.factorioVersion);
continue;
}
address = controller.getPlayerProxyAddress(proxyPort);
} else if (host.publicAddress !== "") {
address = instance.gamePort !== undefined
? `${host.publicAddress}:${instance.gamePort}`
: host.publicAddress;
}
const settings = instance.config.get("factorio.settings");
const includeAddress = controller.config.get("player_auth.show_connect_address");
servers.push({
name: settings["name"] as string || "unnamed server",
factorioVersion: instance.factorioVersion,
address: (includeAddress && host.publicAddress !== "") ? address : undefined,
address: includeAddress ? address : undefined,
});
}
if (proxiedVersions.size) {
const [version] = proxiedVersions;
servers.unshift({
name: controller.config.get("controller.name"),
factorioVersion: proxiedVersions.size === 1 ? version : undefined,
address: includeAddress ? proxyAddress : undefined,
});
}
+52 -24
View File
@@ -138,32 +138,35 @@ describe("player_auth", function() {
});
describe("/api/player_auth/servers", function() {
it("should return a list of running servers with player_auth loaded", async function() {
function addInstance(id, status, load, name, version, gamePort, host=1) {
mockController.instances.records.set(id, {
config: {
get(field) {
if (field === "player_auth.load_plugin") {
return load;
}
if (field === "factorio.settings") {
return { name };
}
if (field === "instance.id") {
return id;
}
if (field === "instance.assigned_host") {
return host;
}
throw new Error(`field ${field} not implemented`);
},
function addInstance(id, status, load, name, version, gamePort, host=1, proxyPort=null) {
mockController.instances.records.set(id, {
config: {
get(field) {
if (field === "player_auth.load_plugin") {
return load;
}
if (field === "factorio.settings") {
return { name };
}
if (field === "instance.id") {
return id;
}
if (field === "instance.assigned_host") {
return host;
}
if (field === "instance.player_proxy_port") {
return proxyPort;
}
throw new Error(`field ${field} not implemented`);
},
status,
gamePort,
factorioVersion: version,
});
}
},
status,
gamePort,
factorioVersion: version,
});
}
it("should return a list of running servers with player_auth loaded", async function() {
addInstance(1, "running", true, "running loaded", "1.1.1", 34197);
addInstance(2, "stopped", true, "stopped loaded", "1.1.2", 34197);
addInstance(3, "running", false, "running unloaded", "1.1.3", 34197);
@@ -186,6 +189,31 @@ describe("player_auth", function() {
{ name: "no version", address: "127.0.0.1:34197" },
]);
});
it("should list the player proxy once for instances behind it", async function() {
for (const id of [...mockController.instances.records.keys()]) {
mockController.instances.records.delete(id);
}
mockController.mockConfigEntries.set("controller.name", "Cluster");
mockController.mockConfigEntries.set(
"controller.player_proxy_public_address", "play.example:34197"
);
mockController.getPlayerProxyAddress = port => `play.example:${port ?? 34197}`;
try {
addInstance(1, "running", true, "behind proxy", "2.1.19", 34201);
addInstance(2, "running", true, "also behind proxy", "2.1.19", 34202);
addInstance(3, "running", true, "dedicated port", "2.1.19", 34203, 1, 34300);
addInstance(4, "stopped", true, "stopped", "2.1.19", 34204, 1, 34301);
const result = await fetch(`${controllerUrl}/api/player_auth/servers`);
assert.deepEqual(await result.json(), [
{ name: "Cluster", address: "play.example:34197", factorioVersion: "2.1.19" },
{ name: "dedicated port", address: "play.example:34300", factorioVersion: "2.1.19" },
]);
} finally {
mockController.mockConfigEntries.set("controller.player_proxy_public_address", null);
}
});
});
describe("/api/player_auth/player_code", function() {