Send save list update after manual save

Trigger a save list update in the event an admin manually saves the game
with the /server-save command.
This commit is contained in:
Hornwitser committed 2022-03-25 23:15:07 +01:00
1 parent ce95f868fd
commit 946847c95d
3 files changed
+37 -2

No files matched your search

+3
View File
@@ -409,6 +409,7 @@ const outputHeuristics = [
* - game-ready - invoked when the server is finished starting up
* - autosave-start - invoked when the server starts an autosave
* - autosave-fnished - invoked when the autosave finished
* - save-finished - invoked when the server has finished a manual save
* - exit - invoked when the sterver has exited
* @extends events.EventEmitter
* @memberof module:lib/factorio
@@ -500,6 +501,8 @@ class FactorioServer extends events.EventEmitter {
if (this._runningAutosave) {
this.emit("autosave-finished", this._runningAutosave);
this._runningAutosave = null;
} else {
this.emit("save-finished");
}
});
}
+6
View File
@@ -199,6 +199,12 @@ class Instance extends libLink.Link {
});
});
this.server.on("save-finished", () => {
this.sendSaveListUpdate().catch(err => {
this.logger.error(`Error handling save-finished in instance ${this.name}:\n${err.stack}`);
});
});
this.server.on("ipc-player_event", event => {
libLink.messages.playerEvent.send(this, {
instance_id: this.id,
+28 -2
View File
@@ -6,6 +6,7 @@ const events = require("events");
const libLink = require("@clusterio/lib/link");
const libUsers = require("@clusterio/lib/users");
const { wait } = require("@clusterio/lib/helpers");
const testStrings = require("../lib/factorio/test_strings");
const {
@@ -252,6 +253,7 @@ describe("Integration of Clusterio", function() {
describe("instance create-save", function() {
it("creates a save", async function() {
slowTest(this);
getControl().saveListUpdates = [];
await execCtl("instance create-save test");
await checkInstanceStatus(44, "stopped");
});
@@ -325,8 +327,32 @@ describe("Integration of Clusterio", function() {
describe("instance send-rcon", function() {
it("sends the command", async function() {
slowTest(this);
await execCtl("instance send-rcon test test");
// TODO check that the command was received
await execCtl("instance send-rcon test technobabble");
let { log } = await libLink.messages.queryLog.send(getControl(), {
all: false,
master: false,
slave_ids: [],
instance_ids: [44],
max_level: null,
limit: 10,
order: "desc",
});
assert(log.some(info => /technobabble/.test(info.message)), "Command was not sent");
});
it("should trigger saveListUpdate on save", async function() {
slowTest(this);
getControl().saveListUpdates = [];
await execCtl("instance send-rcon test /server-save");
let received = false;
for (let x = 0; x < 10; x++) {
if (getControl().saveListUpdates.length) {
received = true;
break;
}
await wait(100);
}
assert(received, "saveListUpdate not sent");
});
});