Compare commits

...

3 Commits

Author SHA1 Message Date
EJClaw
e499c79464 슈퍼어드민 디스코드 ID를 저장소에서 제거: 서버 deploy/.env의 SUPERADMIN_DISCORD_IDS에만 둔다
- config: 기본값 삭제(설정이 없으면 슈퍼어드민 없음)
- 테스트·E2E: 만든 ID(900000000000000001/2) 사용
- 문서·README·.env.example·관리자 화면 입력 예시에서 실제 ID 삭제

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 10:36:08 +09:00
EJClaw
4e4c195c79 다시보기: 대국 중 답을 받던 창(무르기·무승부 요청, 뱅! 선택 창)이 화면을 덮지 않게
- 다시보기는 게임의 Side/Board를 읽기 전용으로 그리는데, 그 장면의 요청 창(Sheet, 뱅! 모달)도 함께 떠서
  화면 전체를 덮고 클릭을 막았음(읽기 전용 영역이라 수락/거절도 안 됨). .replay-readonly 안의 창은 숨김
- e2e(replay): 오목 중 무르기 요청→거절을 넣고, 폰 다시보기에서 그 장면에 창이 없고 [다음]이 되는지 확인

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 10:23:14 +09:00
EJClaw
beaee4675d 아무도 앉지 않은 방은 마지막 사람이 [방 나가기]로 나가면 바로 닫기
- 컴퓨터가 있는 방에만 있던 '나가서 앉은 사람이 없으면 바로 닫기'를 모든 방에 적용
  (아무도 들어오지 않은 대기실을 만든 사람이 나가면 목록에서 바로 사라짐)
- 관전자가 남아 있으면 그대로 두고, 마지막 관전자가 나갈 때 닫음
- 사이트를 닫거나 다른 화면으로 간 경우(자리 유지)는 기존 규칙 그대로

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 10:14:29 +09:00
15 changed files with 78 additions and 23 deletions

View File

@@ -34,7 +34,7 @@ cd deploy && docker compose up -d --build
자세한 절차는 [docs/11-deployment-ops.md](docs/11-deployment-ops.md).
## 관리자
`/admin`. 슈퍼어드민은 디스코드 ID `293719842274541579`, `1352267557213573160`(환경 변수 `SUPERADMIN_DISCORD_IDS`), 어드민은 관리자 화면에서 디스코드 ID로 추가한다. 자세한 내용은 [docs/14-admin.md](docs/14-admin.md).
`/admin`. 슈퍼어드민은 서버의 `deploy/.env`에 있는 환경 변수 `SUPERADMIN_DISCORD_IDS`의 디스코드 ID(저장소에는 넣지 않음), 어드민은 관리자 화면에서 디스코드 ID로 추가한다. 자세한 내용은 [docs/14-admin.md](docs/14-admin.md).
## 구조
- `packages/engine` — 게임 공통 타입, 시드 난수, 테스트 도구

View File

@@ -1,8 +1,8 @@
/** Admin site tests (docs/14-admin.md §9). */
import { afterEach, describe, expect, test } from 'bun:test';
import { Client, api, boot, guest, sleep } from './test-utils';
import { Client, TEST_SUPERADMINS, api, boot, guest, sleep } from './test-utils';
const SUPER = '293719842274541579';
const [SUPER, SUPER2] = TEST_SUPERADMINS;
type Booted = ReturnType<typeof boot>;
const running: Booted[] = [];
const clients: Client[] = [];
@@ -47,7 +47,7 @@ describe('roles', () => {
const me = await api(s.base, '/api/admin/me', { cookie: sup.cookie });
expect(me.body.role).toBe('superadmin');
expect((await api(s.base, '/api/me', { cookie: sup.cookie })).body.role).toBe('superadmin');
const sup2 = await discordLogin(s, '1352267557213573160');
const sup2 = await discordLogin(s, SUPER2);
expect((await api(s.base, '/api/admin/me', { cookie: sup2.cookie })).body.role).toBe('superadmin');
});
@@ -60,7 +60,7 @@ describe('roles', () => {
// Pre-register before the person ever logged in.
const add = await api(s.base, '/api/admin/admins', { method: 'POST', cookie: sup.cookie, body: JSON.stringify({ discordId: adminDiscord, note: '친구1' }) });
expect(add.res.status).toBe(200);
expect(add.body.admins.map((a: any) => a.discordId)).toEqual([SUPER, '1352267557213573160', adminDiscord]);
expect(add.body.admins.map((a: any) => a.discordId)).toEqual([SUPER, SUPER2, adminDiscord]);
const adm = await discordLogin(s, adminDiscord);
expect((await api(s.base, '/api/admin/me', { cookie: adm.cookie })).body.role).toBe('admin');
expect((await api(s.base, '/api/admin/users', { cookie: adm.cookie })).res.status).toBe(403);

View File

@@ -14,9 +14,6 @@ export interface Config {
loadTestNoHttpLimits: boolean;
}
/** Superadmin Discord IDs, comma-separated (docs/14-admin.md §2). */
export const DEFAULT_SUPERADMIN = '293719842274541579,1352267557213573160';
export function loadConfig(env: Record<string, string | undefined> = process.env): Config {
const publicOrigin = (env.PUBLIC_ORIGIN ?? 'http://localhost:5173').replace(/\/$/, '');
const extra = (env.ALLOWED_ORIGINS ?? '').split(',').map((s) => s.trim()).filter(Boolean);
@@ -36,6 +33,7 @@ export function loadConfig(env: Record<string, string | undefined> = process.env
secureCookies: publicOrigin.startsWith('https://'),
trustProxy: env.TRUST_PROXY === '1',
loadTestNoHttpLimits: env.LOADTEST_NO_HTTP_LIMITS === '1' && !publicOrigin.startsWith('https://'),
superadminDiscordIds: (env.SUPERADMIN_DISCORD_IDS ?? DEFAULT_SUPERADMIN).split(',').map((s) => s.trim()).filter(Boolean),
/** Superadmin Discord IDs, comma-separated (docs/14-admin.md §2). Only in deploy/.env, never in the repo. */
superadminDiscordIds: (env.SUPERADMIN_DISCORD_IDS ?? '').split(',').map((s) => s.trim()).filter(Boolean),
};
}

View File

@@ -312,6 +312,38 @@ describe('practice rooms close once nobody is there', () => {
expect(h.manager.get(room.code)).toBeUndefined();
});
test('a room nobody joined closes as soon as the host leaves it', () => {
const h = harness();
const room = h.create('A', 'omok', 'public');
room.join(h.conn('A'), 'player');
expect(h.manager.publicRooms('omok')).toHaveLength(1);
room.leave('A');
expect(h.manager.get(room.code)).toBeUndefined();
expect(h.store.openRooms()).toHaveLength(0);
expect(h.manager.publicRooms('omok')).toHaveLength(0);
// Taking a seat in another room frees the lobby seat: same thing.
const first = h.create('B');
const b = h.conn('B');
first.join(b, 'player');
first.disconnect(b);
h.manager.releaseOtherLobbySeats('B', 'other');
expect(h.manager.get(first.code)).toBeUndefined();
});
test('the last person leaving a game on purpose closes it; a spectator still watching keeps it', () => {
const h = harness();
const room = h.create('A');
room.join(h.conn('A'), 'player');
room.join(h.conn('B'), 'player');
room.join(h.conn('S'), 'spectator');
expect(room.start('A')).toBeNull();
room.leave('A');
room.leave('B');
expect(h.manager.get(room.code)).toBe(room); // S is still connected
room.leave('S');
expect(h.manager.get(room.code)).toBeUndefined();
});
test('rooms without computers keep the old timeouts; someone still connected keeps any room', () => {
const h = harness();
const room = h.create('A');

View File

@@ -50,8 +50,8 @@ export class RoomManager {
settings: this.deps.settings,
botDelay: this.deps.botDelay,
onEmpty: (room, why) => {
// Everyone left a room with computer players on purpose: nobody can come back to it, close it now.
if (why === 'leave' && this.byCode.get(room.code) === room && room.hasBots() && !room.hasPeopleSeated()) this.close(room);
// The last person left on purpose and nobody holds a seat (only computers, or nobody joined): close it now.
if (why === 'leave' && this.byCode.get(room.code) === room && !room.hasPeopleSeated()) this.close(room);
},
onSeatChange: (room, userId, seated) => {
if (isBotId(userId)) return;

View File

@@ -7,6 +7,8 @@ import { loadConfig } from './config';
import { startServer, type StartOptions } from './server';
export const ORIGIN = 'http://localhost:5173';
/** Made-up superadmin Discord IDs for tests (the real ones live only in deploy/.env). */
export const TEST_SUPERADMINS = ['900000000000000001', '900000000000000002'] as const;
export function tempDbPath(): string {
const dir = mkdtempSync(join(process.env.TMPDIR ?? tmpdir(), 'bg-test-'));
@@ -14,7 +16,7 @@ export function tempDbPath(): string {
}
export function boot(dbPath = tempDbPath(), extra: Partial<StartOptions> = {}) {
const config = loadConfig({ PORT: '0', DB_PATH: dbPath, PUBLIC_ORIGIN: ORIGIN });
const config = loadConfig({ PORT: '0', DB_PATH: dbPath, PUBLIC_ORIGIN: ORIGIN, SUPERADMIN_DISCORD_IDS: TEST_SUPERADMINS.join(',') });
const app = startServer({ config, log: () => {}, staticDir: null, stopWaitMs: 50, ...extra });
const base = `http://localhost:${app.server.port}`;
return { ...app, base, dbPath, config };

View File

@@ -577,7 +577,7 @@ function Admins() {
<h2>어드민 추가</h2>
<label className="field">
디스코드 ID(숫자)
<input className="input" inputMode="numeric" value={discordId} onChange={(e) => setDiscordId(e.target.value)} placeholder="예: 293719842274541579" />
<input className="input" inputMode="numeric" value={discordId} onChange={(e) => setDiscordId(e.target.value)} placeholder="디스코드 ID (숫자 17~20자리)" />
</label>
<label className="field">
메모(선택)

View File

@@ -1010,6 +1010,11 @@ button.header-user {
.replay-readonly {
display: contents;
}
/* Prompts that waited on a live player (무르기·무승부 요청, 뱅! 선택 창…) can't be answered in a replay: don't let them cover the screen. */
.replay-readonly .sheet-backdrop,
.replay-readonly .bg-modal-back {
display: none;
}
.replay-readonly button,
.replay-readonly [role='button'],
.replay-readonly svg {

View File

@@ -7,5 +7,5 @@ SESSION_SECRET=
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
LOG_LEVEL=info
# Super admin Discord user IDs (comma separated). Default is the site owner.
SUPERADMIN_DISCORD_IDS=293719842274541579,1352267557213573160
# Super admin Discord user IDs (comma separated). Required for the admin site; keep the real IDs out of git.
SUPERADMIN_DISCORD_IDS=

View File

@@ -95,7 +95,7 @@ interface Room {
```
- 한 사용자는 동시에 한 방에만 플레이어로 있을 수 있다(다른 방에 들어가면 이전 방 대기실 자리에서 빠짐. 이전 방이 게임 중이면 "진행 중인 게임이 있어요. 그래도 이동할까요?").
- 제한: 서버 전체 방 2,000개, 사용자당 동시에 만든 방 3개.
- 방 정리(1분마다): 접속이 하나도 없는 방 중 대기실은 10분, 끝난 방·멈춘 방은 30분 동안 활동이 없으면 닫는다. 컴퓨터가 있는 방(연습 방)은 마지막 사람이 나간 때부터 재서 대기실·끝난 방은 1분, 게임 중인 방은 30분 뒤 닫는다(사이트를 닫았으면 아래 규칙대로 1분). 사람이 [방 나가기]로 모두 나가 컴퓨터만 남으면 바로 닫는다.
- 방 정리(1분마다): 접속이 하나도 없는 방 중 대기실은 10분, 끝난 방·멈춘 방은 30분 동안 활동이 없으면 닫는다. 컴퓨터가 있는 방(연습 방)은 마지막 사람이 나간 때부터 재서 대기실·끝난 방은 1분, 게임 중인 방은 30분 뒤 닫는다(사이트를 닫았으면 아래 규칙대로 1분). 마지막 사람이 [방 나가기]로 나가서 자리에 앉은 사람이 없으면(컴퓨터만 남았거나 아무도 들어오지 않은 방) 바로 닫는다.
- 게임 중이거나 끝난 방(대기실 제외)에서 자리에 앉은 사람이 모두 사이트를 닫으면(서버와 연결된 창이 하나도 없으면) 마지막 사람이 닫은 때부터 1분 뒤 정리 때 닫는다. 진행 중인 게임은 무효 처리되고, 관전자는 셈하지 않고, 남아 있던 관전자도 방에서 내보낸다. 대기실은 초대받은 사람이 들어올 수 있으므로 위 규칙을 따른다. 자리가 있는 사람은 다른 화면에 있어도 서버 연결을 유지한다(새로 연 창에서도 `/api/me`의 `activeRoom`이 있으면 연결).
- 방 화면을 벗어나면(홈, 규칙 등) 클라이언트가 `detach`를 보낸다. 자리는 그대로이고 '접속 중'으로 남지만, 방 메시지를 받지 않고 방의 접속 수에서도 빠진다. 그 상태로 사이트를 닫으면 연결 끊김으로 처리한다.

View File

@@ -16,7 +16,7 @@ deploy/
| `DISCORD_CLIENT_ID` / `DISCORD_CLIENT_SECRET` | 디스코드 앱 |
| `SESSION_SECRET` | 짧은 수명 서명 쿠키(OAuth state)용 32바이트 |
| `DB_PATH` | 기본 `/data/app.db` |
| `SUPERADMIN_DISCORD_IDS` | 슈퍼어드민 디스코드 ID(쉼표 구분). 기본 `293719842274541579,1352267557213573160` |
| `SUPERADMIN_DISCORD_IDS` | 슈퍼어드민 디스코드 ID(쉼표 구분). 기본값 없음, 실제 값은 서버 `deploy/.env`에만(저장소에 넣지 않음) |
| `TRUST_PROXY` | `1`이면 Caddy가 붙인 X-Forwarded-For로 IP 판단 |
| `PORT` | 기본 3000 |
| `LOG_LEVEL` | info |

View File

@@ -5,7 +5,7 @@
## 0. 확정된 결정 (2026-10-04)
- 도메인: **game.tkrmagid.kr** 고정. 모든 기능을 완성한 뒤 연결한다.
- 상표명: 친구끼리 쓰는 사이트라 **원래 이름을 그대로 사용**한다.
- 관리자 사이트 추가. 슈퍼어드민은 디스코드 ID `293719842274541579`, 어드민은 디스코드 ID로 추가(`14-admin.md`).
- 관리자 사이트 추가. 슈퍼어드민은 `SUPERADMIN_DISCORD_IDS`의 디스코드 ID, 어드민은 디스코드 ID로 추가(`14-admin.md`).
- 화면은 **PC 버전 중심**으로 만든다(휴대폰은 접어서 지원).
- 게임 규칙 기본값은 관리자 사이트에서 모두 바꿀 수 있으므로, 3절의 기본안은 "처음 값"이다.

View File

@@ -8,7 +8,7 @@
## 2. 권한
| 등급 | 누가 | 할 수 있는 것 |
|---|---|---|
| 슈퍼어드민 | 디스코드 ID `293719842274541579`, `1352267557213573160` (설정 `SUPERADMIN_DISCORD_IDS`, 기본값이 이 두 ID) | 모든 것: 아래 어드민 권한 + 사용자 관리 + 어드민 추가/삭제 |
| 슈퍼어드민 | 서버 `deploy/.env`의 `SUPERADMIN_DISCORD_IDS`에 적은 디스코드 ID (기본값 없음, 개인정보라 저장소에 넣지 않음) | 모든 것: 아래 어드민 권한 + 사용자 관리 + 어드민 추가/삭제 |
| 어드민 | 슈퍼어드민이 디스코드 ID로 등록한 사람 | 관리자 사이트 보기, 게임 설정, 사이트 설정, 방 관리, 기록 보기 |
| 일반 | 그 외(게스트 포함) | 관리자 사이트 접근 불가(관리자 주소로 들어오면 "권한이 없어요") |

View File

@@ -13,9 +13,10 @@ const PORT = Number(process.env.E2E_PORT ?? 4518);
const ORIGIN = `http://localhost:${PORT}`;
const SHOTS = process.env.E2E_SHOTS ?? join(import.meta.dir, '../test-results');
mkdirSync(SHOTS, { recursive: true });
const SUPER = '293719842274541579';
/** Made-up ID; the real superadmin IDs live only in deploy/.env. */
const SUPER = '900000000000000001';
const config = loadConfig({ PORT: String(PORT), DB_PATH: join(mkdtempSync(join(process.env.TMPDIR ?? '/tmp', 'bg-e2e-')), 'app.db'), PUBLIC_ORIGIN: ORIGIN });
const config = loadConfig({ PORT: String(PORT), DB_PATH: join(mkdtempSync(join(process.env.TMPDIR ?? '/tmp', 'bg-e2e-')), 'app.db'), PUBLIC_ORIGIN: ORIGIN, SUPERADMIN_DISCORD_IDS: SUPER });
config.discord = { clientId: 'e2e', clientSecret: 'e2e' };
const app = startServer({
config,

View File

@@ -2,6 +2,7 @@
* E2E (docs/09 §8): game record replay.
* 1) 오목 to the end with two browsers (PC + phone), open 다시 보기 from the result sheet and from 내 정보,
* step through it (buttons, slider, keyboard, play) and check the board changes.
* A asks to take back a move once and B declines: B's replay must not show that request as a sheet over the screen.
* 2) 원카드 (hidden hands): each player's replay shows only their own cards.
* Run: E2E_PORT=4532 bun e2e/replay.e2e.ts (needs apps/web/dist built)
*/
@@ -102,6 +103,14 @@ try {
for (let i = 0; i < 4; i++) {
await a.getByText('내 차례예요').waitFor();
await tapCell(a, 5 + i, 7, false);
if (i === 3) {
// A asks to take the 4th stone back; B declines (the replay keeps that moment).
await waitStones(b, 7);
await a.getByRole('button', { name: /↩ 무르기/ }).click();
await b.getByText('상대가 1수 무르기를 요청했어요').waitFor();
await b.getByRole('button', { name: '거절' }).tap();
await a.getByText('상대의 답을 기다리는 중…').waitFor({ state: 'detached' });
}
await b.getByText('내 차례예요').waitFor();
await tapCell(b, 5 + i, 3, true);
}
@@ -117,7 +126,7 @@ try {
await a.waitForURL(/\/replay\/[0-9A-Z]{26}$/);
replayUrl = a.url();
await a.getByText('게임을 시작했어요.').waitFor();
expectEq((await count(a)).replace(/\s+/g, ' '), '시작 / 전체 9번', 'count at start');
expectEq((await count(a)).replace(/\s+/g, ' '), '시작 / 전체 11번', 'count at start');
await waitStones(a, 0);
await a.getByRole('button', { name: '다음' }).click();
await waitStones(a, 1);
@@ -137,7 +146,7 @@ try {
await step('A(PC): 슬라이더 · 방향키 · 재생/멈춤 · 판은 눌러도 그대로', async () => {
await a.getByLabel('몇 번째 장면인지 고르기').fill('4');
await waitStones(a, 4);
expectEq((await count(a)).replace(/\s+/g, ' '), '4번째 / 전체 9번', 'count after slider');
expectEq((await count(a)).replace(/\s+/g, ' '), '4번째 / 전체 11번', 'count after slider');
await a.locator('body').click({ position: { x: 5, y: 300 } });
await a.keyboard.press('ArrowRight');
await waitStones(a, 5);
@@ -174,6 +183,14 @@ try {
await waitStones(b, 2);
await b.getByText('내가 움직였어요.').waitFor();
await b.screenshot({ path: join(SHOTS, 'replay-3-omok-phone.png') });
// The moment A asked to take a move back: no "수락/거절" sheet covering the screen, the controls still work.
await b.getByLabel('몇 번째 장면인지 고르기').fill('8');
await waitStones(b, 7);
expectEq((await count(b)).replace(/\s+/g, ' '), '8번째 / 전체 11번', 'count at the undo request');
if (await b.getByRole('dialog').count()) throw new Error('the undo request sheet shows in the replay');
await b.screenshot({ path: join(SHOTS, 'replay-3b-undo-request-phone.png') });
await b.getByRole('button', { name: '다음' }).tap();
expectEq((await count(b)).replace(/\s+/g, ' '), '9번째 / 전체 11번', 'count after 다음 at the undo request');
await b.getByRole('button', { name: '끝으로' }).tap();
await waitStones(b, 9);
});