fix(chess): admin users and move registration
Some checks failed
Deploy to Production / test (push) Failing after 29s

- Add role field to JOIN_ROOM message schema
- Allow admin users to join rooms and be added as players
- Update panel to pass user role when joining game rooms
- Fix chess move coordinates in tests (algebraic notation)
- Ensure admin users can make moves for both sides
This commit is contained in:
syntaxbullet
2026-04-02 15:27:56 +02:00
parent 9c4da51cfb
commit e521d3086f
6 changed files with 12 additions and 16 deletions

View File

@@ -82,7 +82,7 @@ function AppRoutes() {
{/* Game routes (both roles) */}
<Route path="/games" element={<GameLobby />} />
<Route path="/:gameSlug/:roomId" element={<GameRoom userId={user.discordId} />} />
<Route path="/:gameSlug/:roomId" element={<GameRoom userId={user.discordId} role={user.role} />} />
{/* Admin routes */}
{user.role === "admin" && (

View File

@@ -4,13 +4,13 @@ import { gameUIRegistry } from "./registry";
import { Loader2 } from "lucide-react";
import "./chess";
export function GameRoom({ userId }: { userId: string }) {
export function GameRoom({ userId, role }: { userId: string; role?: string }) {
const { gameSlug, roomId } = useParams<{ gameSlug: string; roomId: string }>();
const navigate = useNavigate();
const {
gameState, players, spectators, roomStatus,
isSpectator, gameOver, error, sendAction, leaveRoom,
} = useGameRoom(roomId!, userId);
} = useGameRoom(roomId!, userId, role);
const plugin = gameSlug ? gameUIRegistry.get(gameSlug) : undefined;

View File

@@ -16,7 +16,7 @@ interface GameRoomState {
error: string | null;
}
export function useGameRoom(roomId: string, userId: string) {
export function useGameRoom(roomId: string, userId: string, role?: string) {
const { send, subscribe, connected } = useWebSocket();
const [state, setState] = useState<GameRoomState>({
gameState: null,
@@ -31,7 +31,7 @@ export function useGameRoom(roomId: string, userId: string) {
useEffect(() => {
if (!connected) return;
send({ type: "JOIN_ROOM", roomId, as: "player" });
send({ type: "JOIN_ROOM", roomId, as: "player", role: role ?? "player" });
const unsubscribe = subscribe((msg: any) => {
if (msg.roomId && msg.roomId !== roomId) return;