Skip to content

[TASK] roundStartTime 검증 및 fallback 로직 추가 #174

Description

@DDINGJOO

Parent Story

Task 개요

백엔드에서 serverTime 필드를 추가하기 전 임시 조치로,
roundStartTime 값을 검증하고 잘못된 경우 클라이언트 시간으로 fallback 처리합니다.

변경 파일

  • src/domains/freetalk/hooks/useChatWebSocket.js

구현 내용

```javascript
onRoundStart: (data) => {
const roundData = data.data || data;
const now = Date.now();

// serverTime이 없으면 클라이언트 시간 사용 (임시)
const serverTime = roundData.serverTime || now;
let roundStartTime = roundData.roundStartTime || now;

// roundStartTime 검증: 미래 시간이거나 너무 과거면 보정
const MAX_CLOCK_DRIFT = 5000; // 5초 허용
if (roundStartTime > now + MAX_CLOCK_DRIFT) {
    console.warn('[Timer] Invalid roundStartTime (future), using client time');
    roundStartTime = now;
}
if (roundStartTime < now - 120000) { // 2분 이상 과거
    console.warn('[Timer] Invalid roundStartTime (too old), using client time');
    roundStartTime = now;
}

setGameState((prev) => ({
    ...prev,
    roundStartTime: roundStartTime,
    serverTime: serverTime,
    roundDuration: roundData.roundDuration || roundData.roundTimeLimit || 60,
    // ... 기존 필드
}));

}
```

Acceptance Criteria

  • roundStartTime이 미래 시간이면 현재 시간으로 보정
  • roundStartTime이 2분 이상 과거면 현재 시간으로 보정
  • roundStartTime이 없으면 현재 시간 사용
  • console.warn으로 보정 사실 로깅
  • 정상 값은 그대로 사용

테스트 시나리오

  1. 정상 roundStartTime → 그대로 사용
  2. roundStartTime 누락 → 클라이언트 시간 사용
  3. roundStartTime이 미래 → 클라이언트 시간으로 보정
  4. roundStartTime이 너무 과거 → 클라이언트 시간으로 보정

예상 작업량

  • 30분

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions