Files
dflike/server/src/main.ts
T
root eb639bf562 feat(server): integrate persistence into GameLoop and main.ts
Wire SaveManager into game startup/shutdown: constructor now checks for
existing save file and loads or creates new world accordingly. Add
autosave every 30s, final save on stop, and graceful shutdown signals.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:34:03 +00:00

27 lines
761 B
TypeScript

import 'dotenv/config';
import http from 'http';
import { GameLoop } from './game/GameLoop.js';
import { SocketServer } from './network/SocketServer.js';
const PORT = process.env.PORT ? parseInt(process.env.PORT) : 3001;
const newWorld = process.argv.includes('--new-world');
const gameLoop = new GameLoop({ newWorld });
const httpServer = http.createServer();
new SocketServer(httpServer, gameLoop);
httpServer.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
gameLoop.start();
});
// Graceful shutdown
for (const signal of ['SIGINT', 'SIGTERM'] as const) {
process.on(signal, () => {
console.log(`\nReceived ${signal}, saving and shutting down...`);
gameLoop.stop();
httpServer.close();
process.exit(0);
});
}