플레이어가 모두 사이트를 닫으면 게임 중·끝난 방을 1분 뒤 닫기(관전자는 셈하지 않음)

- 게이트웨이가 사용자별 '마지막 소켓이 닫힌 시각'을 기록(offlineSince). 소켓이 하나라도 열려 있으면 사이트에 있는 것
- sweep: 대기실이 아닌 방에서 자리에 앉은 사람(컴퓨터·게임 중 나간 사람 제외)이 모두 사이트를 떠난 지 1분이면
  게임을 무효로 끝내고 방을 닫는다. 관전자가 접속해 있어도 닫고 내보낸다. 대기실은 초대 입장 때문에 기존 규칙 유지
- 홈 등 다른 화면에서 새로 연 창도 자리가 있으면(/api/me activeRoom) 소켓을 연결해 '사이트 열림'으로 남게
- Room.closeByAdmin을 closeWith(summary, notice)로 일반화
- e2e(bots): 오목은 컴퓨터가 3번만 받게(이후 단계 전에 게임이 끝나지 않게), 홈 단계를 원카드 앞으로(턴 시간 초과 방지)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-08 09:47:22 +09:00
parent 0a587a8b98
commit f5671cda70
10 changed files with 229 additions and 34 deletions

View File

@@ -126,3 +126,24 @@ describe('leaving the room page', () => {
expect(room.detached.size).toBe(0);
});
});
describe('on the site or not', () => {
test('offlineSince: null while any socket is open, the close time once the last one closes', async () => {
const s = start();
const g = await guest(s.base, '사이트');
expect(s.gateway.offlineSince(g.id)).toBe(0); // never connected since the server started
const c1 = await connect(s, g);
const c2 = await connect(s, g);
expect(s.gateway.offlineSince(g.id)).toBeNull();
c1.close();
for (let i = 0; i < 50 && !c1.closed; i++) await sleep(10);
await sleep(20);
expect(s.gateway.offlineSince(g.id)).toBeNull(); // another tab is still open
const before = Date.now();
c2.close();
for (let i = 0; i < 50 && s.gateway.offlineSince(g.id) === null; i++) await sleep(10);
expect(s.gateway.offlineSince(g.id)).toBeGreaterThanOrEqual(before);
await connect(s, g);
expect(s.gateway.offlineSince(g.id)).toBeNull();
});
});