32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import type { ModData, ModListing } from "$/common/mod_loader.ts";
|
|
import type { WorldSave } from "./saves.ts";
|
|
|
|
// messages between server/main.ts (the host) and the game server worker
|
|
|
|
export type HostToGame =
|
|
| {
|
|
type: "init";
|
|
save: WorldSave;
|
|
default_seed: string;
|
|
// in load order, with the scripts' code since the worker can't read files
|
|
mods: { listing: ModListing; data: ModData; server_code?: string; worldgen_code?: string }[];
|
|
}
|
|
| { type: "connect"; conn: number }
|
|
| { type: "message"; conn: number; data: string }
|
|
| { type: "disconnect"; conn: number }
|
|
// save now and say when it's done, for shutting down
|
|
| { type: "shutdown" }
|
|
// answers download, with the bytes or why it failed
|
|
| { type: "downloaded"; id: number; bytes?: Uint8Array; error?: string };
|
|
|
|
export type GameToHost =
|
|
| { type: "ready"; seed: string }
|
|
| { type: "failed"; error: string }
|
|
// text is a json message, bytes a binary one
|
|
| { type: "send"; conn: number; data: string | Uint8Array<ArrayBuffer> }
|
|
| { type: "close"; conn: number }
|
|
// level.json and the chunks that changed
|
|
| { type: "save"; save: Required<WorldSave>; final: boolean }
|
|
// the worker can't use the network, so the host fetches urls for it, like skins
|
|
| { type: "download"; id: number; url: string; max_bytes: number };
|