47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
// a dedicated server: the host from server/host.ts on a port, saving the world when it's stopped
|
|
import { type Host, start_host } from "./host.ts";
|
|
|
|
const PORT = Number(Deno.env.get("PORT") ?? 8000);
|
|
|
|
let host: Host;
|
|
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"),
|
|
// leave it out for a few, 0 to generate on the game's thread
|
|
worldgen_workers: Deno.env.get("WORLDGEN_WORKERS") ? Number(Deno.env.get("WORLDGEN_WORKERS")) : undefined,
|
|
on_fatal(message) {
|
|
console.error(message);
|
|
Deno.exit(1);
|
|
},
|
|
});
|
|
} catch (e) {
|
|
console.error((e as Error).message);
|
|
Deno.exit(1);
|
|
}
|
|
|
|
async function shutdown() {
|
|
try {
|
|
await host.shutdown();
|
|
Deno.exit(0);
|
|
} catch (e) {
|
|
console.error((e as Error).message);
|
|
Deno.exit(1);
|
|
}
|
|
}
|
|
Deno.addSignalListener("SIGINT", shutdown);
|
|
if (Deno.build.os !== "windows") {
|
|
Deno.addSignalListener("SIGTERM", shutdown);
|
|
}
|
|
|
|
Deno.serve(
|
|
{ port: PORT, onListen: ({ port }) => console.log(`bworld server on http://localhost:${port}/`) },
|
|
host.handle,
|
|
);
|