From 87b66cd65d88c55757bf3866e0cf48a610274f80 Mon Sep 17 00:00:00 2001 From: syntaxbullet Date: Thu, 2 Apr 2026 14:24:23 +0200 Subject: [PATCH] feat(games): allow admins to play against themselves Skip the duplicate-player check when the joining user has the admin role, so admins can test games solo by joining their own room as both players. Co-Authored-By: Claude Opus 4.6 (1M context) --- api/src/games/RoomManager.ts | 4 ++-- api/src/games/ws-handler.ts | 3 ++- api/src/server.ts | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/src/games/RoomManager.ts b/api/src/games/RoomManager.ts index 5d66a0e..a332f25 100644 --- a/api/src/games/RoomManager.ts +++ b/api/src/games/RoomManager.ts @@ -33,7 +33,7 @@ export class RoomManager { return { ok: true, roomId: id }; } - joinRoom(roomId: string, playerId: string, as: "player" | "spectator"): JoinResult { + joinRoom(roomId: string, playerId: string, as: "player" | "spectator", role?: string): JoinResult { const room = this.rooms.get(roomId); if (!room) return { ok: false, error: "Room not found" }; @@ -46,7 +46,7 @@ export class RoomManager { const plugin = gameRegistry.get(room.gameSlug)!; if (room.players.length >= plugin.maxPlayers) return { ok: false, error: "Room is full" }; - if (room.players.includes(playerId)) return { ok: true, started: room.status === "playing" }; + if (room.players.includes(playerId) && role !== "admin") return { ok: true, started: room.status === "playing" }; room.players.push(playerId); diff --git a/api/src/games/ws-handler.ts b/api/src/games/ws-handler.ts index 3a7704c..57ea12a 100644 --- a/api/src/games/ws-handler.ts +++ b/api/src/games/ws-handler.ts @@ -7,6 +7,7 @@ export const roomManager = new RoomManager(); interface WsContext { playerId: string; username: string; + role: string; send: (data: string) => void; subscribe: (channel: string) => void; unsubscribe: (channel: string) => void; @@ -29,7 +30,7 @@ export function handleGameMessage(msg: GameWsClientMessage, ctx: WsContext): voi } case "JOIN_ROOM": { - const result = roomManager.joinRoom(msg.roomId, ctx.playerId, msg.as); + const result = roomManager.joinRoom(msg.roomId, ctx.playerId, msg.as, ctx.role); if (!result.ok) { ctx.send(JSON.stringify({ type: "ERROR", message: result.error })); return; diff --git a/api/src/server.ts b/api/src/server.ts index e8e0097..443d9a6 100644 --- a/api/src/server.ts +++ b/api/src/server.ts @@ -202,6 +202,7 @@ export async function createWebServer(config: WebServerConfig = {}): Promise ws.send(data), subscribe: (channel) => ws.subscribe(channel), unsubscribe: (channel) => ws.unsubscribe(channel),