mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 23:14:53 +09:00
Merge pull request #503 from Luciole0x/inventory_sync-fix
fix inventory_sync plugin
This commit is contained in:
4 files changed
+33
-12
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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}`)
|
||||
|
||||
@@ -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
|
||||
) {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"strict": true,
|
||||
"alwaysStrict": true,
|
||||
"esModuleInterop": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user