Skip to content

Commit 179cf84

Browse files
feat: Operators
1 parent e2de2fb commit 179cf84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4506
-119
lines changed

packages/kitten-analysts/examples/a708b0ad-5f94-4466-8a2e-1d381117d0e0.json

+1-1
Large diffs are not rendered by default.

packages/kitten-analysts/examples/ka-internal-savestate.json

+1-1
Large diffs are not rendered by default.

packages/kitten-analysts/source/entrypoint-backend.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { isNil } from "@oliversalzburg/js-utils/data/nil.js";
44
import { redirectErrorsToConsole } from "@oliversalzburg/js-utils/errors/console.js";
55
import Koa from "koa";
66
import Router from "koa-router";
7+
import { compressToUTF16, decompressFromUTF16 } from "lz-string";
78
import { writeFileSync } from "node:fs";
89
import { readdir, readFile } from "node:fs/promises";
910
import { join } from "node:path";
@@ -12,6 +13,7 @@ import {
1213
KGNetSaveFromGame,
1314
KGNetSavePersisted,
1415
KGNetSaveUpdate,
16+
KGSaveData,
1517
LOCAL_STORAGE_PATH,
1618
} from "./globals.js";
1719
import {
@@ -216,12 +218,17 @@ routerNetwork.post("/kgnet/save/upload", context => {
216218
saveStore.set(gameGUID, savegame);
217219
writeFileSync(`${LOCAL_STORAGE_PATH}/${gameGUID}.json`, JSON.stringify(savegame));
218220

221+
// Rebuild payload to also contain the fixed-string telemetry GUID.
222+
const uncompressed = JSON.parse(decompressFromUTF16(gameSave.saveData)) as KGSaveData;
223+
uncompressed.telemetry.guid = "ka-internal-savestate";
224+
const recompressedSaveData = compressToUTF16(JSON.stringify(uncompressed));
225+
219226
const savegameEphemeral: KGNetSavePersisted = {
220227
archived: false,
221228
guid: "ka-internal-savestate",
222229
index: { calendar: { day: calendar.day, year: calendar.year } },
223230
label: "Background Game",
224-
saveData: gameSave.saveData,
231+
saveData: recompressedSaveData,
225232
size: context.request.length,
226233
timestamp: Date.now(),
227234
};

packages/kitten-analysts/source/globals.ts

+21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@ export const LOCAL_STORAGE_PATH = "/local_storage";
22

33
// KGNet Savegame Storage
44

5+
export interface KGSaveData {
6+
saveVersion: number;
7+
resources: unknown;
8+
telemetry: {
9+
guid: string;
10+
};
11+
game: {
12+
forceShowLimits: unknown;
13+
isCMBREnabled: unknown;
14+
useWorkers: unknown;
15+
colorScheme: unknown;
16+
unlockedSchemes: unknown;
17+
karmaKittens: unknown;
18+
karmaZebras: unknown;
19+
ironWill: unknown;
20+
deadKittens: unknown;
21+
cheatMode: unknown;
22+
opts: unknown;
23+
lastBackup: unknown;
24+
};
25+
}
526
export interface KGNetSaveFromGame {
627
guid: string;
728
metadata: {

packages/kitten-analysts/source/network/KittensGameRemote.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ export class KittensGameRemote {
201201
console.debug(`<= ${identifyExchange(message)}...`);
202202

203203
const request = new Promise<KittenAnalystsMessage<TMessage> | null>((resolve, reject) => {
204-
if (!socket.isAlive || socket.ws.readyState === WebSocket.CLOSED) {
204+
if (
205+
!socket.isAlive ||
206+
socket.ws.readyState === WebSocket.CLOSED ||
207+
socket.ws.readyState === WebSocket.CLOSING
208+
) {
205209
console.warn("Send request can't be handled, because socket is dead!");
206210
socket.isAlive = false;
207211
resolve(null);

0 commit comments

Comments
 (0)