Implements PROTOCOL.md's private-room flow: room:create/room:join with a collision-checked numeric code, up to a 5-match repeating series per room via game/session.js, random-theme selection that excludes the previous match's theme, and room:closed for matchLimit or quit (rooms never touch matchmaking's ban store). themeMode: 'chosen' gets a narrow resolveChosenTheme() stand-in pending #7's real theme-voting flow. Also adds a minimal opponentName lookup to registry.js (registerSocket's new optional name arg + getPlayerName) since room:joined needs it, mirroring the same addition landing on #5's branch.
30 lines
958 B
JavaScript
30 lines
958 B
JavaScript
import http from 'node:http';
|
|
import { WebSocketServer } from 'ws';
|
|
import { handleConnection } from './ws/connectionHandler.js';
|
|
import { registerMatchmakingHandlers } from './matchmaking/queue.js';
|
|
import { registerRoomHandlers } from './rooms/room.js';
|
|
|
|
const PORT = process.env.PORT || 8080;
|
|
|
|
registerMatchmakingHandlers();
|
|
|
|
const server = http.createServer((req, res) => {
|
|
if (req.url === '/health') {
|
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
res.end(JSON.stringify({ status: 'ok' }));
|
|
return;
|
|
}
|
|
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
res.end('Not found');
|
|
});
|
|
|
|
// The WebSocket server shares the HTTP server's port via the upgrade
|
|
// handshake, so one process serves both plain HTTP and `ws://`.
|
|
const wss = new WebSocketServer({ server });
|
|
wss.on('connection', handleConnection);
|
|
|
|
registerRoomHandlers();
|
|
|
|
server.listen(PORT, () => {
|
|
console.log(`Matchmaking server listening on :${PORT}`);
|
|
});
|