mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 07:24:53 +09:00
Close the remaining ways an accepted import fails to restore
Imports no longer accept the cutscene controller, which needs waypoints to restore. Logistic filters and the basic item stack fields now have the types and limits Factorio enforces, and the inventory summary skips malformed items and counts repeated exported items once instead of expanding them. Lua's JSON loses precision past 2^50, so a generation there could no longer be counted up and uploads were discarded. Imports now start over from generation 1 when the stored or imported generation is at that limit. Instances holding a copy from another epoch take the stored generation instead of keeping their own higher one when there is no data to download. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9ecd497f1e
commit
39df22be65
6 files changed
+167
-20
No files matched your search
@@ -28,15 +28,17 @@ export type InventorySummary = {
|
||||
export function summarizeInventory(inventory: SerializedInventory): ItemSummary[] {
|
||||
let items: ItemSummary[] = [];
|
||||
let stacks = new Map<string, ItemSummary>();
|
||||
for (let entry of Object.values(inventory.i ?? [])) {
|
||||
let repeat = (entry.r ?? 0) + 1;
|
||||
if (entry.e !== undefined) {
|
||||
for (let i = 0; i < repeat; i++) {
|
||||
items.push({ name: "exported item", count: 1, exportSize: entry.e.length });
|
||||
}
|
||||
for (let entry of Object.values(inventory?.i ?? [])) {
|
||||
// Uploads are not validated as strictly as imports
|
||||
if (typeof entry !== "object" || entry === null) {
|
||||
continue;
|
||||
}
|
||||
if (entry.n === undefined) {
|
||||
let repeat = Number.isInteger(entry.r) ? entry.r! + 1 : 1;
|
||||
if (typeof entry.e === "string") {
|
||||
items.push({ name: "exported item", count: repeat, exportSize: entry.e.length });
|
||||
continue;
|
||||
}
|
||||
if (typeof entry.n !== "string") {
|
||||
continue;
|
||||
}
|
||||
let key = `${entry.n}\0${entry.q ?? ""}`;
|
||||
@@ -46,7 +48,7 @@ export function summarizeInventory(inventory: SerializedInventory): ItemSummary[
|
||||
stacks.set(key, stack);
|
||||
items.push(stack);
|
||||
}
|
||||
stack.count += (entry.c ?? 0) * repeat;
|
||||
stack.count += (typeof entry.c === "number" ? entry.c : 0) * repeat;
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user