feat(game): add configurable rounds per room

This commit is contained in:
jessy-david-dev
2026-04-11 13:47:05 +02:00
parent d245232497
commit e9f39c572d
8 changed files with 175 additions and 114 deletions
+7 -2
View File
@@ -21,6 +21,7 @@ export type Room = {
phase: "waiting" | "countdown" | "playing" | "results";
round: number;
totalRounds: number;
maxPlayers: number;
startArticle: string;
targetArticle: string;
roundWinner: string | null; // player id
@@ -75,12 +76,15 @@ function pruneOldRooms(rooms: Map<string, Room>) {
// Response: { room: Room, playerId: string }
export async function POST(request: NextRequest) {
const body = await request.json();
const { playerName } = body as { playerName: string };
const { playerName, maxPlayers, totalRounds } = body as { playerName: string; maxPlayers?: number; totalRounds?: number };
if (!playerName || typeof playerName !== "string" || playerName.trim() === "") {
return Response.json({ error: "Pseudo invalide" }, { status: 400 });
}
const clampedMax = Math.min(Math.max(typeof maxPlayers === "number" ? Math.floor(maxPlayers) : 16, 2), 16);
const clampedRounds = Math.min(Math.max(typeof totalRounds === "number" ? Math.floor(totalRounds) : 3, 1), 10);
const rooms = getRooms();
pruneOldRooms(rooms);
@@ -109,7 +113,8 @@ export async function POST(request: NextRequest) {
],
phase: "waiting",
round: 0,
totalRounds: 3,
totalRounds: clampedRounds,
maxPlayers: clampedMax,
startArticle: "",
targetArticle: "",
roundWinner: null,