Skip to content

Commit aad1081

Browse files
committed
♻️ exit 응답 추가
1 parent 4245a04 commit aad1081

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.f1.backend.domain.game.dto.RoomEventType;
1818
import io.f1.backend.domain.game.dto.request.RoomCreateRequest;
1919
import io.f1.backend.domain.game.dto.request.RoomValidationRequest;
20+
import io.f1.backend.domain.game.dto.response.ExitSuccessResponse;
2021
import io.f1.backend.domain.game.dto.response.GameSettingResponse;
2122
import io.f1.backend.domain.game.dto.response.PlayerListResponse;
2223
import io.f1.backend.domain.game.dto.response.RoomCreateResponse;
@@ -168,9 +169,12 @@ public void exitRoom(Long roomId, String sessionId, UserPrincipal principal) {
168169

169170
Player removePlayer = getRemovePlayer(room, sessionId, principal);
170171

172+
String destination = getDestination(roomId);
173+
171174
/* 방 삭제 */
172175
if (isLastPlayer(room, sessionId)) {
173176
removeRoom(room);
177+
messageSender.send(destination, MessageType.EXIT_SUCCESS, new ExitSuccessResponse(true));
174178
return;
175179
}
176180

@@ -180,18 +184,18 @@ public void exitRoom(Long roomId, String sessionId, UserPrincipal principal) {
180184
}
181185

182186
/* 플레이어 삭제 */
183-
removePlayer(room, sessionId, removePlayer);
187+
boolean isRemoved = removePlayer(room, sessionId, removePlayer);
184188

185189
SystemNoticeResponse systemNoticeResponse =
186190
ofPlayerEvent(removePlayer.nickname, RoomEventType.EXIT);
187191

188192
PlayerListResponse playerListResponse = toPlayerListResponse(room);
189193

190-
String destination = getDestination(roomId);
191-
192194
messageSender.send(destination, MessageType.PLAYER_LIST, playerListResponse);
193195
messageSender.send(destination, MessageType.SYSTEM_NOTICE, systemNoticeResponse);
196+
messageSender.send(destination, MessageType.EXIT_SUCCESS, new ExitSuccessResponse(isRemoved));
194197
}
198+
195199
}
196200

197201
public void handlePlayerReady(Long roomId, String sessionId) {
@@ -307,9 +311,8 @@ private void changeHost(Room room, String hostSessionId) {
307311
log.info("user_id:{} 방장 변경 완료 ", nextHost.getId());
308312
}
309313

310-
private void removePlayer(Room room, String sessionId, Player removePlayer) {
311-
room.removeUserId(removePlayer.getId());
312-
room.removeSessionId(sessionId);
314+
private boolean removePlayer(Room room, String sessionId, Player removePlayer) {
315+
return room.removeUserId(removePlayer.getId()) && room.removeSessionId(sessionId);
313316
}
314317

315318
private String getDestination(Long roomId) {

backend/src/main/java/io/f1/backend/domain/game/dto/MessageType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ public enum MessageType {
99
CHAT,
1010
QUESTION_RESULT,
1111
RANK_UPDATE,
12+
EXIT_SUCCESS,
1213
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.f1.backend.domain.game.dto.response;
2+
3+
public record ExitSuccessResponse(boolean isSuccess) {
4+
5+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public void updateRoomState(RoomState newState) {
5656
this.state = newState;
5757
}
5858

59-
public void removeUserId(Long id) {
60-
this.userIdSessionMap.remove(id);
59+
public boolean removeUserId(Long id) {
60+
return this.userIdSessionMap.remove(id) != null;
6161
}
6262

63-
public void removeSessionId(String sessionId) {
64-
this.playerSessionMap.remove(sessionId);
63+
public boolean removeSessionId(String sessionId) {
64+
return this.playerSessionMap.remove(sessionId) != null;
6565
}
6666

6767
public void increasePlayerCorrectCount(String sessionId) {

0 commit comments

Comments
 (0)