8단계 관리자: 노래 추가·초성 검색·일괄 작업·휴지통·가져오기/내보내기·중복 병합·하이라이트 지정, 가수 별칭, 장르, 통계와 난이도 제안, 방 강제 종료, 수집 실행/멈추기, 새 방 기본 설정·잠금 + 출제 기록(song_plays)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-18 22:27:21 +09:00
parent 7266fc8d25
commit 4165712fac
23 changed files with 2367 additions and 105 deletions

View File

@@ -156,6 +156,8 @@ export class RoomManager {
/** Question time limit for short clips (site setting). */
limitSec?: () => number;
timing?: Partial<GameTiming>;
/** Site room defaults and locked settings (admin 사이트 설정). */
roomPolicy?: () => { defaults: Record<string, unknown>; locks: string[] };
},
) {
this.saved = new SavedQuizzes(deps.db);
@@ -169,9 +171,23 @@ export class RoomManager {
}
}
/** The site's default room settings (invalid entries are ignored) and locked keys. */
private policy(): { base: RoomConfig; locks: Set<string> } {
const p = this.deps.roomPolicy?.() ?? { defaults: {}, locks: [] };
let base = DEFAULT_ROOM_CONFIG;
for (const [k, v] of Object.entries(p.defaults)) {
if (k === 'title') continue;
const next = applyConfigPatch(base, { [k]: v });
if (typeof next !== 'string') base = next;
}
return { base, locks: new Set(p.locks) };
}
create(hostId: string, init: Partial<RoomConfig> = {}): Room | string {
const nick = this.deps.user(hostId)?.nickname ?? '';
const cfg = applyConfigPatch({ ...DEFAULT_ROOM_CONFIG, title: `${nick}님의 방`.slice(0, 40) }, init);
const { base, locks } = this.policy();
const wanted = Object.fromEntries(Object.entries(init).filter(([k]) => !locks.has(k)));
const cfg = applyConfigPatch({ ...base, title: `${nick}님의 방`.slice(0, 40) }, wanted);
if (typeof cfg === 'string') return cfg;
const room = new Room(this.newCode(), hostId, cfg, this.deps);
// Empty until someone joins: a room created and never entered expires like any empty room.
@@ -297,6 +313,8 @@ export class RoomManager {
setConfig(ws: ServerWebSocket<WsData>, patch: Record<string, unknown>): string | null {
return this.hostAction(ws, (room) => {
const { locks } = this.policy();
if (Object.keys(patch).some((k) => locks.has(k))) return '관리자가 고정한 설정이라 바꿀 수 없어요.';
const next = applyConfigPatch(room.config, patch);
if (typeof next === 'string') return next;
room.config = next;
@@ -478,6 +496,34 @@ export class RoomManager {
});
}
/** 관리자 → 방: every room, private ones too. */
adminList() {
return [...this.rooms.values()].map((r) => ({
code: r.code,
title: r.config.title,
visibility: r.config.visibility,
status: r.status,
host: r.nick(r.hostId),
createdAt: r.createdAt,
game: r.game ? { phase: r.game.phase, n: r.game.n, total: r.game.total } : null,
players: [...r.players].map(([id, p]) => ({ id, nickname: r.nick(id), online: p.conns.size > 0 })),
}));
}
/** 강제 종료: everyone is told and the room is gone. */
adminClose(code: string): boolean {
const room = this.rooms.get(code);
if (!room) return false;
room.send({ t: 'left', code, reason: 'admin' });
for (const [id, p] of room.players) {
for (const ws of p.conns) ws.data.roomCode = undefined;
if (this.where.get(id) === code) this.where.delete(id);
}
room.players.clear();
this.close(room);
return true;
}
/** Every 10s: drop players gone longer than the grace period, close rooms created but never entered. */
sweep(now = Date.now()): void {
for (const room of this.rooms.values()) {