diff --git a/client/gui/title_screen.ts b/client/gui/title_screen.ts index d360ac0..acc13d4 100644 --- a/client/gui/title_screen.ts +++ b/client/gui/title_screen.ts @@ -244,12 +244,12 @@ function has_singleplayer() { return new URL(location.href).searchParams.has("singleplayer"); } -// the desktop app's build for the os the browser is on, next to the page in dist/. everything that isn't windows +// the desktop app's build for the os the browser is on, which the server has in /dist/, see DESKTOP_DOWNLOADS. everything that isn't windows // gets linux's function download_os() { return /windows/i.test(navigator.userAgent) - ? { name: "Windows", file: "dist/windows.zip" } - : { name: "Linux", file: "dist/linux.zip" }; + ? { name: "Windows", file: "/dist/windows.zip" } + : { name: "Linux", file: "/dist/linux.zip" }; } function download_desktop_app() { diff --git a/server/host.ts b/server/host.ts index a580c19..b70bdc2 100644 --- a/server/host.ts +++ b/server/host.ts @@ -1,6 +1,6 @@ // the part of a game server that has permissions: files and networking. the game itself runs in a worker with none. // server/main.ts runs it as a dedicated server, and the desktop app runs it for singleplayer -import { serveDir } from "@std/http/file-server"; +import { serveDir, serveFile } from "@std/http/file-server"; import { join } from "@std/path"; import { GameToHost, HostToGame } from "./game/host_protocol.ts"; import { load_bmods } from "./load_bmods.ts"; @@ -12,12 +12,16 @@ const MAX_MESSAGE_SIZE = 4096; export const ENGINE_TEXTURES_INDEX = "assets/textures/index.json"; const SHUTDOWN_TIMEOUT_MS = 5000; const DOWNLOAD_TIMEOUT_MS = 10_000; +// the desktop app's zips that deno task desktop-all makes, for the title screen's download button +export const DESKTOP_DOWNLOADS = ["windows.zip", "linux.zip"]; export interface HostOptions { // what deno task build made: the client and the engine's assets build_dir: string; // the .bmod files to load server_mods_dir: string; + // where DESKTOP_DOWNLOADS are, served at /dist/. without it there's nothing to download + dist_dir?: string; // the world's folder: level.json, and the blocks in region/ world_dir: string; seed?: string; @@ -170,6 +174,10 @@ export async function start_host(options: HostOptions): Promise { }, }); } + const desktop_download = url.pathname.match(/^\/dist\/([^/]+)$/)?.[1]; + if (options.dist_dir && desktop_download && DESKTOP_DOWNLOADS.includes(desktop_download)) { + return serveFile(req, join(options.dist_dir, desktop_download)); + } return serve_static(options.build_dir, req, url); }, diff --git a/server/main.ts b/server/main.ts index 7c10fa4..650037e 100644 --- a/server/main.ts +++ b/server/main.ts @@ -8,6 +8,7 @@ try { host = await start_host({ build_dir: Deno.env.get("BUILD_DIR") ?? "build", server_mods_dir: Deno.env.get("SERVER_MODS_DIR") ?? "server_mods", + dist_dir: Deno.env.get("DIST_DIR") ?? "dist", world_dir: Deno.env.get("WORLD_DIR") ?? "world", seed: Deno.env.get("SEED"), on_fatal(message) {