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); }); }