d3/server/main.ts

37 lines
1 KiB
TypeScript
Executable file

#!/bin/env -S deno run --allow-net --allow-read
import { log_from, v2 } from "../common/utils.ts";
import { Engine } from "./engine.ts";
import { Session } from "./entities/player.ts";
import { sys_spawn_structure } from "./components/world.ts";
import { Gateway } from "./network.ts";
import { sys_spawn_enemy } from "./entities/enemy.ts";
import { enemy_plugin } from "./entities/enemy.ts";
const log = log_from(import.meta);
async function main() {
const args = parse_args(Deno.args);
log("Starting.");
const engine = new Engine();
enemy_plugin(engine);
engine.start();
engine.run(await sys_spawn_structure("../data/structures/houses.txt", v2(2, 2)));
engine.run(sys_spawn_enemy(v2(1, 1)));
const gateway = new Gateway(args.port);
log("Awaiting connection.");
for await (const client of gateway.accept()) {
Session.init(client, engine).start();
}
}
function parse_args(args: string[]) {
const [port_] = args;
let port = 9999;
if (port_ !== undefined) port = parseInt(port_);
return { port };
}
if (import.meta.main) await main();