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

+17
View File
@@ -5,6 +5,7 @@ import type { InstancePluginContext } from "@clusterio/host";
import {
AcquireRequest, AcquireResponse, ReleaseRequest, UploadRequest, DownloadRequest, DownloadResponse, IpcPlayerData,
} from "./messages.js";
import { enabledComponents, stripPlayerData } from "./components.js";
type IpcPlayerName = {
player_name: string
@@ -198,6 +199,7 @@ export default async function(context: InstancePluginContext) {
return;
}
stripPlayerData(response.playerData, enabledComponents(instance.config));
await applyRecipeNotificationDelta(response.playerData, request.recipe_notifications, logger);
const chunkSize = instance.config.get("player_sync.rcon_chunk_size");
@@ -239,6 +241,21 @@ export default async function(context: InstancePluginContext) {
),
);
/** Tell the scenario which components are synced. */
async function sendComponents() {
const enabled = Object.fromEntries([...enabledComponents(instance.config)].map(name => [name, true]));
const json = lib.escapeString(JSON.stringify(enabled));
await instance.sendRcon(`/sc player_sync.set_components("${json}")`, true, plugin.name);
}
instance.hooks.start.attach(plugin.name, sendComponents);
instance.hooks.instanceConfigFieldChanged.attach(plugin.name, async (field) => {
if (field.startsWith("player_sync.sync_") && instance.status === "running") {
await sendComponents();
}
});
instance.hooks.prepareControllerDisconnect.attach(plugin.name, async () => {
disconnecting = true;
});