채팅 연속 입력 전부 전송(짧은 연타 허용 + 보내기 대기열), 사람도 '입력 중' 표시, 오른쪽 위 소리 크기(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

@@ -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();