Skip to content

Commit 928b61a

Browse files
committed
♻️ 정상로직에 대한 처리
1 parent 645051f commit 928b61a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ private void exitIfInAnotherRoom(Room room, Long userId) {
150150
}else{
151151
exitRoom(joinedRoomId,getCurrentUserPrincipal());
152152
}
153-
removeUserRepository(userId, joinedRoomId);
154153
}
155154
}
156155

@@ -312,7 +311,9 @@ public void cancelTask(Long userId){
312311

313312
public void exitIfNotPlaying(Long roomId, UserPrincipal principal) {
314313
Room room = findRoom(roomId);
315-
if (!room.isPlaying()) {
314+
if (room.isPlaying()) {
315+
removeUserRepository(principal.getUserId(), roomId);
316+
}else{
316317
exitRoom(roomId, principal);
317318
}
318319
}
@@ -380,6 +381,10 @@ public void exitRoomForDisconnectedPlayer(Long roomId, Player player) {
380381
private void cleanRoom(Room room, Player player) {
381382

382383
Long roomId = room.getId();
384+
Long userId = player.getId();
385+
386+
/* user-room mapping 정보 삭제 */
387+
removeUserRepository(userId, roomId);
383388

384389
/* 방 삭제 */
385390
if (room.isLastPlayer(player)) {
@@ -388,8 +393,6 @@ private void cleanRoom(Room room, Player player) {
388393
return;
389394
}
390395

391-
Long userId = player.getId();
392-
393396
/* 방장 변경 */
394397
if (room.isHost(userId)) {
395398
changeHost(room, player);
@@ -413,4 +416,8 @@ public ConnectionState getPlayerState(Long userId, Long roomId) {
413416
public void removeUserRepository(Long userId, Long roomId) {
414417
userRoomRepository.removeUser(userId, roomId);
415418
}
419+
420+
public boolean isUserInAnyRoom(Long userId){
421+
return userRoomRepository.isUserInAnyRoom(userId);
422+
}
416423
}

0 commit comments

Comments
 (0)