feat(lobby): allow up to 100 players per room

This commit is contained in:
jessy-david-dev
2026-04-15 19:26:50 +02:00
parent 2dc57915be
commit 6ba0df304f
6 changed files with 34 additions and 4 deletions
+16
View File
@@ -371,6 +371,22 @@ export async function PATCH(
return Response.json({ room }); return Response.json({ room });
} }
// Hôte change le nombre de joueurs max
case "setMaxPlayers": {
const host = room.players.find((p) => p.id === playerId);
if (!host?.isHost) {
return Response.json(
{ error: "Seul l'hôte peut modifier ce paramètre" },
{ status: 403 },
);
}
if (typeof value === "number") {
room.maxPlayers = Math.min(Math.max(Math.floor(value), 2), 100);
await saveRoom(room);
}
return Response.json({ room });
}
// Hôte change le nombre de manches // Hôte change le nombre de manches
case "setTotalRounds": { case "setTotalRounds": {
const host = room.players.find((p) => p.id === playerId); const host = room.players.find((p) => p.id === playerId);
+1 -1
View File
@@ -117,7 +117,7 @@ export async function POST(request: NextRequest) {
const clampedMax = Math.min( const clampedMax = Math.min(
Math.max(typeof maxPlayers === "number" ? Math.floor(maxPlayers) : 16, 2), Math.max(typeof maxPlayers === "number" ? Math.floor(maxPlayers) : 16, 2),
16, 100,
); );
const clampedRounds = Math.min( const clampedRounds = Math.min(
Math.max(typeof totalRounds === "number" ? Math.floor(totalRounds) : 3, 1), Math.max(typeof totalRounds === "number" ? Math.floor(totalRounds) : 3, 1),
+4 -2
View File
@@ -20,6 +20,7 @@ type LobbyScreenProps = {
setGameMode: (v: Room["gameMode"]) => void; setGameMode: (v: Room["gameMode"]) => void;
onSetGameMode: (v: Room["gameMode"]) => void; onSetGameMode: (v: Room["gameMode"]) => void;
onSetTotalRounds: (v: number) => void; onSetTotalRounds: (v: number) => void;
onSetMaxPlayers: (v: number) => void;
onSetSearchAllowed: (v: boolean) => void; onSetSearchAllowed: (v: boolean) => void;
onSetTimeLimit: (v: number) => void; onSetTimeLimit: (v: number) => void;
}; };
@@ -41,6 +42,7 @@ export function LobbyScreen({
setGameMode, setGameMode,
onSetGameMode, onSetGameMode,
onSetTotalRounds, onSetTotalRounds,
onSetMaxPlayers,
onSetSearchAllowed, onSetSearchAllowed,
onSetTimeLimit, onSetTimeLimit,
}: LobbyScreenProps) { }: LobbyScreenProps) {
@@ -171,10 +173,10 @@ export function LobbyScreen({
<span className="text-xs text-[#888]">Joueurs max</span> <span className="text-xs text-[#888]">Joueurs max</span>
<select <select
value={maxPlayers} value={maxPlayers}
onChange={(e) => { setMaxPlayers(Number(e.target.value)); }} onChange={(e) => { const v = Number(e.target.value); setMaxPlayers(v); onSetMaxPlayers(v); }}
className="w-full min-h-11 px-2 bg-[#0f0f0f] border border-[#2e2e2e] rounded-xl text-sm text-[#f0f0f0] outline-none focus:border-[#7c3aed] cursor-pointer transition-colors" className="w-full min-h-11 px-2 bg-[#0f0f0f] border border-[#2e2e2e] rounded-xl text-sm text-[#f0f0f0] outline-none focus:border-[#7c3aed] cursor-pointer transition-colors"
> >
{[2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16].map((n) => ( {[2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 25, 30, 40, 50, 75, 100].map((n) => (
<option key={n} value={n}> <option key={n} value={n}>
{n} joueurs {n} joueurs
</option> </option>
+1
View File
@@ -160,6 +160,7 @@ export function ScreenRouter({
setGameMode={setGameMode} setGameMode={setGameMode}
onSetGameMode={(v) => multi.setGameMode(v)} onSetGameMode={(v) => multi.setGameMode(v)}
onSetTotalRounds={(v) => multi.setTotalRounds(v)} onSetTotalRounds={(v) => multi.setTotalRounds(v)}
onSetMaxPlayers={(v) => multi.setMaxPlayers(v)}
onSetSearchAllowed={(v) => multi.setSearchAllowed(v)} onSetSearchAllowed={(v) => multi.setSearchAllowed(v)}
onSetTimeLimit={(v) => multi.setTimeLimit(v)} onSetTimeLimit={(v) => multi.setTimeLimit(v)}
/> />
+1 -1
View File
@@ -12,7 +12,7 @@ export default function WikiRush() {
const [screen, setScreen] = useState<Screen>("home"); const [screen, setScreen] = useState<Screen>("home");
const [playerName, setPlayerName] = useState(""); const [playerName, setPlayerName] = useState("");
const [joinCode, setJoinCode] = useState(""); const [joinCode, setJoinCode] = useState("");
const [maxPlayers, setMaxPlayers] = useState(16); const [maxPlayers, setMaxPlayers] = useState(100);
const [totalRounds, setTotalRounds] = useState(3); const [totalRounds, setTotalRounds] = useState(3);
const [gameMode, setGameMode] = useState<"race" | "all_finish">("race"); const [gameMode, setGameMode] = useState<"race" | "all_finish">("race");
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
+11
View File
@@ -430,6 +430,16 @@ export function useMultiGame() {
if (res.ok) setRoom(((await res.json()) as { room: Room }).room); if (res.ok) setRoom(((await res.json()) as { room: Room }).room);
} }
async function setMaxPlayers(value: number) {
if (!room || !playerId) return;
const res = await fetch(`/api/rooms/${room.code}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action: "setMaxPlayers", playerId, value }),
});
if (res.ok) setRoom(((await res.json()) as { room: Room }).room);
}
async function setSearchAllowed(value: boolean) { async function setSearchAllowed(value: boolean) {
if (!room || !playerId) return; if (!room || !playerId) return;
const res = await fetch(`/api/rooms/${room.code}`, { const res = await fetch(`/api/rooms/${room.code}`, {
@@ -529,6 +539,7 @@ export function useMultiGame() {
timeLeft, timeLeft,
setGameMode, setGameMode,
setTotalRounds, setTotalRounds,
setMaxPlayers,
setTimeLimit, setTimeLimit,
setSearchAllowed, setSearchAllowed,
restore, restore,