# DiscoveryServer Lightweight Node.js + WebSocket server for ZAMNY co-op matchmaking. **Responsibilities**: - Player registry + nicknames (max 16 chars) - List available players - Room creation / joining (2-player co-op) - Relay for initial handshake **No game logic** (AD-03). All simulation runs client-side. ## Quick Start ```bash npm install npm run dev # tsx watch, ws://localhost:3001 npm test # node:test via tsx npm run build npm start ``` ## WebSocket Protocol All messages are JSON objects with `type`. ### Client → Server - `{ "type": "set_nickname", "nickname": "Player1" }` - `{ "type": "list_players" }` - `{ "type": "join_room", "target": "p123" }` (TODO) ### Server → Client - `{ "type": "welcome", "id": "p1" }` - `{ "type": "nickname_ok", "nickname": "Player1" }` - `{ "type": "player_list", "players": [{ "id": "p2", "nickname": "ZomSlayer" }] }` - `{ "type": "error", "message": "..." }` ## Notes - Pure functions (`validateNickname`, `createRoomId`) are unit-tested. - Server only starts when run directly (not during tests). - Port 3001 (hardcoded for now). - See root [ARCHITECTURE.md](../ARCHITECTURE.md) for full design.