Allow inventory sync components to be turned off per instance

Adds an inventory_sync.sync_<component> instance config field for the
controller, force, appearance, inventories, logistics, quick bar,
settings and recipe notifications. All default to on, which keeps the
current behaviour.

A component which is off on an instance is left alone there and its
fields are not stored from that instance. The controller merges each
upload with the stored data using the uploading instance's config, the
instance strips the fields from downloads before sending them over RCON,
and the scenario is told the enabled set on start and when it changes so
it can skip serializing them and skip the steps which replace the
character.

The controller is only synced together with the inventories, as switching
controller can destroy the character holding them. Without the controller
synced the player gets back the controller they had on the instance, only
character inventories move between instances, and a player without a
character keeps their inventory.

Closes #968

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-17 15:25:06 +00:00
1 parent e810020db5
commit 0e559cf000
11 files changed
+571 -81

No files matched your search

+44
View File
@@ -6,6 +6,7 @@ import * as lib from "@clusterio/lib";
import * as mock from "../../../test/mock.js";
import loadInstancePlugin, { recipeNotificationDelta, applyRecipeNotificationDelta } from "../dist/node/instance.js";
import { DownloadResponse } from "../dist/node/messages.js";
import { components } from "../dist/node/components.js";
import { plugin as info } from "../dist/node/index.js";
const inflate = util.promisify(zlib.inflate);
@@ -84,6 +85,9 @@ describe("player_sync", function() {
});
beforeEach(function() {
instance.server.reset();
for (const component of Object.keys(components)) {
instance.mockConfigEntries.set(`player_sync.sync_${component}`, true);
}
});
function respondWith(playerData) {
@@ -125,5 +129,45 @@ describe("player_sync", function() {
const expected = { generation: 1, name: "test", recipe_notifications: await encode({ add: ["a"] }) };
assert.deepEqual(instance.server.rconCommands, [downloadCommand(expected)]);
});
it("should leave out components the instance does not sync", async function() {
instance.mockConfigEntries.set("player_sync.sync_force", false);
instance.mockConfigEntries.set("player_sync.sync_recipe_notifications", false);
respondWith({ generation: 1, name: "test", force: "enemy", tag: "tag", recipe_notifications: "x" });
await download({ player_name: "test" });
const expected = { generation: 1, name: "test", tag: "tag" };
assert.deepEqual(instance.server.rconCommands, [downloadCommand(expected)]);
});
});
describe("set_components", function() {
let instance;
before(async function() {
({ instance } = await mock.loadInstancePlugin(loadInstancePlugin, info));
});
beforeEach(function() {
instance.server.reset();
for (const component of Object.keys(components)) {
instance.mockConfigEntries.set(`player_sync.sync_${component}`, true);
}
});
it("should send the synced components on start", async function() {
instance.mockConfigEntries.set("player_sync.sync_quick_bar", false);
await instance.hooks.start.invoke();
const enabled = Object.fromEntries(
Object.keys(components).filter(c => c !== "quick_bar").map(c => [c, true])
);
const json = lib.escapeString(JSON.stringify(enabled));
assert.deepEqual(
instance.server.rconCommands,
[`/sc player_sync.set_components("${json}")`]
);
});
it("should send the synced components when one is changed", async function() {
await instance.hooks.instanceConfigFieldChanged.invoke("player_sync.rcon_chunk_size", 1, 2);
assert.equal(instance.server.rconCommands.length, 0);
await instance.hooks.instanceConfigFieldChanged.invoke("player_sync.sync_force", false, true);
assert.equal(instance.server.rconCommands.length, 1);
});
});
});