Add inspect and modify tools for player sync

Admins had no way to look at or fix the player data the controller
stores when a sync went wrong. The web page now lists every stored
entry with its generation, size and the instance holding the lock, and
opens a drawer per player with an inventory summary, JSON export and
import, delete and lock release. The same operations are exposed as
clusterioctl player-sync commands.

Import bumps the generation past the stored one so instances holding an
older copy download the new data on the next join. Import and delete
are refused while an instance holds the lock, since its upload on leave
would undo the change. A new player_sync.inventory.modify permission
gates the write operations.

Closes #1003

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Fable 5.1 committed 2026-10-17 18:52:29 +00:00
1 parent 5e2ecdd143
commit a81d98e981
12 files changed
+953 -22

No files matched your search

+156 -1
View File
@@ -1,5 +1,5 @@
import { Type, Static } from "@sinclair/typebox";
import { StringEnum } from "@clusterio/lib";
import { StringEnum, jsonArray } from "@clusterio/lib";
// .\module\serialize.lua:serialize.serialize_player()
export type IpcPlayerData = {
@@ -193,3 +193,158 @@ export class DatabaseStatsRequest {
static permission = "player_sync.inventory.view" as const;
static Response = DatabaseStatsResponse;
}
export class PlayerEntry {
constructor(
public name: string,
public generation?: number,
public size?: number,
public instanceId?: number,
) {
}
static jsonSchema = Type.Object({
"name": Type.String(),
"generation": Type.Optional(Type.Integer()),
"size": Type.Optional(Type.Integer()),
"instanceId": Type.Optional(Type.Integer()),
});
static fromJSON(json: Static<typeof PlayerEntry.jsonSchema>): PlayerEntry {
return new this(json.name, json.generation, json.size, json.instanceId);
}
}
export class ListPlayersRequest {
declare ["constructor"]: typeof ListPlayersRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static plugin = "player_sync" as const;
static permission = "player_sync.inventory.view" as const;
static Response = jsonArray(PlayerEntry);
}
export class GetPlayerDataResponse {
constructor(
public playerData: IpcPlayerData | null,
public instanceId?: number,
) {
}
static jsonSchema = Type.Object({
"playerData": Type.Union([jsonPlayerData, Type.Null()]),
"instanceId": Type.Optional(Type.Integer()),
});
static fromJSON(json: Static<typeof GetPlayerDataResponse.jsonSchema>): GetPlayerDataResponse {
return new this(json.playerData as IpcPlayerData | null, json.instanceId);
}
}
export class GetPlayerDataRequest {
declare ["constructor"]: typeof GetPlayerDataRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static plugin = "player_sync" as const;
static permission = "player_sync.inventory.view" as const;
static Response = GetPlayerDataResponse;
constructor(
public playerName: string,
) {
}
static jsonSchema = Type.Object({
"playerName": Type.String(),
});
static fromJSON(json: Static<typeof GetPlayerDataRequest.jsonSchema>) {
return new this(json.playerName);
}
}
export class SetPlayerDataResponse {
constructor(
public generation: number,
) {
}
static jsonSchema = Type.Object({
"generation": Type.Integer(),
});
static fromJSON(json: Static<typeof SetPlayerDataResponse.jsonSchema>): SetPlayerDataResponse {
return new this(json.generation);
}
}
export class SetPlayerDataRequest {
declare ["constructor"]: typeof SetPlayerDataRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static plugin = "player_sync" as const;
static permission = "player_sync.inventory.modify" as const;
static Response = SetPlayerDataResponse;
constructor(
public playerName: string,
public playerData: IpcPlayerData,
) {
}
static jsonSchema = Type.Object({
"playerName": Type.String(),
"playerData": jsonPlayerData,
});
static fromJSON(json: Static<typeof SetPlayerDataRequest.jsonSchema>) {
return new this(json.playerName, json.playerData as IpcPlayerData);
}
}
export class DeletePlayerDataRequest {
declare ["constructor"]: typeof DeletePlayerDataRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static plugin = "player_sync" as const;
static permission = "player_sync.inventory.modify" as const;
constructor(
public playerName: string,
) {
}
static jsonSchema = Type.Object({
"playerName": Type.String(),
});
static fromJSON(json: Static<typeof DeletePlayerDataRequest.jsonSchema>) {
return new this(json.playerName);
}
}
export class ForceReleaseRequest {
declare ["constructor"]: typeof ForceReleaseRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static plugin = "player_sync" as const;
static permission = "player_sync.inventory.modify" as const;
constructor(
public playerName: string,
) {
}
static jsonSchema = Type.Object({
"playerName": Type.String(),
});
static fromJSON(json: Static<typeof ForceReleaseRequest.jsonSchema>) {
return new this(json.playerName);
}
}