채팅을 따로 분리해 속도 제한 없이: 방 채팅·마피아·라이어·그림 맞히기(그리기 전) 채팅의 줄 간격 제한(chat-pace)과 브라우저 대기열을 없애 치는 대로 바로 보냄. 서버 연결당 공용 한도(초당 20개)를 채팅·입력 중 신호가 같이 써서 빠르게 치면 15번째 줄부터 조용히 사라지던 문제도: 채팅은 별도 한도(초당 50, 최대 200, 매크로 도배 방지용)로 분리. 게임 채팅은 보내는 동안 게임 버튼을 잠그지 않음(pending 미설정)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -173,6 +173,14 @@ describe('채팅 공개 범위(§5.3, §8.3)', () => {
|
||||
expect(reason(t, g, guess('배3'), T0 + 2300)).toContain('천천히');
|
||||
expect(reason(t, g, guess('배3'), T0 + 3000)).toBeNull();
|
||||
});
|
||||
|
||||
test('그리기 전 채팅은 제한 없음 (정답 입력만 초당 3개)', () => {
|
||||
let s = make(3);
|
||||
expect(s.turn.phase).toBe('choosing');
|
||||
const g = guessers(s)[0]!;
|
||||
for (let i = 0; i < 20; i++) s = act(s, g, { type: 'chat', text: `안녕 ${i}` }, T0 + 500);
|
||||
expect(view(s, g).chat.filter((m) => m.from === g && m.text.startsWith('안녕')).length).toBe(20);
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- §6 scores
|
||||
|
||||
@@ -628,7 +628,6 @@ export const catchmind: GameDefinition<S, A, CatchmindView, CatchmindOptions> =
|
||||
const len = [...cleanText(a.text)].length;
|
||||
if (len < 1) return fail('내용을 입력해 주세요.');
|
||||
if (len > CHAT_MAX) return fail(`${CHAT_MAX}자까지 쓸 수 있어요.`);
|
||||
if (!rateOk(s.msgTimes[actor], GUESS_MSGS_PER_SEC, now)) return fail('조금 천천히 보내 주세요.');
|
||||
return ok;
|
||||
}
|
||||
case 'reaction':
|
||||
@@ -670,7 +669,6 @@ export const catchmind: GameDefinition<S, A, CatchmindView, CatchmindOptions> =
|
||||
guess(s, actor, a.text, ctx);
|
||||
break;
|
||||
case 'chat':
|
||||
stamp(s, actor, now);
|
||||
addChat(s, { from: actor, text: maskBanned(cleanText(a.text)), at: now, audience: 'all', kind: 'chat' });
|
||||
break;
|
||||
case 'reaction':
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import { CHAT_BURST, CHAT_INTERVAL_MS, chatNext, chatWait } from './chat-pace';
|
||||
|
||||
describe('chat pace', () => {
|
||||
test(`${CHAT_BURST} lines at once go through, the next waits one interval`, () => {
|
||||
let next: number | undefined;
|
||||
for (let i = 0; i < CHAT_BURST; i++) {
|
||||
expect(chatWait(next, 1000)).toBe(0);
|
||||
next = chatNext(next, 1000);
|
||||
}
|
||||
expect(chatWait(next, 1000)).toBe(CHAT_INTERVAL_MS);
|
||||
expect(chatWait(next, 1000 + CHAT_INTERVAL_MS)).toBe(0);
|
||||
});
|
||||
|
||||
test('a person typing a line every 0.4 s never waits', () => {
|
||||
let next: number | undefined;
|
||||
for (let t = 0; t < 60_000; t += 400) {
|
||||
expect(chatWait(next, t)).toBe(0);
|
||||
next = chatNext(next, t);
|
||||
}
|
||||
});
|
||||
|
||||
test('an old "last sent at" time from a saved game does not block', () => {
|
||||
expect(chatWait(5_000, 5_000)).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -1,19 +0,0 @@
|
||||
/**
|
||||
* Chat pace, shared by the server checks (room chat, 마피아, 라이어 게임) and the browser's send queue.
|
||||
*
|
||||
* One number per person: the time from which the next line is "free" (GCRA). Up to `CHAT_BURST` lines go through
|
||||
* at once, then about one line per `CHAT_INTERVAL_MS` — far faster than anyone types, while a flood still stops.
|
||||
* A plain "last sent at" time from older saved games reads as a time in the past, so nothing needs migrating.
|
||||
*/
|
||||
export const CHAT_BURST = 6;
|
||||
export const CHAT_INTERVAL_MS = 300;
|
||||
|
||||
/** How long until one more line is allowed (0 = now). */
|
||||
export function chatWait(next: number | undefined, now: number, burst = CHAT_BURST, interval = CHAT_INTERVAL_MS): number {
|
||||
return Math.max(0, (next ?? -Infinity) - (burst - 1) * interval - now);
|
||||
}
|
||||
|
||||
/** The new "free from" time after sending a line at `now`. */
|
||||
export function chatNext(next: number | undefined, now: number, interval = CHAT_INTERVAL_MS): number {
|
||||
return Math.max(next ?? -Infinity, now) + interval;
|
||||
}
|
||||
@@ -12,7 +12,6 @@
|
||||
* and the liar is told "시민" like everybody else). Who the liar is never appears in any view before the reveal.
|
||||
*/
|
||||
import { fail, ok, type GameDefinition, type GameEvent, type GameResult, type PlayerId, type Validation } from '@bg/engine';
|
||||
import { chatNext, chatWait } from '../chat-pace';
|
||||
import { judge, normalize } from '../catchmind/text';
|
||||
import { chatProblem, cleanChat } from '../mafia';
|
||||
import {
|
||||
@@ -338,8 +337,6 @@ function validate(s: LiarState, actor: PlayerId, a: LiarAction, ctx?: { now: num
|
||||
if (why) return fail(why);
|
||||
const mine = wordOf(s, actor);
|
||||
if (mine && saysWord(text, s.topic, mine)) return fail('제시어를 직접 말하면 안 돼요.');
|
||||
// Pace limit for free talk only: a description is one per turn anyway.
|
||||
if (ph.kind !== 'describe' && ctx && chatWait(s.lastChatAt[actor], ctx.now) > 0) return fail('조금 천천히 보내 주세요.');
|
||||
return ok;
|
||||
}
|
||||
case 'ready':
|
||||
@@ -483,7 +480,6 @@ export const liar: Def = {
|
||||
phase: { kind: 'reveal', startedAt: now, endsAt: now + REVEAL_MS, ready: [] },
|
||||
descriptions: [],
|
||||
chat: [],
|
||||
lastChatAt: {},
|
||||
events: [],
|
||||
accused: null,
|
||||
guess: null,
|
||||
@@ -514,7 +510,6 @@ export const liar: Def = {
|
||||
s.descriptions.push({ n: s.descriptions.length + 1, round: ph.round, from: actor, text, at: now });
|
||||
nextTurn(s, now, ph.round, ph.turn + 1);
|
||||
} else {
|
||||
s.lastChatAt[actor] = chatNext(s.lastChatAt[actor], now);
|
||||
s.chat.push({ n: (s.chat.at(-1)?.n ?? 0) + 1, from: actor, text, at: now });
|
||||
if (s.chat.length > CHAT_KEEP) s.chat.splice(0, s.chat.length - CHAT_KEEP);
|
||||
}
|
||||
|
||||
@@ -258,12 +258,11 @@ describe('차례대로 설명 (§5.2)', () => {
|
||||
expect(reject(s, 'P0', { type: 'chat', text: '안녕' })).toContain('확인하는 중');
|
||||
s = until(s, 'discussion');
|
||||
const t = at(s);
|
||||
// A quick run of lines goes through at once; only a flood is refused.
|
||||
for (let i = 0; i < 6; i++) s = act(s, 'P1', { type: 'chat', text: `누구지 ${i}` }, t);
|
||||
expect(reject(s, 'P1', { type: 'chat', text: '또' }, t + 100)).toBe('조금 천천히 보내 주세요.');
|
||||
// No pace limit: any number of lines at the same moment all go through.
|
||||
for (let i = 0; i < 20; i++) s = act(s, 'P1', { type: 'chat', text: `누구지 ${i}` }, t);
|
||||
s = until(s, 'vote');
|
||||
s = act(s, 'P2', { type: 'chat', text: '투표해요' });
|
||||
expect(s.chat.map((m) => m.text)).toEqual(['누구지 0', '누구지 1', '누구지 2', '누구지 3', '누구지 4', '누구지 5', '투표해요']);
|
||||
expect(s.chat.map((m) => m.text)).toEqual([...Array.from({ length: 20 }, (_, i) => `누구지 ${i}`), '투표해요']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -128,8 +128,6 @@ export interface LiarState {
|
||||
phase: Phase;
|
||||
descriptions: Description[];
|
||||
chat: ChatMessage[];
|
||||
/** Chat pace per person: the time the next line is free from (`chat-pace.ts`; older saves hold the last send time). */
|
||||
lastChatAt: Record<PlayerId, number>;
|
||||
events: PublicEvent[];
|
||||
accused: PlayerId | null;
|
||||
guess: string | null;
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
* it by channel permission (§5.6, §8.3).
|
||||
*/
|
||||
import { fail, ok, type GameDefinition, type GameEvent, type GameResult, type PlayerId, type Rng, type Validation } from '@bg/engine';
|
||||
import { chatNext, chatWait } from '../chat-pace';
|
||||
import {
|
||||
CHANNELS,
|
||||
EXTRA_ROLES,
|
||||
@@ -524,7 +523,6 @@ function validate(s: MafiaState, actor: PlayerId, a: MafiaAction, ctx?: { now: n
|
||||
if (block) return fail(block);
|
||||
const why = chatProblem(cleanChat(a.text), s.options.kidSafeChat);
|
||||
if (why) return fail(why);
|
||||
if (ctx && chatWait(s.lastChatAt[actor], ctx.now) > 0) return fail('조금 천천히 보내 주세요.');
|
||||
return ok;
|
||||
}
|
||||
default:
|
||||
@@ -718,7 +716,6 @@ export const mafia: Def = {
|
||||
privateResults: [],
|
||||
chat: [],
|
||||
chatCount: { day: 0, mafia: 0, dead: 0, lovers: 0 },
|
||||
lastChatAt: {},
|
||||
events: [],
|
||||
trialVoters: [],
|
||||
mvpVotes: {},
|
||||
@@ -749,7 +746,6 @@ export const mafia: Def = {
|
||||
s.chatCount[a.channel] += 1;
|
||||
s.chat.push({ id: s.chatCount[a.channel], channel: a.channel, from: actor, text: cleanChat(a.text), at: now, day: s.day });
|
||||
if (s.chat.length > CHAT_KEEP) s.chat.splice(0, s.chat.length - CHAT_KEEP);
|
||||
s.lastChatAt[actor] = chatNext(s.lastChatAt[actor], now);
|
||||
break;
|
||||
}
|
||||
case 'adjustTime':
|
||||
|
||||
@@ -419,14 +419,13 @@ describe('채팅 권한 (§5.6)', () => {
|
||||
const roles: Role[] = ['mafia', 'mafia', 'police', 'doctor', 'medium', 'lover', 'lover', 'citizen', 'citizen'];
|
||||
const o = { extraRoles: { medium: true, lovers: true } };
|
||||
|
||||
test('밤에 시민 낮 채팅 거부, 죽은 사람 낮 채팅 거부, 레이트 리밋 초과 거부', () => {
|
||||
test('밤에 시민 낮 채팅 거부, 죽은 사람 낮 채팅 거부, 연달아 치는 채팅은 제한 없음', () => {
|
||||
let s = until(rig(roles, o), 'greeting');
|
||||
const g0 = (s.phase as Extract<MafiaState['phase'], { kind: 'greeting' }>).startedAt;
|
||||
s = say(s, 'P7', 'day', '안녕하세요');
|
||||
// A quick run of lines goes through at once; only a flood is refused.
|
||||
for (let i = 0; i < 5; i++) s = say(s, 'P7', 'day', `연달아 ${i}`, g0 + 1);
|
||||
expect(reject(s, 'P7', { type: 'chat', channel: 'day', text: '또 안녕' }, g0 + 1)).toBe('조금 천천히 보내 주세요.');
|
||||
expect(mafia.validate(s, 'P7', { type: 'chat', channel: 'day', text: '또 안녕' }, { now: g0 + 1 + 300 }).ok).toBe(true);
|
||||
// No pace limit: any number of lines at the same moment all go through.
|
||||
for (let i = 0; i < 20; i++) s = say(s, 'P7', 'day', `연달아 ${i}`, g0 + 1);
|
||||
expect(s.chat.filter((m) => m.text.startsWith('연달아')).length).toBe(20);
|
||||
s = tick(s);
|
||||
expect(reject(s, 'P7', { type: 'chat', channel: 'day', text: '밤인데' })).toBe('밤에는 낮 채팅을 쓸 수 없어요.');
|
||||
expect(reject(s, 'P7', { type: 'chat', channel: 'mafia', text: '...' })).toBe('마피아만 쓸 수 있어요.');
|
||||
|
||||
@@ -196,8 +196,6 @@ export interface MafiaState {
|
||||
/** Every message of every channel; the view filters by channel permission. */
|
||||
chat: ChatMessage[];
|
||||
chatCount: Record<Channel, number>;
|
||||
/** Chat pace per person: the time the next line is free from (`chat-pace.ts`; older saves hold the last send time). */
|
||||
lastChatAt: Record<PlayerId, number>;
|
||||
events: PublicEvent[];
|
||||
/** Voters (vote phase) for the current accused — for the MVP count. */
|
||||
trialVoters: PlayerId[];
|
||||
|
||||
Reference in New Issue
Block a user