mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
Create FactorioServer and Instance through async factories
FactorioServer.fromOptions finds the Factorio install and generates the RCON password before constructing, so _version and _dataDir are never null and setTargetVersion and init are gone. checkForUpdates is now a module function called before fromOptions. Instance.fromConfig resolves the version, downloads Factorio if needed and builds the server, then constructs the instance with it. It runs before the instance is connected, so the starting and stopped statuses and the version requests go through the host link. FactorioVersionsRequest and LatestReleasesRequest now accept host as a source, and the host tracks starting instances so a second start during a download is rejected. Plugin loading stays a separate loadPlugins step after the instance is connected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3a81cfd94b
commit
abb04f3258
12 files changed
+364
-221
No files matched your search
@@ -12,8 +12,7 @@ describe("Integration of lib/factorio/export", function() {
|
||||
requiresFactorio(this);
|
||||
it("returns a nested Map with base game locale information", async function() {
|
||||
let writePath = path.join("temp", "test", "server");
|
||||
let testServer = new FactorioServer(factorioDir, writePath, {});
|
||||
await testServer.init();
|
||||
let testServer = await FactorioServer.fromOptions(factorioDir, writePath, {});
|
||||
|
||||
let locale = await _exportLocale(testServer, new Map(), new Map(), ["base"], "en");
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { Host, Instance, InstanceConnection } from "@clusterio/host";
|
||||
import { ControlConnection, Controller, HostConnection, InstanceRecord } from "@clusterio/controller";
|
||||
import { MockServer } from "../mock.js";
|
||||
|
||||
// Although there are no imports, the file has side-effects such as "before" which can effect tests
|
||||
import "./index.js";
|
||||
@@ -39,7 +40,7 @@ function connectInstance(controller, host, instanceId) {
|
||||
instanceConfig.set("instance.assigned_host", host.config.get("host.id"));
|
||||
host.assignedInstances.set(instanceId, { path: "invalid", config: instanceConfig });
|
||||
controller.instances.records.set(new InstanceRecord(instanceConfig, "stopped"));
|
||||
const instance = new Instance(host, instanceSide, "invalid", "invalid", instanceConfig);
|
||||
const instance = new Instance(host, instanceSide, "invalid", instanceConfig, new MockServer());
|
||||
const instanceConnection = new InstanceConnection(hostSide, host, instance);
|
||||
host.instanceConnections.set(instanceId, instanceConnection);
|
||||
return instance;
|
||||
|
||||
@@ -40,12 +40,14 @@ describe("Integration of host/src/server", function() {
|
||||
|
||||
describe("class FactorioServer", function() {
|
||||
let writePath = path.join("temp", "test", "integration");
|
||||
let server = new FactorioServer(factorioDir, writePath, {});
|
||||
// Let Factorio bind an OS-assigned UDP port instead of guessing a free one.
|
||||
server.gamePort = 0;
|
||||
let server;
|
||||
let logFile;
|
||||
|
||||
before(async function() {
|
||||
server = await FactorioServer.fromOptions(factorioDir, writePath, {});
|
||||
// Let Factorio bind an OS-assigned UDP port instead of guessing a free one.
|
||||
server.gamePort = 0;
|
||||
|
||||
// Delete result from previous run of these tests
|
||||
await fs.rm(writePath, { force: true, recursive: true, maxRetries: 10 });
|
||||
|
||||
@@ -63,9 +65,6 @@ describe("Integration of host/src/server", function() {
|
||||
}
|
||||
logFile.write(`${JSON.stringify(output)}\n`);
|
||||
});
|
||||
|
||||
// Initialize sever.
|
||||
await server.init();
|
||||
});
|
||||
|
||||
after(function() {
|
||||
|
||||
Reference in new issue
Block a user