mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
Cache save details on the controller
Keep a copy of the instance saves details on the controller so that saves can be queried even when the host is disconnected and the controller can properly track and provide updates on the saves to its clients.
This commit is contained in:
1 parent
d186f85773
commit
a2914bda33
13 files changed
+219
-66
No files matched your search
@@ -228,7 +228,7 @@ export default class Instance extends lib.Link {
|
||||
this.handle(lib.InstanceMetricsRequest, this.handleInstanceMetricsRequest.bind(this));
|
||||
this.handle(lib.InstanceStartRequest, this.handleInstanceStartRequest.bind(this));
|
||||
this.handle(lib.InstanceLoadScenarioRequest, this.handleInstanceLoadScenarioRequest.bind(this));
|
||||
this.handle(lib.InstanceListSavesRequest, this.handleInstanceListSavesRequest.bind(this));
|
||||
this.handle(lib.InstanceSaveDetailsListRequest, this.handleInstanceSaveDetailsListRequest.bind(this));
|
||||
this.handle(lib.InstanceCreateSaveRequest, this.handleInstanceCreateSaveRequest.bind(this));
|
||||
this.handle(lib.InstanceExportDataRequest, this.handleInstanceExportDataRequest.bind(this));
|
||||
this.handle(lib.InstanceStopRequest, this.handleInstanceStopRequest.bind(this));
|
||||
@@ -374,7 +374,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
||||
}
|
||||
}
|
||||
|
||||
static async listSaves(savesDir: string, loadedSave: string | null) {
|
||||
static async listSaves(instanceId: number, savesDir: string, loadedSave: string | null) {
|
||||
let defaultSave = null;
|
||||
if (loadedSave === null) {
|
||||
defaultSave = await lib.getNewestFile(
|
||||
@@ -395,12 +395,14 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
||||
}
|
||||
|
||||
list.push(new lib.SaveDetails(
|
||||
instanceId,
|
||||
type,
|
||||
name,
|
||||
stat.size,
|
||||
stat.mtimeMs,
|
||||
name === loadedSave,
|
||||
name === defaultSave,
|
||||
false,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -410,9 +412,9 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
||||
async sendSaveListUpdate() {
|
||||
this.sendTo(
|
||||
"controller",
|
||||
new lib.InstanceSaveListUpdateEvent(
|
||||
new lib.InstanceSaveDetailsUpdatesEvent(
|
||||
await Instance.listSaves(this.id, this.path("saves"), this._loadedSave),
|
||||
this.id,
|
||||
await Instance.listSaves(this.path("saves"), this._loadedSave),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1034,8 +1036,8 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
||||
}
|
||||
}
|
||||
|
||||
async handleInstanceListSavesRequest() {
|
||||
return await Instance.listSaves(this.path("saves"), this._loadedSave);
|
||||
async handleInstanceSaveDetailsListRequest() {
|
||||
return await Instance.listSaves(this.id, this.path("saves"), this._loadedSave);
|
||||
}
|
||||
|
||||
async handleInstanceCreateSaveRequest(request: lib.InstanceCreateSaveRequest) {
|
||||
|
||||
Reference in new issue
Block a user