diff --git a/packages/lib/src/config/definitions.ts b/packages/lib/src/config/definitions.ts index b39d2ef4..cdfa7d0f 100644 --- a/packages/lib/src/config/definitions.ts +++ b/packages/lib/src/config/definitions.ts @@ -157,6 +157,7 @@ export class ControllerConfig extends classes.Config { get(name: "controller.proxy_stream_timeout"): number; get(name: "controller.default_mod_pack_id"): number | null; get(name: "controller.default_role_id"): number | null; + get(name: string): unknown; get(name: string) { return super.get(name); } @@ -262,6 +263,7 @@ export class HostConfig extends classes.Config { get(name: "host.tls_ca"): string | null; get(name: "host.public_address"): string; get(name: "host.max_reconnect_delay"): number; + get(name: string): unknown; get(name: string) { return super.get(name); } @@ -450,6 +452,7 @@ export class InstanceConfig extends classes.Config { get(name: "factorio.sync_whitelist"): boolean; get(name: "factorio.sync_banlist"): boolean; get(name: "factorio.max_concurrent_commands"): number; + get(name: string): unknown; get(name: string) { return super.get(name); } diff --git a/plugins/inventory_sync/instance.ts b/plugins/inventory_sync/instance.ts index c460e339..5927e6fd 100644 --- a/plugins/inventory_sync/instance.ts +++ b/plugins/inventory_sync/instance.ts @@ -1,5 +1,5 @@ import * as lib from "@clusterio/lib"; -import { AcquireRequest, ReleaseRequest, UploadRequest, DownloadRequest } from "./messages"; +import { AcquireRequest, AcquireResponse, ReleaseRequest, UploadRequest, DownloadRequest, DownloadResponse } from "./messages"; type IpcPlayerName = { player_name: string @@ -22,6 +22,14 @@ export type IpcPlayerData = { //.\module\serialize.lua:serialize.serialize_playe crafting_queue?: any, } +type IpcAcquireResponse = { + player_name: string, + status: string, + generation?: number, + has_data?: boolean, + message?: string, +} + /** * Splits string into array of strings with max of a certain length * @param chunkSize - Max length of each chunk @@ -64,7 +72,10 @@ export class InstancePlugin extends lib.BaseInstancePlugin { return; } this.playersToRelease.delete(player_name); - await this.instance.sendTo("controller", new ReleaseRequest(this.instance.id, player_name)); + await this.instance.sendTo( + "controller", + new ReleaseRequest(this.instance.id, player_name) + ); } })().catch( err => this.logger.error(`Unpexpected error releasing queued up players:\n${err.stack}`) @@ -73,17 +84,17 @@ export class InstancePlugin extends lib.BaseInstancePlugin { } async handleAcquire(request: IpcPlayerName) { - let response = { + let response: IpcAcquireResponse = { player_name: request.player_name, status: "error", message: "Controller is temporarily unavailable", - generation: undefined, has_data: undefined, + generation: undefined, }; if (this.host.connector.connected && !this.disconnecting) { try { - let acquireResponse = await this.instance.sendTo( + let acquireResponse: AcquireResponse = await this.instance.sendTo( "controller", new AcquireRequest(this.instance.id, request.player_name), ); @@ -112,7 +123,10 @@ export class InstancePlugin extends lib.BaseInstancePlugin { } try { - await this.instance.sendTo("controller", new ReleaseRequest(this.instance.id, request.player_name)); + await this.instance.sendTo( + "controller", + new ReleaseRequest(this.instance.id, request.player_name) + ); } catch (err: any) { if (err instanceof lib.SessionLost) { this.playersToRelease.add(request.player_name); @@ -150,15 +164,18 @@ export class InstancePlugin extends lib.BaseInstancePlugin { const playerName = request.player_name; this.logger.verbose(`Downloading ${playerName}`); - let response = await this.instance.sendTo("controller", new DownloadRequest(this.instance.id, playerName)); + let response: DownloadResponse = await this.instance.sendTo( + "controller", + new DownloadRequest(this.instance.id, playerName) + ); - if (!response.player_data) { + if (!response.playerData) { await this.sendRcon(`/sc inventory_sync.download_inventory('${playerName}',nil,0,0)`, true); return; } - const chunkSize = this.instance.config.get("inventory_sync.rcon_chunk_size"); - const chunks = chunkify(chunkSize, JSON.stringify(response.player_data)); + const chunkSize = this.instance.config.get("inventory_sync.rcon_chunk_size") as number; + const chunks = chunkify(chunkSize, JSON.stringify(response.playerData)); this.logger.verbose(`Sending inventory for ${playerName} in ${chunks.length} chunks`); for (let i = 0; i < chunks.length; i++) { // this.logger.verbose(`Sending chunk ${i+1} of ${chunks.length}`) diff --git a/plugins/inventory_sync/messages.ts b/plugins/inventory_sync/messages.ts index 8eb7f390..251c8d7c 100644 --- a/plugins/inventory_sync/messages.ts +++ b/plugins/inventory_sync/messages.ts @@ -8,7 +8,7 @@ const jsonPlayerData = Type.Object({ name: Type.String(), }) -class AcquireResponse { +export class AcquireResponse { constructor( public status: string, public generation?: number, @@ -100,7 +100,7 @@ export class UploadRequest { } } -class DownloadResponse { +export class DownloadResponse { constructor( public playerData: IpcPlayerData | null ) { diff --git a/plugins/inventory_sync/tsconfig.json b/plugins/inventory_sync/tsconfig.json index 5408f6b2..cf0cf5e6 100644 --- a/plugins/inventory_sync/tsconfig.json +++ b/plugins/inventory_sync/tsconfig.json @@ -11,6 +11,7 @@ "strict": true, "alwaysStrict": true, "esModuleInterop": true, + "resolveJsonModule": true, "skipLibCheck": true } }