채팅 연속 입력 전부 전송(짧은 연타 허용 + 보내기 대기열), 사람도 '입력 중' 표시, 오른쪽 위 소리 크기(0~100, 기본 50)

- 서버 방 채팅: 0.5초 고정 간격 대신 토큰 버킷(4줄 연속, 초당 2줄) — 도배는 여전히 막음
- 웹: useChatOutbox(방 채팅·마피아·라이어 게임)로 빠르게 친 줄도 순서대로 전송
- typing 메시지(방 채팅 / 게임 공개 채팅만, 마피아 밤 채널은 보내지 않음), BotActivity에 사람 표시
- VolumeControl: 사이트 머리글·방 막대 오른쪽 위, 설정 페이지에도 슬라이더
- e2e/chat.e2e.ts: 연타 7줄, 입력 중, 소리 크기

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 04:14:19 +09:00
parent f12cf12b84
commit f620faf70b
17 changed files with 415 additions and 21 deletions

View File

@@ -226,3 +226,43 @@ describe('윷놀이 room rules', () => {
expect(st.view.turnSeq).toBe((room.game!.state as any).turnSeq);
});
});
describe('Room chat (2026-10-13)', () => {
test('a quick burst of lines all goes through; a flood is still stopped', () => {
const { room, clock, conn } = harness();
const a = conn('A');
const b = conn('B');
room.join(a, 'player');
room.join(b, 'player');
for (let i = 0; i < 4; i++) expect(room.chat('A', `줄 ${i}`)).toBeNull();
expect(room.chat('A', '도배')).toBe('조금 천천히 보내 주세요.');
clock.advance(500);
expect(room.chat('A', '0.5초 뒤')).toBeNull();
expect(b.msgs.filter((m) => m.t === 'chat').map((m) => (m as { text: string }).text)).toEqual(['줄 0', '줄 1', '줄 2', '줄 3', '0.5초 뒤']);
});
test('"입력 중" reaches the others (not me), repeats within a second are dropped, off always goes', () => {
const { room, clock, conn } = harness();
const a = conn('A');
const b = conn('B');
room.join(a, 'player');
room.join(b, 'player');
const typingOf = (c: { msgs: ServerMessage[] }) => c.msgs.filter((m) => m.t === 'typing');
room.typing('A', true, 'room');
room.typing('A', true, 'room');
expect(typingOf(b)).toEqual([{ t: 'typing', from: 'A', on: true, ch: 'room' }]);
expect(typingOf(a)).toHaveLength(0);
clock.advance(1000);
room.typing('A', true, 'room');
room.typing('A', false, 'room');
expect(typingOf(b)).toHaveLength(3);
// Game chat signal only while a game with its own chat runs (omok has none).
room.typing('A', true, 'game');
expect(typingOf(b)).toHaveLength(3);
// Chat off: nothing.
room.configure('A', { chatEnabled: false });
clock.advance(1000);
room.typing('A', true, 'room');
expect(typingOf(b)).toHaveLength(3);
});
});

View File

@@ -14,6 +14,7 @@ import { BotBrain, type BotActivity } from '../ai/brain';
import type { Llm } from '../ai/llm';
import type { LogEntry, RoomStore } from './store';
import { applyLocks, type EffectiveGame, type SiteSettings } from '../admin/settings';
import { TokenBucket } from '../ws/rate-limit';
export interface Conn {
userId: string;
@@ -151,6 +152,9 @@ export class Room {
private flushTimer: ReturnType<typeof setTimeout> | null = null;
private recentCs = new Map<string, number[]>();
private lastChatAt = new Map<string, number>();
private chatBuckets = new Map<string, TokenBucket>();
/** When each person last said they were typing (to drop repeats within a second). */
private typingAt = new Map<string, number>();
private consecutiveErrors = 0;
private readonly now: () => number;
/** Plays the computer players' moves (docs/06 §12). */
@@ -798,8 +802,11 @@ export class Room {
if (!this.isParticipant(userId)) return '방에 들어와야 채팅할 수 있어요.';
if (this.gameChatOnly()) return '게임 중에는 게임 화면의 채팅을 써 주세요.';
const now = this.now();
if (now - (this.lastChatAt.get(userId) ?? 0) < 500) return '조금 천천히 보내 주세요.';
this.lastChatAt.set(userId, now);
// A few lines in a row go through (people often send 2~3 quick lines); a flood still stops.
let bucket = this.chatBuckets.get(userId);
if (!bucket) this.chatBuckets.set(userId, (bucket = new TokenBucket(2, 4, now)));
if (!bucket.take(now)) return '조금 천천히 보내 주세요.';
this.typingAt.delete(userId);
const clean = text.replace(/[\u0000-\u001f\u007f]/g, ' ').trim();
if (!clean) return null;
const msg: Extract<ServerMessage, { t: 'chat' }> = {
@@ -820,6 +827,21 @@ export class Room {
return (this.status === 'playing' || this.status === 'paused') && !!this.def.ownChat;
}
/**
* "입력 중" for people, like the computers'. Room chat: only while the room chat is open. Game chat: only in games
* with their own chat, and the client only sends it from the public channel (마피아 낮, 라이어 토론).
*/
typing(userId: string, on: boolean, ch: 'room' | 'game'): void {
if (!this.isParticipant(userId)) return;
if (ch === 'room' ? !this.config.chatEnabled || this.gameChatOnly() : !this.gameChatOnly()) return;
const now = this.now();
if (on) {
if (now - (this.typingAt.get(userId) ?? -Infinity) < 1000) return;
this.typingAt.set(userId, now);
} else this.typingAt.delete(userId);
for (const [id, c] of this.conns) if (id !== userId) c.send({ t: 'typing', from: userId, on, ch });
}
emote(userId: string, id: string): void {
if (!this.isParticipant(userId) || this.gameChatOnly()) return;
const now = this.now();

View File

@@ -208,6 +208,9 @@ export class Gateway {
case 'emote':
room.emote(u, m.id);
return;
case 'typing':
room.typing(u, m.on, m.ch);
return;
case 'rematch':
e = room.rematch(u);
break;