From b61be627c9b9eb973a554dc52e0e1e3fb8de129b Mon Sep 17 00:00:00 2001 From: EJClaw Date: Thu, 15 Oct 2026 00:45:33 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B1=84=ED=8C=85=20=EC=86=8C=EB=A6=AC=20?= =?UTF-8?q?=EA=B8=B0=EB=B3=B8=20=ED=81=AC=EA=B8=B0=EB=A5=BC=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=20=EC=86=8C=EB=A6=AC=EC=9D=98=2080%=EB=A1=9C=20?= =?UTF-8?q?=EC=98=AC=EB=A6=AC=EA=B3=A0(60%=EB=8A=94=20=EB=84=88=EB=AC=B4?= =?UTF-8?q?=20=EC=95=88=20=EB=93=A4=EB=A6=B0=EB=8B=A4=EB=8A=94=20=EC=9D=98?= =?UTF-8?q?=EA=B2=AC),=20=EA=B4=80=EB=A6=AC=EC=9E=90=20=EC=82=AC=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EC=84=A4=EC=A0=95=EC=97=90=20"=EC=B1=84=ED=8C=85?= =?UTF-8?q?=20=EC=86=8C=EB=A6=AC=20=ED=81=AC=EA=B8=B0"(=EA=B2=8C=EC=9E=84?= =?UTF-8?q?=20=EC=86=8C=EB=A6=AC=EC=9D=98=200~200%,=20=EC=A0=95=EC=88=98,?= =?UTF-8?q?=20=EA=B8=B0=EB=B3=B8=2080%)=EB=A5=BC=20=EC=B6=94=EA=B0=80.=200?= =?UTF-8?q?%=EB=A9=B4=20=EC=B1=84=ED=8C=85=20=EC=86=8C=EB=A6=AC=20?= =?UTF-8?q?=EC=97=86=EC=9D=8C.=20=EA=B0=81=EC=9E=90=EC=9D=98=20=EC=86=8C?= =?UTF-8?q?=EB=A6=AC=20=ED=81=AC=EA=B8=B0(0~100)=EB=8A=94=20=EA=B7=B8?= =?UTF-8?q?=EB=8C=80=EB=A1=9C=20=EA=B3=B1=ED=95=B4=EC=A7=90.=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=98=EB=A9=B4=20/api/config=EC=99=80=20=EB=B0=A9?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4(RoomView.chatSound)=EB=A1=9C=20=EC=97=B4?= =?UTF-8?q?=EB=A6=B0=20=EB=B0=A9=EC=97=90=EB=8F=84=20=EB=B0=94=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9.=20=EC=84=A4=EC=A0=95=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=97=90=20=EC=A0=80=EC=9E=A5=20=EC=97=86=EC=9D=B4=20=EA=B7=B8?= =?UTF-8?q?=20=EA=B0=92=EC=9C=BC=EB=A1=9C=20=EC=9A=B8=EB=A0=A4=20=EB=B3=B4?= =?UTF-8?q?=EB=8A=94=20"=EB=93=A4=EC=96=B4=20=EB=B3=B4=EA=B8=B0"=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC.=20feedback.test.ts=C2=B7admin.test.ts=C2=B7?= =?UTF-8?q?admin.e2e.ts=EC=97=90=20=ED=99=95=EC=9D=B8=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?,=20docs/14-admin.md=20=ED=91=9C=EC=97=90=20=ED=95=AD=EB=AA=A9?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- apps/server/src/admin.test.ts | 26 +++++++++++++++++ apps/server/src/admin/settings.ts | 4 ++- apps/server/src/http/admin.ts | 4 +-- apps/server/src/http/app.ts | 1 + apps/server/src/rooms/room.ts | 3 +- apps/web/src/lib/feedback.test.ts | 35 +++++++++++++++++++---- apps/web/src/lib/feedback.ts | 20 ++++++++++---- apps/web/src/net/api.ts | 2 +- apps/web/src/net/socket.ts | 2 ++ apps/web/src/pages/admin/AdminApp.tsx | 40 ++++++++++++++++++++++++++- apps/web/src/store/session.ts | 4 ++- docs/14-admin.md | 1 + e2e/admin.e2e.ts | 13 +++++++++ packages/shared/src/types.ts | 15 ++++++++++ 14 files changed, 153 insertions(+), 17 deletions(-) diff --git a/apps/server/src/admin.test.ts b/apps/server/src/admin.test.ts index bb30891..28838f7 100644 --- a/apps/server/src/admin.test.ts +++ b/apps/server/src/admin.test.ts @@ -223,6 +223,32 @@ describe('site settings, rooms, users', () => { expect((await next).room.gameSpeed).toBe(2); }); + test('chat sound: 0~200% (default 80), shown in /api/config and open rooms, out of range rejected', async () => { + const s = start(); + const sup = await discordLogin(s, SUPER); + const site = (await api(s.base, '/api/admin/site', { cookie: sup.cookie })).body.site; + expect(site.chatSound).toBe(80); + expect((await api(s.base, '/api/config')).body.chatSound).toBe(80); + for (const bad of [-1, 201, 50.5]) { + const r = await api(s.base, '/api/admin/site', { method: 'PUT', cookie: sup.cookie, body: JSON.stringify({ ...site, chatSound: bad }) }); + expect(r.res.status).toBe(400); + } + for (const ok of [0, 200, 120]) { + const r = await api(s.base, '/api/admin/site', { method: 'PUT', cookie: sup.cookie, body: JSON.stringify({ ...site, chatSound: ok }) }); + expect(r.res.status).toBe(200); + expect((await api(s.base, '/api/config')).body.chatSound).toBe(ok); + } + const g = await guest(s.base, '방장님'); + const room = await api(s.base, '/api/rooms', { method: 'POST', cookie: g.cookie, body: JSON.stringify({ gameId: 'omok' }) }); + const c = await new Client(s.base, g.cookie, g.id).connect(); + clients.push(c); + c.send({ t: 'join', code: room.body.code, as: 'player' }); + expect((await c.next('room')).room.chatSound).toBe(120); + const next = c.next('room'); + await api(s.base, '/api/admin/site', { method: 'PUT', cookie: sup.cookie, body: JSON.stringify({ ...site, chatSound: 30 }) }); + expect((await next).room.chatSound).toBe(30); + }); + test('admin closes a room: everyone is told and disconnected from it', async () => { const s = start(); const sup = await discordLogin(s, SUPER); diff --git a/apps/server/src/admin/settings.ts b/apps/server/src/admin/settings.ts index 925a01f..20ed59b 100644 --- a/apps/server/src/admin/settings.ts +++ b/apps/server/src/admin/settings.ts @@ -5,7 +5,7 @@ import type { Database } from 'bun:sqlite'; import { z } from 'zod'; import type { AnyGameDefinition } from '@bg/engine'; -import { CATALOG, GAME_SPEED_DEFAULT, GAME_SPEED_MAX, GAME_SPEED_MIN, type CatalogEntry } from '@bg/shared'; +import { CATALOG, CHAT_SOUND_DEFAULT, CHAT_SOUND_MAX, CHAT_SOUND_MIN, GAME_SPEED_DEFAULT, GAME_SPEED_MAX, GAME_SPEED_MIN, type CatalogEntry } from '@bg/shared'; export const SiteSettingsSchema = z.object({ siteName: z.string().trim().min(1).max(40).default('같이 놀자 보드게임'), @@ -21,6 +21,8 @@ export const SiteSettingsSchema = z.object({ chatFloodGuard: z.boolean().default(false), /** Animations and the computers' thinking time are divided by this (applies at once, also to running games). */ gameSpeed: z.number().min(GAME_SPEED_MIN).max(GAME_SPEED_MAX).default(GAME_SPEED_DEFAULT), + /** Chat sound in % of a game sound (0 = silent, applies at once, also to open rooms). */ + chatSound: z.number().int().min(CHAT_SOUND_MIN).max(CHAT_SOUND_MAX).default(CHAT_SOUND_DEFAULT), }); export type SiteSettings = z.infer; diff --git a/apps/server/src/http/admin.ts b/apps/server/src/http/admin.ts index 3a74515..da43c3f 100644 --- a/apps/server/src/http/admin.ts +++ b/apps/server/src/http/admin.ts @@ -93,8 +93,8 @@ export function createAdminApp(d: AdminDeps) { const before = d.settings.getSite(); d.settings.setSite(parsed.data, actor(c)); d.audit.log(actor(c), 'site.update', null, before, parsed.data); - // The game speed applies at once: open rooms get it with a fresh room view (their animations follow it). - if (before.gameSpeed !== parsed.data.gameSpeed) for (const r of d.rooms.all()) r.broadcastRoom(); + // The game speed and chat sound apply at once: open rooms get them with a fresh room view. + if (before.gameSpeed !== parsed.data.gameSpeed || before.chatSound !== parsed.data.chatSound) for (const r of d.rooms.all()) r.broadcastRoom(); return c.json({ site: parsed.data }); }); diff --git a/apps/server/src/http/app.ts b/apps/server/src/http/app.ts index 28d9fa1..cbaa638 100644 --- a/apps/server/src/http/app.ts +++ b/apps/server/src/http/app.ts @@ -98,6 +98,7 @@ export function createHttpApp(d: HttpDeps) { announcement: site.announcement, maintenance: site.maintenance, gameSpeed: site.gameSpeed, + chatSound: site.chatSound, }); }); diff --git a/apps/server/src/rooms/room.ts b/apps/server/src/rooms/room.ts index 1fa9c8a..10a2e67 100644 --- a/apps/server/src/rooms/room.ts +++ b/apps/server/src/rooms/room.ts @@ -4,7 +4,7 @@ */ import { ulid } from 'ulid'; import { SeededRng, createSeed, secureRandom, seedToHex, type AnyGameDefinition, type ChaChaSeed, type GameResult, type RngState } from '@bg/engine'; -import { botChatRequired, clampGameSpeed, botsAllowed, isBotId, makeBotId, botNumber, maskProfanity, type BotPick, type PublicUser, type RoomView, type ServerMessage, type SeatView } from '@bg/shared'; +import { botChatRequired, clampChatSound, clampGameSpeed, botsAllowed, isBotId, makeBotId, botNumber, maskProfanity, type BotPick, type PublicUser, type RoomView, type ServerMessage, type SeatView } from '@bg/shared'; import { botPersona } from '@bg/games/bots'; import { luckApplies, shufflesFor, type LuckJob } from '@bg/games/bots/luck'; import { sha256Hex } from '../auth/sessions'; @@ -440,6 +440,7 @@ export class Room { // Levels are revealed only once the game is over (fairness check). ...(this.game?.finished && this.game.bots ? { lastBots: this.game.bots, lastShuffles: this.game.shuffles ?? 1 } : {}), gameSpeed: this.gameSpeed(), + chatSound: clampChatSound(this.deps.settings?.getSite().chatSound), }; } diff --git a/apps/web/src/lib/feedback.test.ts b/apps/web/src/lib/feedback.test.ts index bbae23b..ed5f3bb 100644 --- a/apps/web/src/lib/feedback.test.ts +++ b/apps/web/src/lib/feedback.test.ts @@ -57,7 +57,7 @@ class FakeCtx { // The real settings store needs a page (document); only the sound settings matter here. let settings = { sound: true, volume: 100 }; mock.module('../store/session', () => ({ useSession: { getState: () => ({ settings }) } })); -const { CHAT_LEVEL, GAME_LEVEL, chatSound, sounds } = await import('./feedback'); +const { GAME_LEVEL, chatLevel, chatSound, setChatSound, sounds } = await import('./feedback'); const setVolume = (volume: number, sound = true) => { settings = { sound, volume }; @@ -67,19 +67,19 @@ beforeEach(() => { notes = []; }); -test('chat sound is 60% of the game sounds', () => { +test('chat sound is 80% of the game sounds by default', () => { expect(GAME_LEVEL).toBe(0.15); - expect(CHAT_LEVEL).toBeCloseTo(GAME_LEVEL * 0.6, 10); + expect(chatLevel()).toBeCloseTo(GAME_LEVEL * 0.8, 10); setVolume(100); sounds.myTurn(); // a typical game sound at the usual level const game = Math.max(...notes.map((n) => n.peak)); notes = []; chatSound(); - // Notes playing at the same moment add up; the loudest moment of the chat sound is 60% of a game sound. + // Notes playing at the same moment add up; the loudest moment of the chat sound is 80% of a game sound. const byStart = new Map(); for (const n of notes) byStart.set(n.start, (byStart.get(n.start) ?? 0) + n.peak); const loudest = Math.max(...byStart.values()); - expect(loudest).toBeCloseTo(game * 0.6, 6); + expect(loudest).toBeCloseTo(game * 0.8, 6); // One bubble ("뽁") gliding up from a low start. expect(notes.map((n) => n.freq)).toEqual([380]); expect(notes.map((n) => n.to)).toEqual([1150]); @@ -110,3 +110,28 @@ test('lines arriving in a burst share one sound', async () => { chatSound(); expect(notes.length).toBe(one * 2); }); + +test('admin chat sound setting: 0~200% of a game sound, 0 is silent, preview does not change it', async () => { + setVolume(100); + for (const [pct, want] of [[200, 2], [150, 1.5], [999, 2], [-5, 0]] as const) { + setChatSound(pct); + expect(chatLevel()).toBeCloseTo(GAME_LEVEL * want, 10); + } + setChatSound(0); + await new Promise((r) => setTimeout(r, 100)); + notes = []; + chatSound(); + expect(notes).toEqual([]); + setChatSound(200); + await new Promise((r) => setTimeout(r, 100)); + chatSound(); + expect(Math.max(...notes.map((n) => n.peak))).toBeCloseTo(GAME_LEVEL * 2, 6); + // Previewing another value in the admin page plays it once and leaves the setting alone. + await new Promise((r) => setTimeout(r, 100)); + notes = []; + chatSound(50); + expect(Math.max(...notes.map((n) => n.peak))).toBeCloseTo(GAME_LEVEL * 0.5, 6); + expect(chatLevel()).toBeCloseTo(GAME_LEVEL * 2, 10); + setChatSound(undefined); // missing from an old server → the default 80% + expect(chatLevel()).toBeCloseTo(GAME_LEVEL * 0.8, 10); +}); diff --git a/apps/web/src/lib/feedback.ts b/apps/web/src/lib/feedback.ts index 013fbe3..1b9b10f 100644 --- a/apps/web/src/lib/feedback.ts +++ b/apps/web/src/lib/feedback.ts @@ -5,6 +5,7 @@ * directly for something of their own. */ import { useEffect, useRef } from 'react'; +import { CHAT_SOUND_DEFAULT, clampChatSound } from '@bg/shared/lite'; import { useSession } from '../store/session'; let ctx: AudioContext | null = null; @@ -190,21 +191,30 @@ export const sounds = { /** The usual level of a game sound at volume 100 (`tone`'s default). */ export const GAME_LEVEL = 0.15; -/** Chat sound: 60% of the game sounds (it follows the same volume setting); 90% hit the ears too hard. */ -export const CHAT_LEVEL = GAME_LEVEL * 0.6; +/** Chat sound in % of a game sound (admin setting `chatSound`, 0~200, default 80); it also follows the volume setting. */ +let chatPercent = CHAT_SOUND_DEFAULT; +/** Sets the chat sound percent from /api/config or the room view (out-of-range values are clamped). */ +export function setChatSound(x: unknown): void { + chatPercent = clampChatSound(x); +} +/** Peak level of the chat sound at volume 100 (`percent`: the admin setting unless previewing another value). */ +export const chatLevel = (percent = chatPercent): number => (GAME_LEVEL * clampChatSound(percent)) / 100; let lastChatAt = -Infinity; /** * Chat "뽁": one water-drop bubble like a messenger, a sine gliding up fast from low (about 0.08 s). * Kept apart from the UI/game sounds, which are steady notes (click, good, myTurn …), so it is not mistaken for one; * it also starts lower and is shorter and softer than the game "pop" (700→1400 Hz). - * It peaks at CHAT_LEVEL and fades in over 12 ms so it does not snap. Lines arriving in a burst share one sound. + * It peaks at `chatLevel()` (none at 0%) and fades in over 12 ms so it does not snap. Lines arriving in a burst share one sound. + * `percent` previews another level (admin settings) without changing the setting. */ -export function chatSound(): void { +export function chatSound(percent?: number): void { + const level = chatLevel(percent); + if (level <= 0) return; const now = performance.now(); if (now - lastChatAt < 80) return; lastChatAt = now; - tone(380, 80, 'sine', CHAT_LEVEL, 0, { attack: 12, slideTo: 1150 }); + tone(380, 80, 'sine', level, 0, { attack: 12, slideTo: 1150 }); } /** Plays the chat sound whenever `lastKey` (the newest live chat line) changes after the first render. */ diff --git a/apps/web/src/net/api.ts b/apps/web/src/net/api.ts index 98e2283..683a294 100644 --- a/apps/web/src/net/api.ts +++ b/apps/web/src/net/api.ts @@ -67,7 +67,7 @@ export interface RoomPreview { export const api = { config: () => - call<{ discord: boolean; catalog: (CatalogEntry & { notice?: string })[]; siteName: string; announcement: string; maintenance: boolean; gameSpeed?: number }>('GET', '/api/config'), + call<{ discord: boolean; catalog: (CatalogEntry & { notice?: string })[]; siteName: string; announcement: string; maintenance: boolean; gameSpeed?: number; chatSound?: number }>('GET', '/api/config'), me: () => call('GET', '/api/me'), guest: (nickname: string) => call<{ me: PublicUser }>('POST', '/api/auth/guest', { nickname }), updateMe: (patch: { nickname?: string; useAvatar?: boolean; settings?: Settings }) => call<{ me: PublicUser }>('PATCH', '/api/me', patch), diff --git a/apps/web/src/net/socket.ts b/apps/web/src/net/socket.ts index 8e84dfc..cf9b66e 100644 --- a/apps/web/src/net/socket.ts +++ b/apps/web/src/net/socket.ts @@ -7,6 +7,7 @@ import { PROTOCOL, type GameResultView, type PublicUser, type RoomView, type Ser import { toast } from '../store/toast'; import { markOutdated, noteServerBuild } from '../lib/update'; import { setGameSpeed } from '../lib/motion'; +import { setChatSound } from '../lib/feedback'; export type ConnStatus = 'idle' | 'connecting' | 'open' | 'reconnecting' | 'replaced' | 'offline'; @@ -285,6 +286,7 @@ class GameSocket { case 'room': if (m.seq >= st.roomSeq || m.room.code !== st.room?.code) { if (m.room.gameSpeed !== undefined) setGameSpeed(m.room.gameSpeed); + if (m.room.chatSound !== undefined) setChatSound(m.room.chatSound); useRoom.setState({ room: m.room, roomSeq: m.seq, joinError: null }); if (m.room.status === 'playing' && st.result) useRoom.setState({ result: null }); } diff --git a/apps/web/src/pages/admin/AdminApp.tsx b/apps/web/src/pages/admin/AdminApp.tsx index 70f6adc..3c661a1 100644 --- a/apps/web/src/pages/admin/AdminApp.tsx +++ b/apps/web/src/pages/admin/AdminApp.tsx @@ -1,7 +1,7 @@ /** 관리자 사이트 (docs/14-admin.md). Downloaded only when /admin is opened. */ import { useCallback, useEffect, useState, type ReactNode } from 'react'; import { NavLink, Route, Routes, useNavigate, useParams } from 'react-router'; -import { formatRoomCode, GAME_SPEED_MAX, GAME_SPEED_MIN, type MyGameSummary } from '@bg/shared/lite'; +import { CHAT_SOUND_DEFAULT, CHAT_SOUND_MAX, CHAT_SOUND_MIN, formatRoomCode, GAME_SPEED_MAX, GAME_SPEED_MIN, type MyGameSummary } from '@bg/shared/lite'; import { ConfirmSheet, Sheet } from '../../components/ui'; import { apiCall, discordLoginUrl, type Role } from '../../net/api'; import { useSession } from '../../store/session'; @@ -10,6 +10,7 @@ import { SchemaForm, type JsonSchema } from './SchemaForm'; import { gameName } from '../../components/GameNotice'; import { RecordCell, record, recordText, resultLabel, sumStats } from '../../components/PlayerCard'; import type { GameStat } from '../../net/api'; +import { chatSound } from '../../lib/feedback'; const a = { get: (p: string) => apiCall('GET', `/api/admin${p}`), @@ -445,6 +446,43 @@ function Site() { +
+
+ + 채팅 소리 크기 (게임 소리의 {CHAT_SOUND_MIN}~{CHAT_SOUND_MAX}%, 기본 {CHAT_SOUND_DEFAULT}%) + +

+ 새 채팅이 올 때 나는 "뽁" 소리의 크기예요. 100%면 게임 소리와 같고, 0%면 채팅 소리가 안 나요. 각자 정한 소리 크기도 그대로 곱해져요. 저장하면 열린 방에도 바로 적용돼요. +

+
+ setS({ ...s, chatSound: Number(e.target.value) })} + /> + setS({ ...s, chatSound: Number(e.target.value) })} + /> + % + +
+
+
{num('maxRoomsPerUser', '사용자당 동시에 만들 수 있는 방', 1, 50)} {num('maxRooms', '서버 전체 방 수 제한', 10, 20000)} diff --git a/apps/web/src/store/session.ts b/apps/web/src/store/session.ts index d5542ee..fb4953c 100644 --- a/apps/web/src/store/session.ts +++ b/apps/web/src/store/session.ts @@ -4,6 +4,7 @@ import type { CatalogEntry, PublicUser } from '@bg/shared/lite'; import { api, type Settings } from '../net/api'; import { socket } from '../net/socket'; import { setGameSpeed } from '../lib/motion'; +import { setChatSound } from '../lib/feedback'; const LS_KEY = 'bg.settings'; @@ -76,7 +77,7 @@ export const useSession = create((set, get) => ({ hasDiscordAvatar: false, async refresh() { const [cfg, me] = await Promise.all([ - api.config().catch(() => ({ discord: false, catalog: [] as CatalogEntry[], siteName: '같이 놀자 보드게임', announcement: '', maintenance: false, gameSpeed: 1 })), + api.config().catch(() => ({ discord: false, catalog: [] as CatalogEntry[], siteName: '같이 놀자 보드게임', announcement: '', maintenance: false, gameSpeed: 1, chatSound: undefined })), api.me().catch(() => ({ me: null }) as Awaited>), ]); const settings = { ...get().settings, ...withoutDeviceOnly(me.settings ?? {}) }; @@ -84,6 +85,7 @@ export const useSession = create((set, get) => ({ localStorage.setItem(LS_KEY, JSON.stringify(settings)); document.title = cfg.siteName; setGameSpeed(cfg.gameSpeed); + setChatSound(cfg.chatSound); set({ loaded: true, me: me.me, diff --git a/docs/14-admin.md b/docs/14-admin.md index 4373c00..5112074 100644 --- a/docs/14-admin.md +++ b/docs/14-admin.md @@ -59,6 +59,7 @@ | 채팅 기본값 | 켜짐 / 필터 켜짐 | 새 방의 기본값 | | 채팅 도배 방지 | 꺼짐 | 켜면 접속마다 채팅·입력 중 신호를 초당 50개(한 번에 200개)까지만 받음(`03-realtime-protocol.md` §8). 끄면 채팅 속도 제한 없음. 저장하면 바로 적용 | | 게임 속도 배율 | 1배 | 1/16~16배. 게임 화면의 애니메이션·연출(배너가 떠 있는 시간, 차례로 이어지는 연출, 다시 보기 한 칸)과 컴퓨터가 생각하는 시간을 이 배율로 나눈다(2배 = 두 배 빠르게). 저장하면 열린 방에도 바로 적용(방 정보 `RoomView.gameSpeed`로 다시 보냄). 턴 제한 시간·결과 화면 대기 같은 규칙 시간, 원카드 외치기 같은 반응 경쟁, 실시간 게임의 판정 시간은 그대로 | +| 채팅 소리 크기 | 80% | 0~200%(정수). 새 채팅 "뽁" 소리의 크기를 게임 소리 기준(0.15)에 대한 비율로 정한다(100% = 게임 소리와 같음, 0% = 채팅 소리 없음). 각자 정한 소리 크기(0~100)가 그대로 곱해진다. 저장하면 열린 방에도 바로 적용(`/api/config`와 방 정보 `RoomView.chatSound`). 설정 화면의 "들어 보기"는 저장하지 않고 그 값으로 한 번 울린다 | ## 6. 사용자 관리 (슈퍼어드민) - **이용 제한**: 사유와 함께 설정. 즉시 그 사용자의 모든 세션 삭제와 접속 종료. 제한된 디스코드 계정은 다시 로그인할 수 없다("이용이 제한된 계정이에요"). 해제하면 다시 로그인 가능. diff --git a/e2e/admin.e2e.ts b/e2e/admin.e2e.ts index 150a560..0f92df4 100644 --- a/e2e/admin.e2e.ts +++ b/e2e/admin.e2e.ts @@ -131,6 +131,19 @@ try { if (app.settings.getSite().chatFloodGuard !== true) throw new Error('chat flood guard not saved'); }); + await step('사이트 탭: 채팅 소리 크기 기본 80%, 150% 저장 → /api/config 반영', async () => { + const pct = a.getByLabel('채팅 소리 크기(%)'); + if ((await pct.inputValue()) !== '80') throw new Error(`chat sound should default to 80: ${await pct.inputValue()}`); + await pct.fill('150'); + await pct.evaluate((el) => el.scrollIntoView({ block: 'center' })); + await a.getByRole('button', { name: '들어 보기' }).click(); + await a.screenshot({ path: join(SHOTS, 'admin-6-chat-sound.png') }); + await a.getByRole('button', { name: '저장', exact: true }).click(); + await a.getByText('저장했어요.').last().waitFor(); + const cfg = await a.evaluate(async () => (await (await fetch('/api/config')).json()).chatSound); + if (cfg !== 150) throw new Error(`chatSound not saved: ${cfg}`); + }); + await step('기록 탭에 변경 내역', async () => { await a.locator('.admin-side').getByRole('link', { name: '기록', exact: true }).click(); await a.getByText('어드민 추가').waitFor(); diff --git a/packages/shared/src/types.ts b/packages/shared/src/types.ts index d958ed6..d8a9bd4 100644 --- a/packages/shared/src/types.ts +++ b/packages/shared/src/types.ts @@ -16,6 +16,19 @@ export function clampGameSpeed(x: unknown): number { return Math.min(GAME_SPEED_MAX, Math.max(GAME_SPEED_MIN, x)); } +/** + * Chat sound level (admin site setting, docs/14-admin.md §5): percent of the usual game sound level, 0 = no chat sound. + * It still follows each player's own volume setting. + */ +export const CHAT_SOUND_MIN = 0; +export const CHAT_SOUND_MAX = 200; +export const CHAT_SOUND_DEFAULT = 80; +/** Clamps a chat sound percent from the network / settings into the range (anything not a number → the default). */ +export function clampChatSound(x: unknown): number { + if (typeof x !== 'number' || !Number.isFinite(x)) return CHAT_SOUND_DEFAULT; + return Math.min(CHAT_SOUND_MAX, Math.max(CHAT_SOUND_MIN, x)); +} + export const EMOTES = ['thumbs', 'laugh', 'wow', 'sad', 'clap', 'nice', 'hurry', 'gg'] as const; export const EMOTE_LABEL: Record<(typeof EMOTES)[number], string> = { thumbs: '👍', @@ -83,6 +96,8 @@ export interface RoomView { lastShuffles?: number; /** Game speed set by the admin (1/16 ~ 16, 1 = normal): the screen's animations follow it. */ gameSpeed?: number; + /** Chat sound set by the admin (0~200, % of a game sound): the chat "뽁" follows it. */ + chatSound?: number; } export interface GameResultView {