Files
joke-app/packages/shared/src/protocol.ts
EJClaw 2ec622ebf6 방 설정 "컴퓨터 채팅": 컴퓨터가 혼자 말하는 건 방장이 켤 때만(기본 끄기), 마피아는 항상 켜짐
- RoomConfig/RoomView.botChat, config 메시지에 botChat. 새 방·옛 방 모두 끄기.
- BotBrain: 꺼져 있으면 도발·반응·대답·시작 인사·끝 인사 안 함, 모델 미리 올리기도 안 함.
  바퀴벌레 포커 진짜/블러핑 판단은 그대로, 한마디만 뺌.
- BOT_CHAT_REQUIRED(마피아): 설정과 상관없이 항상 켜짐, 설정 칸에 "항상 켜짐" 표시.
- 대기실 설정에 컴퓨터 채팅 켜기/끄기(컴퓨터 상대가 있는 게임만).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 21:59:30 +09:00

46 lines
2.1 KiB
TypeScript

/** WebSocket protocol client→server schema (zod; server-side validation), docs/03-realtime-protocol.md. */
import { z } from 'zod';
import { CHAT_MAX } from './types';
export * from './types';
const code = z.string().regex(/^\d{6}$/);
const userId = z.string().min(1).max(64);
export const ClientMessage = z.discriminatedUnion('t', [
z.object({ t: z.literal('join'), code, as: z.enum(['player', 'spectator']).default('player') }),
z.object({ t: z.literal('leave') }),
/** Left the room page without leaving the room: seat kept, no more room messages until the next join. */
z.object({ t: z.literal('detach') }),
z.object({ t: z.literal('seat'), seat: z.number().int().min(0).max(31).optional() }),
z.object({ t: z.literal('unseat') }),
z.object({ t: z.literal('ready'), ready: z.boolean() }),
z.object({
t: z.literal('config'),
gameId: z.string().max(40).optional(),
options: z.unknown().optional(),
maxPlayers: z.number().int().min(1).max(32).optional(),
visibility: z.enum(['private', 'public']).optional(),
turnSeconds: z.number().int().min(5).max(600).nullable().optional(),
allowSpectators: z.boolean().optional(),
chatEnabled: z.boolean().optional(),
chatFilter: z.boolean().optional(),
botChat: z.boolean().optional(),
}),
z.object({ t: z.literal('start') }),
z.object({ t: z.literal('kick'), userId }),
z.object({ t: z.literal('host'), userId }),
z.object({ t: z.literal('addBot'), seat: z.number().int().min(0).max(31).optional() }),
z.object({ t: z.literal('removeBot'), userId }),
z.object({ t: z.literal('botLevel'), userId, pick: z.enum(['random', 'easy', 'normal', 'hard']) }),
z.object({ t: z.literal('act'), cs: z.number().int().min(1), a: z.unknown() }),
z.object({ t: z.literal('chat'), text: z.string().min(1).max(CHAT_MAX) }),
z.object({ t: z.literal('emote'), id: z.string().max(20) }),
z.object({ t: z.literal('rematch') }),
z.object({ t: z.literal('void') }),
z.object({ t: z.literal('sync') }),
z.object({ t: z.literal('ping'), ts: z.number() }),
]);
export type ClientMessage = z.infer<typeof ClientMessage>;