Update config of running Factorio instances

Monitor the factorio.settings config for changes and apply them to
running instances via the /config set command.
This commit is contained in:
Hornwitser committed 2020-05-31 22:28:51 +02:00
1 parent 5b043524b4
commit 931ad4816f
8 files changed
+274 -51

No files matched your search

+37
View File
@@ -6,9 +6,31 @@ const needle = require("needle");
const util = require("util");
const events = require("events");
const link = require("lib/link");
const server = require("lib/factorio/server");
class TestControl extends link.Link {
constructor(connector) {
super("control", "master", connector);
link.attachAllMessages(this);
}
async prepareDisconnectRequestHandler(message, request) {
this.connector.setClosing();
return await super.prepareDisconnectRequestHandler(message, request);
}
async debugWsMessageEventHandler() { }
async instanceOutputEventHandler() { }
}
class TestControlConnector extends link.WebSocketClientConnector {
register() {
this.sendHandshake("register_control", { token: this.token, agent: "clusterctl", version: "test" });
}
}
// Mark that this test takes a lot of time, or depeneds on a test
// that takes a lot of time.
function slowTest(test) {
@@ -29,6 +51,7 @@ async function get(path) {
let masterProcess;
let slaveProcess;
let control;
let url = "https://localhost:4443/";
let token = jwt.sign({ id: "api" }, "TestSecretDoNotUse");
@@ -43,6 +66,11 @@ async function exec(...args) {
return await util.promisify(child_process.exec)(...args);
}
async function sendRcon(instanceId, command) {
let response = await link.messages.sendRcon.send(control, { instance_id: instanceId, command })
return response.result;
}
function spawn(name, cmd, waitFor) {
return new Promise((resolve, reject) => {
console.log(cmd);
@@ -94,6 +122,11 @@ before(async function() {
masterProcess = await spawn("master:", `node master --config ${masterConfigPath} run`, "All plugins loaded");
slaveProcess = await spawn("slave:", `node slave --config ${slaveConfigPath} run`, "SOCKET | received ready from master");
let controlConnector = new TestControlConnector(url, 2);
controlConnector.token = token;
control = new TestControl(controlConnector);
await controlConnector.connect();
});
after(async function() {
@@ -118,9 +151,13 @@ process.on("exit", () => {
module.exports = {
TestControl,
TestControlConnector,
slowTest,
get,
exec,
sendRcon,
control,
url,
token,