Skip to content

Commit 3914981

Browse files
committed
♻️ 리뷰 반영 - util 추가, 메소드명 수정, 널세이프수정
1 parent 6061c87 commit 3914981

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public RoomCreateResponse saveRoom(RoomCreateRequest request) {
9090

9191
Room room = new Room(newId, roomSetting, gameSetting, host);
9292

93-
room.addValidatedUserIds(getCurrentUserId());
93+
room.addValidatedUserId(getCurrentUserId());
9494

9595
roomRepository.saveRoom(room);
9696

@@ -123,7 +123,7 @@ public void enterRoom(RoomValidationRequest request) {
123123
throw new CustomException(RoomErrorCode.WRONG_PASSWORD);
124124
}
125125

126-
room.addValidatedUserIds(getCurrentUserId());
126+
room.addValidatedUserId(getCurrentUserId());
127127
}
128128
}
129129

backend/src/main/java/io/f1/backend/domain/game/model/Room.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public Room(Long id, RoomSetting roomSetting, GameSetting gameSetting, Player ho
5151
this.host = host;
5252
}
5353

54-
public boolean addValidatedUserIds(Long userId) {
55-
return validatedUserIds.add(userId);
54+
public void addValidatedUserId(Long userId) {validatedUserIds.add(userId);
5655
}
5756

5857
public int getCurrentUserCnt() {

backend/src/main/java/io/f1/backend/domain/game/websocket/WebSocketUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ public static UserPrincipal getSessionUser(Message<?> message) {
2222
public static String getDestination(Long roomId) {
2323
return "/sub/room/" + roomId;
2424
}
25+
26+
public static String getRoomSubscriptionDestination(Message<?> message) {
27+
StompHeaderAccessor headerAccessor = StompHeaderAccessor.wrap(message);
28+
return headerAccessor.getDestination();
29+
}
2530
}

backend/src/main/java/io/f1/backend/domain/game/websocket/eventlistener/WebsocketEventListener.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.f1.backend.domain.game.websocket.eventlistener;
22

3+
import static io.f1.backend.domain.game.websocket.WebSocketUtils.getRoomSubscriptionDestination;
34
import static io.f1.backend.domain.game.websocket.WebSocketUtils.getSessionId;
45
import static io.f1.backend.domain.game.websocket.WebSocketUtils.getSessionUser;
56

@@ -39,18 +40,12 @@ public void handleSubscribeListener(SessionSubscribeEvent event) {
3940

4041
Message<?> message = event.getMessage();
4142

42-
StompHeaderAccessor headerAccessor = StompHeaderAccessor.wrap(message);
43-
4443
String sessionId = getSessionId(message);
4544
UserPrincipal principal = getSessionUser(message);
4645

47-
String destination = headerAccessor.getDestination();
48-
49-
if (destination == null) {
50-
// todo 에러처리: 잘못된 구독 주소입니다
51-
return;
52-
}
46+
String destination = getRoomSubscriptionDestination(message);
5347

48+
//todo 인덱스 길이 유효성 추가
5449
String[] subscribeType = destination.split("/");
5550

5651
if (subscribeType[2].equals("room")) {

backend/src/main/java/io/f1/backend/domain/game/websocket/service/SessionService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void handleUserDisconnect(String sessionId, UserPrincipal principal) {
6464
scheduler.schedule(
6565
() -> {
6666
/* 재연결 실패 */
67-
if (userIdSession.get(userId).equals(sessionId)) {
67+
if (sessionId.equals(userIdSession.get(userId))){
6868
roomService.exitIfNotPlaying(roomId, sessionId, principal);
6969
}
7070
removeSession(sessionId, userId);
@@ -75,7 +75,7 @@ public void handleUserDisconnect(String sessionId, UserPrincipal principal) {
7575

7676
public void removeSession(String sessionId, Long userId) {
7777

78-
if (userIdSession.get(userId).equals(sessionId)) {
78+
if (sessionId.equals(userIdSession.get(userId))) {
7979
userIdSession.remove(userId);
8080
}
8181
sessionIdUser.remove(sessionId);

0 commit comments

Comments
 (0)