From fcae3ef0c11cfa7c1e759309378ba0cdb061cf6d Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 18 Nov 2019 19:53:09 +0100 Subject: [PATCH] Use detected Factorio version Remove Factorio_version from the config file and use the detected version of Factorio instead. --- CHANGELOG.md | 2 ++ config.json.dist | 4 +--- lib/factorio/server.js | 7 +++++++ lib/manager/modManager.js | 8 ++++---- test/lib/factorio/server.js | 6 ++++++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02b70141..98c61578 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ Version 2.0.0 - Removed redundant call to /api/slaves in globalChat plugin. - Removed broken serverManager plugin. - Removed broken remote combinator signaling. +- Removed factorio_version from config. The version installed is auto + detected and used instead. ### Breaking Changes diff --git a/config.json.dist b/config.json.dist index 3029a6a7..c162cbed 100644 --- a/config.json.dist +++ b/config.json.dist @@ -28,9 +28,7 @@ "username": "", "__comment4": "Token from your factorio.com profile page. Required for MP and mod manager services.", "token": "", - "__comment7": "Used for communication with the mod portal, not needed if you manage mods by hand", - "factorio_version": "0.16.41", - + "__comment5": "General user settings", "verify_user_identity": true, "auto_pause": false, diff --git a/lib/factorio/server.js b/lib/factorio/server.js index 70f93d55..a6ba17c4 100644 --- a/lib/factorio/server.js +++ b/lib/factorio/server.js @@ -443,6 +443,13 @@ class FactorioServer extends events.EventEmitter { this._state = "init"; } + /** + * The version of Factorio that was detected + */ + get version() { + return this._version; + } + _attachStdio() { this._server.stdout.on('data', chunk => { this._stdout.data(chunk); }); this._server.stdout.on('close', () => { this._stdout.end(); }); diff --git a/lib/manager/modManager.js b/lib/manager/modManager.js index dc5da90b..4d472135 100644 --- a/lib/manager/modManager.js +++ b/lib/manager/modManager.js @@ -38,7 +38,7 @@ async function listMods(config, instance) { return new Promise((resolve, reject) => { const instances = require("./../getInstances")(config).sync(); if (instances.includes(instance.name)) { - factorioAPI.init(false, instance.path("instanceMods"), instance.path("saves"), config.factorio_version); + factorioAPI.init(false, instance.path("instanceMods"), instance.path("saves"), instance.server.version); factorioAPI.authenticate({ username: config.username, token: config.token, @@ -68,7 +68,7 @@ async function listMods(config, instance) { }); } else { // list shared mods in /sharedMods/ - factorioAPI.init(false, 'sharedMods/', '', config.factorio_version); + factorioAPI.init(false, 'sharedMods/', '', instance.server.version); factorioAPI.authenticate({ username: config.username, token: config.token, @@ -140,7 +140,7 @@ async function addMod(config, term, instance) { if (term && term.length > 0) { if (term.includes("mods.factorio.com/mods/")) { // https://mods.factorio.com/mods/Danielv123/ChooChoo // treat it as a link download - factorioAPI.init(false, modDirectory, "", config.factorio_version); + factorioAPI.init(false, modDirectory, "", instance.server.version); factorioAPI.authenticate({ username: config.username, token: config.token, @@ -185,7 +185,7 @@ async function addMod(config, term, instance) { } } else { // treat it as a search and download the top result - factorioAPI.init(false, modDirectory, "", config.factorio_version); + factorioAPI.init(false, modDirectory, "", instance.server.version); factorioAPI.authenticate({ username: config.username, token: config.token, diff --git a/test/lib/factorio/server.js b/test/lib/factorio/server.js index c87dbc31..33ef05a5 100644 --- a/test/lib/factorio/server.js +++ b/test/lib/factorio/server.js @@ -204,5 +204,11 @@ describe("lib/factorio/server", function() { await assert.rejects(server.init(), new Error("Expected state new but state is init")); }); }); + + describe(".version", function() { + it("should return the version detected", function() { + assert.equal(server.version, "0.1.1"); + }); + }); }); });