Skip to content

Conversation

@sehee123
Copy link
Collaborator

@sehee123 sehee123 commented Jul 29, 2025

🛰️ Issue Number

🪐 작업 내용

  • 웹소켓 세션 id 의 필요성이 없어지면서 걷어내고 UserId 를 key값으로 변경
  • 재연결 로직 변경

disconnected 이벤트 리스너

  • disconnect 되었을때 플레이어 상태 disconnected로 변경
  • 5초뒤 실행 로직이 없으면 무조건 퇴장되었습니다(exit)→ 입장하셨습니다.(initializeRoomSocket)

userRoomRepository

  • userId, roomId 매핑 정보를 담고 있는 userRoomRepository 생성

enterRoom

  • disconnect 이벤트 리스너를 동작시키지 않고 enterRoom 요청할때 (브라우저 새로 켜서 접속)
    • 이전 room 에서
      • 게임중일땐 disconnected
      • 대기중일땐 exit
  • 재연결 유저는 유효성 검사 pass

initializeRoomSocket

  • playerMap에 없는 유저 접근시 enterRoom 로직 실행 안한것이므로 예외처리
  • 재연결 유저는 connected 로 상태 값 변경 후 reconnect 용 응답 보내기

DisconnectTaskManager 를 생성해서 roomService, handleDisconnectedListener 에서 참조

📚 Reference

✅ Check List

  • 코드가 정상적으로 컴파일되나요?
  • 테스트 코드를 통과했나요?
  • merge할 브랜치의 위치를 확인했나요?
  • Label을 지정했나요?

@sehee123 sehee123 self-assigned this Jul 29, 2025
@sehee123 sehee123 added the refactoring 코드 리팩토링 label Jul 29, 2025
@sehee123 sehee123 linked an issue Jul 29, 2025 that may be closed by this pull request
1 task

Long joinedRoomId = userRoomRepository.getRoomId(userId);

if (joinedRoomId != null && !room.getId().equals(joinedRoomId)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[L4-변경제안]
Objects.equals()사용하면 의도가 명확해보여서 좋을 것 같습니다!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

room 내부의 메서드로 분리하면 좋을 것 같습니다 !

return;
}

if (room.getState().equals(RoomState.PLAYING)) {
Copy link
Collaborator

@jiwon1217 jiwon1217 Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

room.isPlaying() 메서드로 대체할 수 있을 것 같습니다 !

}

/* 재연결 */
if (room.getPlayerState(userId).equals(ConnectionState.DISCONNECTED)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

room의 메서드로 분리하는게 좋을 것 같습니다 !


public void cancelDisconnectTask(Long userId) {
ScheduledFuture<?> task = disconnectTasks.remove(userId);
if (task != null && !task.isDone()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위의 조건문과 같은 코드가 반복됩니다 ! 메서드로 분리하면 좋을 것 같습니다

Copy link
Collaborator

@silver-eunjoo silver-eunjoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이미 구현된 이렇게 복잡한 로직을 다시 리팩토링하신 게 대단하셔요.. 확인했습니다 !! 고생하셨어요 :)

roomService.exitRoom(roomId, sessionId, principal);
roomService.exitRoom(roomId, principal);
} catch (Exception e) {
e.printStackTrace();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.printStackTrace() 보다 로깅을 사용하는 것이 좋아보입니다 !

참고 링크: https://dev-jwblog.tistory.com/167

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요부분 로깅은 안봐도되는 부분이라서 지웠어야하는건데 안지웠네욥 ..ㅎㅎ 삭제했습니다!

cancelIfRunning(task);
}

private static void cancelIfRunning(ScheduledFuture<?> future) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static 키워드는 없어도 될 것 같습니다 !


if (room.getRoomSetting().locked()
&& !room.getRoomSetting().password().equals(request.password())) {
&& !room.getRoomSetting().password().equals(request.password())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

room 내부 메서드로 분리하는게 좋아보입니다 !

Copy link
Collaborator

@jiwon1217 jiwon1217 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다 ! 리팩토링을 거치니 확실히 재연결 로직이 간결해보입니다 !

Copy link
Collaborator

@LimKangHyun LimKangHyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

@sehee123 sehee123 merged commit 732a651 into dev Jul 29, 2025
2 checks passed
@sehee123 sehee123 deleted the refactor/148 branch July 29, 2025 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring 코드 리팩토링

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] playerSessionMap key 변경

5 participants