add submit_actual_results WS handler with validation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 22:14:43 +01:00
parent c7a11e80d3
commit f390c21903

View File

@@ -378,6 +378,41 @@ export function registerWebSocketRoutes() {
break
}
case "submit_actual_results": {
if (!sessionId) {
sendError(ws, "Not joined")
return
}
const room = roomManager.getRoom(roomCode)
if (room?.currentAct !== "scoring" && room?.currentAct !== "ended") {
sendError(ws, "Results can only be entered during Scoring or Ended")
return
}
if (!roomManager.isHost(roomCode, sessionId)) {
sendError(ws, "Only the host can enter actual results")
return
}
const gm = roomManager.getGameManager(roomCode)
if (!gm) {
sendError(ws, "Room not found")
return
}
const allPicks = [msg.winner, msg.second, msg.third, msg.last]
for (const code of allPicks) {
if (!gm.isValidCountry(code)) {
sendError(ws, `Invalid country: ${code}`)
return
}
}
if (new Set(allPicks).size !== 4) {
sendError(ws, "All 4 picks must be different countries")
return
}
gm.setActualResults(msg.winner, msg.second, msg.third, msg.last)
broadcastGameStateToAll(roomCode)
break
}
case "tap_bingo_square": {
if (!sessionId) {
sendError(ws, "Not joined")