-
Notifications
You must be signed in to change notification settings - Fork 3
[feat] 재연결 로직 구현 #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
[feat] 재연결 로직 구현 #102
Changes from 49 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
d32fa2c
:recycle: destination 생성 위치 변경
sehee123 4a87b5b
chore: Java 스타일 수정
2ebc45b
:sparkles: subscribe 이벤트 리스너 구현
sehee123 22e2dce
Merge remote-tracking branch 'origin/dev' into feat/34
sehee123 211a772
Merge remote-tracking branch 'origin/dev' into feat/34
sehee123 fb25877
:recycle: 재연결 중간 커밋
sehee123 7be49b7
Merge remote-tracking branch 'origin/dev' into feat/34
sehee123 51efbed
:sparkles: 재연결 로직 완료
sehee123 5ba8a13
chore: Java 스타일 수정
07da462
:recycle: 테스트값 원복
sehee123 6ce1897
:recycle: 재입장 시 기본 방 세팅 값 브로드캐스트
sehee123 527a6c5
chore: Java 스타일 수정
bde0694
:recycle: 중복검사 제거
sehee123 bdc1700
Merge remote-tracking branch 'origin/feat/34' into feat/34
sehee123 4abe282
:recycle: remove 위치 변경
sehee123 849ef71
chore: Java 스타일 수정
bc3fd2b
:recycle: test 수정
sehee123 435d8f0
Merge remote-tracking branch 'origin/feat/34' into feat/34
sehee123 05b3c60
Merge remote-tracking branch 'origin/dev' into feat/34
sehee123 781c283
:recycle: NPE 보완
sehee123 fd9baf5
:recycle: RoomEventType reconnect 추가
sehee123 fd9aff1
chore: Java 스타일 수정
7bd4453
:recycle: 리뷰내용 반영
sehee123 e3dcb00
Merge remote-tracking branch 'origin/feat/34' into feat/34
sehee123 15bfbab
chore: Java 스타일 수정
700c734
:recycle: 리뷰내용 반영
sehee123 4af5a2c
Merge remote-tracking branch 'origin/feat/34' into feat/34
sehee123 147ab05
chore: Java 스타일 수정
31d1f76
:recycle: 패키지 소문자변경
sehee123 1b54ded
Merge remote-tracking branch 'origin/feat/34' into feat/34
sehee123 357443d
Merge remote-tracking branch 'origin/dev' into feat/34
sehee123 6061c87
:recycle: 오류 해결
sehee123 cb1f75d
chore: Java 스타일 수정
3914981
:recycle: 리뷰 반영 - util 추가, 메소드명 수정, 널세이프수정
sehee123 e8616f4
Merge remote-tracking branch 'origin/feat/34' into feat/34
sehee123 f1dd3a2
chore: Java 스타일 수정
ba3e466
:bug: oldSession 관리 순서 변경
sehee123 a568032
:recycle: 테스트 수정
sehee123 e25f2f2
Merge remote-tracking branch 'origin/feat/34' into feat/34
sehee123 cce37c4
chore: Java 스타일 수정
3aef18f
:recycle: 리뷰 반영 s 삭제
sehee123 6a5ad37
Merge remote-tracking branch 'origin/feat/34' into feat/34
sehee123 c506712
chore: Java 스타일 수정
5a1b865
:recycle: 재입장시 connect 상태 변경, 응답 추가
sehee123 6424848
:recycle: 스레드 풀 1-> 2 변경
sehee123 0e644b7
Merge remote-tracking branch 'origin/feat/34' into feat/34
sehee123 b408205
chore: Java 스타일 수정
cbb9a72
Merge remote-tracking branch 'origin/dev' into feat/34
sehee123 fc37e91
Merge remote-tracking branch 'origin/feat/34' into feat/34
sehee123 f9606ba
:white_check_mark: test 코드추가
sehee123 83544c5
chore: Java 스타일 수정
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,17 @@ | ||
| package io.f1.backend.domain.game.model; | ||
|
|
||
| import io.f1.backend.domain.question.entity.Question; | ||
| import io.f1.backend.global.exception.CustomException; | ||
| import io.f1.backend.global.exception.errorcode.RoomErrorCode; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
|
|
@@ -30,7 +34,7 @@ public class Room { | |
|
|
||
| private Map<String, Player> playerSessionMap = new ConcurrentHashMap<>(); | ||
|
|
||
| private Map<Long, String> userIdSessionMap = new ConcurrentHashMap<>(); | ||
| private final Set<Long> validatedUserIds = new HashSet<>(); | ||
|
|
||
| private final LocalDateTime createdAt = LocalDateTime.now(); | ||
|
|
||
|
|
@@ -47,6 +51,26 @@ public Room(Long id, RoomSetting roomSetting, GameSetting gameSetting, Player ho | |
| this.host = host; | ||
| } | ||
|
|
||
| public void addValidatedUserId(Long userId) { | ||
| validatedUserIds.add(userId); | ||
| } | ||
|
|
||
| public int getCurrentUserCnt() { | ||
| return validatedUserIds.size(); | ||
| } | ||
|
|
||
| public void addPlayer(String sessionId, Player player) { | ||
| Long userId = player.getId(); | ||
| if (!validatedUserIds.contains(userId)) { | ||
| throw new CustomException(RoomErrorCode.ROOM_ENTER_REQUIRED); | ||
| } | ||
|
|
||
| if (isHost(userId)) { | ||
| player.toggleReady(); | ||
| } | ||
| playerSessionMap.put(sessionId, player); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 로직을 room 내부로 옮기니까 서비스 코드가 간결해지고, 가독성이 좋아진 것 같습니다 ! 👍 |
||
|
|
||
| public boolean isHost(Long id) { | ||
| return this.host.getId().equals(id); | ||
| } | ||
|
|
@@ -67,14 +91,18 @@ public void updateTimer(ScheduledFuture<?> timer) { | |
| this.timer = timer; | ||
| } | ||
|
|
||
| public void removeUserId(Long id) { | ||
| this.userIdSessionMap.remove(id); | ||
| } | ||
|
|
||
| public void removeSessionId(String sessionId) { | ||
| this.playerSessionMap.remove(sessionId); | ||
| } | ||
|
|
||
| public void removeValidatedUserId(Long userId) { | ||
| validatedUserIds.remove(userId); | ||
| } | ||
|
|
||
| public void removeUserId(Long userId) { | ||
| validatedUserIds.remove(userId); | ||
| } | ||
|
|
||
| public void increasePlayerCorrectCount(String sessionId) { | ||
| this.playerSessionMap.get(sessionId).increaseCorrectCount(); | ||
| } | ||
|
|
@@ -83,11 +111,34 @@ public Question getCurrentQuestion() { | |
| return questions.get(currentRound - 1); | ||
| } | ||
|
|
||
| public Boolean isPlaying() { | ||
| public boolean isPlaying() { | ||
| return state == RoomState.PLAYING; | ||
| } | ||
|
|
||
| public void increaseCurrentRound() { | ||
| currentRound++; | ||
| } | ||
|
|
||
| public void reconnectSession(String oldSessionId, String newSessionId) { | ||
| Player player = playerSessionMap.get(oldSessionId); | ||
| removeSessionId(oldSessionId); | ||
| player.updateState(ConnectionState.CONNECTED); | ||
| playerSessionMap.put(newSessionId, player); | ||
| } | ||
|
|
||
| public void updatePlayerConnectionState(String sessionId, ConnectionState newState) { | ||
| playerSessionMap.get(sessionId).updateState(newState); | ||
| } | ||
|
|
||
| public boolean isExit(String sessionId) { | ||
| return playerSessionMap.get(sessionId) == null; | ||
| } | ||
|
|
||
| public boolean isLastPlayer(String sessionId) { | ||
| long connectedCount = | ||
| playerSessionMap.values().stream() | ||
| .filter(player -> player.getState() == ConnectionState.CONNECTED) | ||
| .count(); | ||
| return connectedCount == 1 && playerSessionMap.containsKey(sessionId); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API 명세서에 /auth/me response를 수정했습니다. 해당 PR이 merge가 되면 재연결 로직이 구현됨에 따라 명세서가 수정되었다고 말씀드리면 될 것 같습니다 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이부분은 재연결때문에 추가한건 아니였고, 추후에 1:1 응답에서 추가될 예정이라서 그부분 구현하고나서 제가 말씀드리겠습니다!
감사합니다.. 💪