From c2c7edf1b7b956bb2ba3efe5181fa346d2eade71 Mon Sep 17 00:00:00 2001 From: Bastiaan <17990055+bbassie@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:03:22 +0100 Subject: [PATCH] Default to the newest Base Game pack on new clusters (#1216) A new cluster gets the default mod packs but controller.default_mod_pack_id stays null, so the first Create save or Start fails with "Default mod pack not set on controller". When seeding the packs, also point the default at the newest Base Game pack, unless an admin already set one. Clusters that already have mod packs are left alone. The config is written with the mod packs on the next autosave or shutdown. Co-authored-by: Claude Opus 5.5 --- docs/configuration.md | 1 + packages/controller/src/Controller.ts | 6 +++++ test/controller/Controller.js | 37 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/docs/configuration.md b/docs/configuration.md index 009f54bd..82376b98 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -284,6 +284,7 @@ Defaults to true. ID of the mod pack to use for instances that don't have factorio.mod_pack_id set. Instances without a mod pack of their own fail to start if this is null. +When the controller adds the default mod packs to a new cluster it sets this to the newest Base Game pack if it is null. Defaults to null. diff --git a/packages/controller/src/Controller.ts b/packages/controller/src/Controller.ts index 7b0ef1fa..41eda66e 100644 --- a/packages/controller/src/Controller.ts +++ b/packages/controller/src/Controller.ts @@ -233,6 +233,12 @@ export default class Controller { // Add default mod packs if (modPacks.size === 0) { modPacks.setMany(lib.ModPack.defaultModPacks); + if (config.get("controller.default_mod_pack_id") === null) { + const baseGame = lib.ModPack.defaultModPacks + .filter(pack => pack.name.startsWith("Base Game ")) + .reduce((a, b) => (b.integerFactorioVersion > a.integerFactorioVersion ? b : a)); + config.set("controller.default_mod_pack_id", baseGame.id); + } } // Add default roles diff --git a/test/controller/Controller.js b/test/controller/Controller.js index 9a5908c0..abaff944 100644 --- a/test/controller/Controller.js +++ b/test/controller/Controller.js @@ -93,6 +93,43 @@ describe("controller/src/Controller", function() { assert(loaded.modPacks.size > 0, "default mod packs were not added"); await fs.access(modsDirectory); }); + it("should default to the newest Base Game pack on a new cluster", async function() { + const config = new ControllerConfig("controller", { + "controller.version": controllerVersion, + "controller.database_directory": path.join(dir, "database"), + "controller.mods_directory": path.join(dir, "mods"), + }); + + const loaded = await Controller.fromConfig(config, [], {}); + const id = config.get("controller.default_mod_pack_id"); + assert.equal(loaded.modPacks.get(id).name, "Base Game 2.1"); + }); + it("should keep a set default mod pack when seeding mod packs", async function() { + const config = new ControllerConfig("controller", { + "controller.version": controllerVersion, + "controller.database_directory": path.join(dir, "database"), + "controller.mods_directory": path.join(dir, "mods"), + "controller.default_mod_pack_id": 42, + }); + + await Controller.fromConfig(config, [], {}); + assert.equal(config.get("controller.default_mod_pack_id"), 42); + }); + it("should not set a default mod pack when mod packs exist", async function() { + const databaseDirectory = path.join(dir, "database"); + await fs.mkdir(databaseDirectory); + await fs.writeFile(path.join(databaseDirectory, "mod-packs.json"), JSON.stringify([ + new ModPack().toJSON(), + ])); + const config = new ControllerConfig("controller", { + "controller.version": controllerVersion, + "controller.database_directory": databaseDirectory, + "controller.mods_directory": path.join(dir, "mods"), + }); + + await Controller.fromConfig(config, [], {}); + assert.equal(config.get("controller.default_mod_pack_id"), null); + }); it("should start and stop with an existing database", async function() { this.timeout(10000); const databaseDirectory = path.join(dir, "database");