Files
factorio-clusterio/plugins/player_sync/index.ts
T
bbassieandClaude Opus 5.5 b0e07ea73b Merge uploads by the components they were serialized with
The controller merged uploads using the uploading instance's current config. An upload serialized under different settings, for example one sent from the save right after an admin turned on sync_inventories and restarted the instance, was then merged as if it held a character and wiped the stored one. Uploads now carry the components they were serialized with, the controller merges by those and drops the key before storing.

The scenario keeps the components a player's synced session started with and serializes their upload with them, so changing the options while a player is online takes effect the next time they join. A player whose session lacks a component that is now synced downloads again even if the generation matches. Downloads snapshot the components when they start, so a change during a download can't mix two sets.

A failed acquire unsyncs the player again regardless of the inventories setting, as before this branch.

The god and dead player inventories move from the inventories component to the controller one, matching what the scenario syncs, which removes the special case in mergePlayerData.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 15:25:06 +00:00

128 lines
3.6 KiB
TypeScript

import * as lib from "@clusterio/lib";
import * as messages from "./messages.js";
declare module "@clusterio/lib" {
export interface InstanceConfigFields {
"player_sync.rcon_chunk_size": number;
"player_sync.sync_controller": boolean;
"player_sync.sync_force": boolean;
"player_sync.sync_appearance": boolean;
"player_sync.sync_inventories": boolean;
"player_sync.sync_logistics": boolean;
"player_sync.sync_quick_bar": boolean;
"player_sync.sync_settings": boolean;
"player_sync.sync_recipe_notifications": boolean;
}
export interface ControllerConfigFields {
"player_sync.player_lock_timeout": number;
}
export interface Permissions {
"player_sync.inventory.view": never;
}
}
export const plugin: lib.PluginDeclaration = {
name: "player_sync",
title: "Player sync",
description: "Synchronizes player inventories and settings between instances",
migrationEntrypoint: "dist/node/migrations.js",
instanceEntrypoint: "dist/node/instance.js",
instanceConfigFields: {
"player_sync.rcon_chunk_size": {
title: "Rcon inventory chunk size",
description:
"Divide inventories into chunks of this size before sending with rcon to prevent blocking the pipe",
type: "number",
initialValue: 1000,
},
"player_sync.sync_controller": {
title: "Sync controller",
description:
"Sync whether the player is a character, god or spectator, their respawn timer, cheat mode " +
"and god inventory. Only synced while inventories are synced too.",
type: "boolean",
initialValue: true,
},
"player_sync.sync_force": {
title: "Sync force",
description: "Sync the force the player is on.",
type: "boolean",
initialValue: true,
},
"player_sync.sync_appearance": {
title: "Sync appearance",
description: "Sync the player colour, chat colour and tag.",
type: "boolean",
initialValue: true,
},
"player_sync.sync_inventories": {
title: "Sync inventories",
description:
"Sync the character inventories, character bonuses and crafting queue. Without the " +
"controller synced a player without a character keeps their local inventory.",
type: "boolean",
initialValue: true,
},
"player_sync.sync_logistics": {
title: "Sync logistics",
description: "Sync the personal logistic requests.",
type: "boolean",
initialValue: true,
},
"player_sync.sync_quick_bar": {
title: "Sync quick bar",
description: "Sync the quick bar.",
type: "boolean",
initialValue: true,
},
"player_sync.sync_settings": {
title: "Sync settings",
description: "Sync the shortcut toggles, game view settings and flashlight.",
type: "boolean",
initialValue: true,
},
"player_sync.sync_recipe_notifications": {
title: "Sync recipe notifications",
description: "Sync which new recipe notifications have been seen.",
type: "boolean",
initialValue: true,
},
},
controllerEntrypoint: "dist/node/controller.js",
controllerConfigFields: {
"player_sync.player_lock_timeout": {
title: "Player Lock Timeout",
description:
"Time in seconds before the lock on a player inventory expires after an instance stops " +
"or is disconnected",
type: "number",
initialValue: 60,
},
},
features: [
"SavePatching",
"ScriptCommands",
],
messages: [
messages.AcquireRequest,
messages.ReleaseRequest,
messages.UploadRequest,
messages.DownloadRequest,
messages.DatabaseStatsRequest,
],
permissions: [
{
name: "player_sync.inventory.view",
title: "View player inventories",
description: "View player inventories",
grantByDefault: true,
},
],
webEntrypoint: "./web",
routes: ["/inventory"],
};