시간 제한 없음은 정말 무제한, 대기실 설정은 바꾸면 바로 적용, 모르는 사람 기다리기(빠른 시작·공개 방) 제거

- 오목에서 [시간 제한 없음]을 골라도 30초가 흐르던 문제: 대기실 설정이 [설정 저장]을 눌러야
  서버에 반영되어, 누르지 않고 [게임 시작]하면 기본값(한 수 30초)으로 시작했다. 이제 설정은
  바꾸는 즉시 서버에 보낸다(저장 버튼 없음, 휴대폰 시트는 [닫기]만). 빠르게 여러 번 눌러도
  먼저 온 방 정보가 새 값을 되돌리지 않게 lib/option-sync.ts로 맞춘다.
- 시간 제한 없음(오목·체스·장기·오델로·바둑·쿼리도): 무응답 한도(idleLimitSec, 5~10분 뒤 시간패)와
  그 카운트다운을 없앴다. 체스는 첫 수 제한도 피셔일 때만. 연결이 끊긴 사람의 접속 유예는 그대로.
- 홈의 [지금 열린 방] 탭, 게임 소개의 [아무나와 빠른 시작]·기다리는 방 목록, 대기실의 방 공개
  설정을 뺐다(방은 모두 친구만). 서버 API는 남겨 두고 화면에서만 부르지 않는다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-08 20:42:46 +09:00
parent 1e1408302a
commit 19c163f4d2
41 changed files with 215 additions and 264 deletions

View File

@@ -0,0 +1,42 @@
import { describe, expect, test } from 'bun:test';
import { OptionSync, optionsKey, withLocks } from './option-sync';
const base = { ruleSet: 'korean', timeControl: { kind: 'perMove', perMoveSec: 30 }, undo: '3' };
const a = { ...base, ruleSet: 'free' };
const ab = { ...a, timeControl: { kind: 'none', perMoveSec: 30 } };
describe('OptionSync', () => {
test('in sync: every room update is followed', () => {
const s = new OptionSync();
expect(s.received(base)).toBe(true);
expect(s.received(a)).toBe(true);
});
test('two quick clicks: a stale update and the first echo do not undo the second click', () => {
const s = new OptionSync();
s.sent(base, a);
s.sent(a, ab);
expect(s.received(base)).toBe(false); // someone joined before our first change reached the server
expect(s.received(a)).toBe(false); // echo of the first click
expect(s.received(a)).toBe(false); // another update between the two echoes
expect(s.received(ab)).toBe(true); // caught up
expect(s.received(base)).toBe(true); // later server change (e.g. game switch) is followed again
});
test('a server-side change we did not send (admin lock) is followed', () => {
const s = new OptionSync();
s.sent(base, a);
expect(s.received({ ...base, undo: 'off' })).toBe(true);
});
test('key order does not matter', () => {
expect(optionsKey({ x: 1, y: { b: 2, a: 1 } })).toBe(optionsKey({ y: { a: 1, b: 2 }, x: 1 }));
});
});
test('withLocks keeps locked paths from the current options', () => {
const current = { ruleSet: 'renju', timeControl: { kind: 'perMove', perMoveSec: 45 }, undo: '3' };
const next = { ruleSet: 'korean', timeControl: { kind: 'none', perMoveSec: 45 }, undo: '1' };
expect(withLocks(next, current, ['ruleSet', 'timeControl.kind'])).toEqual({ ruleSet: 'renju', timeControl: { kind: 'perMove', perMoveSec: 45 }, undo: '1' });
expect(withLocks(next, current, [])).toBe(next);
});

View File

@@ -0,0 +1,55 @@
/**
* Lobby settings are sent on every change (no save button). This keeps the host's screen from jumping back
* when a room update that was already on its way (e.g. someone joined) still carries older options.
*/
/** JSON with sorted object keys, so equal options compare equal whatever order their keys were built in. */
export function optionsKey(v: unknown): string {
return JSON.stringify(v, (_k, x: unknown) =>
x && typeof x === 'object' && !Array.isArray(x) ? Object.fromEntries(Object.entries(x).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) : x,
);
}
/** Copies the locked option paths (e.g. `timeControl.kind`) from the room's current options, as the server does. */
export function withLocks<T>(next: T, current: T, locked: string[]): T {
if (!locked.length) return next;
const out = structuredClone(next) as Record<string, unknown>;
for (const path of locked) {
const keys = path.split('.');
let src: unknown = current;
for (const k of keys) src = (src as Record<string, unknown> | undefined)?.[k];
if (src === undefined) continue;
let dst = out;
for (const k of keys.slice(0, -1)) {
if (typeof dst[k] !== 'object' || dst[k] === null) dst[k] = {};
dst = dst[k] as Record<string, unknown>;
}
dst[keys[keys.length - 1]!] = structuredClone(src);
}
return out as T;
}
/**
* While changes are on their way: [server options before the first change, each sent options...]; empty when in sync.
*/
export class OptionSync {
private history: string[] = [];
/** Call before sending `sent`; `server` is the room's options as last received. */
sent(server: unknown, sent: unknown): void {
if (!this.history.length) this.history = [optionsKey(server)];
this.history.push(optionsKey(sent));
}
/** A room update arrived. True: show the server's options. False: it is older than our latest change, keep ours. */
received(server: unknown): boolean {
const i = this.history.lastIndexOf(optionsKey(server));
if (i >= 0 && i < this.history.length - 1) {
this.history = this.history.slice(i);
return false;
}
// Caught up with our last change, or changed on the server (admin, game switch): follow the server.
this.history = [];
return true;
}
}