-
Notifications
You must be signed in to change notification settings - Fork 3
[refactor] 게임 시작 요청 리팩토링 #83
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
Conversation
- 방장만 게임 시작 가능 - 이미 플레이 중인 방의 중복 게임시작 방지
|
|
||
| Map<String, Player> playerSessionMap = room.getPlayerSessionMap(); | ||
| if (!validateReadyStatus(room)) { | ||
| throw new CustomException(RoomErrorCode.PLAYER_NOT_READY); |
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.
PLAYER_NOT_READY는 room말고 GameErrorCode로 가는게 의미가 맞지않을까 생각이 듭니다!
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.
말씀처럼 게임과 관련된 에러가 더 적절해보이네요 수정해놓겠습니다 :)
sehee123
left a comment
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.
수고하셨습니다! 유틸로 분리된걸 보니 마음이 편안해지네요 😇
silver-eunjoo
left a comment
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.
코드가 굉장히 깔끔해진 것 같습니다 ! 감사합니다 :)
jiwon1217
left a comment
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.
고생하셨습니다 !
🛰️ Issue Number
Closes #74
🪐 작업 내용
게임 시작 요청 리팩토링 내용
게임 시작의 요청 메시지를 제거했습니다.
type과message모두 없습니다.게임 시작에 문제가 될 수 있는 부분들을 추가하고 예외처리하였습니다. 아래는 추가된 예외입니다.
gameStart의 예외처리가 많아져서 메서드로 분리했습니다.
WebSocketUtils 클래스 분리
알게된 점
저만 바보여서 몰랐을 수 도 있지만... 웹소켓은 HTTP요청 기반의 통신이 아니므로, @AuthenticationPrincipal로 UserPrincipal을 @MessageMapping의 인자로 직접 주입받는 것이 불가능합니다.
Spring Security는 인증 정보를 SecurityContextHolder의 ThreadLocal에 저장하는 방식인데, WebSocket 메시지 처리는 다른 쓰레드에서 이루어지기 때문에 기존의 인증 정보가 공유되지 않습니다.
그래서, 매번 SEND마다 컨텍스트홀더에 인증 정보를 수동으로 계속 주입해줘야 하는... 마치 밥을 한 숟가락 먹을때마다, 밥을 새로 짓는듯한.... 아주 비효율의 끝판왕을 제가 하고 있었습니다. 그래서 기존 방식대로 accessor로 웹소켓세션의 어트리뷰트에 접근하는 방식(WebSocktUtils 사용)으로 유지되면 될 것 같습니다.
+ 나중에 리마인드를 위해 추가로 적어놓았습니다!
@AuthenticationPrincipal은 HTTP 요청에서 SecurityContextHolder에 저장된 인증 객체를 기반으로 스프링이 자동 주입해주는 기능📚 Reference
✅ Check List