mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
Forward player data to the instance a player is switching to
An upload can carry destinationInstanceId. Once the upload is stored, the controller sends the stored data, the upload merged with its copy, in a PrefetchEvent to that instance, if it is another running instance with player_sync enabled. No lock is taken or released. A failed send is logged and doesn't fail the upload. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
4128f75328
commit
b8c1e89dff
4 files changed
+124
-2
No files matched your search
@@ -29,6 +29,7 @@ export type IpcPlayerData = {
|
||||
recipe_notifications?: string,
|
||||
// Components the upload was serialized with, all when missing
|
||||
components?: Record<string, boolean> | unknown[],
|
||||
destination_instance_id?: number, // set_destination's instance, on the leave upload only; not player data
|
||||
}
|
||||
|
||||
// Marks tombstones in player_sync.json
|
||||
@@ -268,6 +269,7 @@ export class UploadRequest {
|
||||
public instanceId: number,
|
||||
public playerName: string,
|
||||
public playerData: IpcPlayerData,
|
||||
public destinationInstanceId?: number,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -275,10 +277,33 @@ export class UploadRequest {
|
||||
"instanceId": Type.Integer(),
|
||||
"playerName": Type.String(),
|
||||
"playerData": jsonPlayerData,
|
||||
"destinationInstanceId": Type.Optional(Type.Integer()),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof UploadRequest.jsonSchema>) {
|
||||
return new this(json.instanceId, json.playerName, json.playerData as IpcPlayerData);
|
||||
return new this(json.instanceId, json.playerName, json.playerData as IpcPlayerData, json.destinationInstanceId);
|
||||
}
|
||||
}
|
||||
|
||||
/** The stored data of a player switching to the instance it is sent to, so the join there needs no download */
|
||||
export class PrefetchEvent {
|
||||
declare ["constructor"]: typeof PrefetchEvent;
|
||||
static type = "event" as const;
|
||||
static src = "controller" as const;
|
||||
static dst = "instance" as const;
|
||||
static plugin = "player_sync" as const;
|
||||
|
||||
constructor(
|
||||
public playerData: IpcPlayerData,
|
||||
) {
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"playerData": jsonPlayerData,
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof PrefetchEvent.jsonSchema>): PrefetchEvent {
|
||||
return new this(json.playerData as IpcPlayerData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user