Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.f1.backend.domain.game.dto.RoomEventType;
import io.f1.backend.domain.game.dto.request.RoomCreateRequest;
import io.f1.backend.domain.game.dto.request.RoomValidationRequest;
import io.f1.backend.domain.game.dto.response.ExitSuccessResponse;
import io.f1.backend.domain.game.dto.response.GameSettingResponse;
import io.f1.backend.domain.game.dto.response.PlayerListResponse;
import io.f1.backend.domain.game.dto.response.RoomCreateResponse;
Expand Down Expand Up @@ -168,9 +169,13 @@ public void exitRoom(Long roomId, String sessionId, UserPrincipal principal) {

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

String destination = getDestination(roomId);

/* 방 삭제 */
if (isLastPlayer(room, sessionId)) {
removeRoom(room);
messageSender.send(
destination, MessageType.EXIT_SUCCESS, new ExitSuccessResponse(true));
return;
}

Expand All @@ -180,17 +185,17 @@ public void exitRoom(Long roomId, String sessionId, UserPrincipal principal) {
}

/* 플레이어 삭제 */
removePlayer(room, sessionId, removePlayer);
boolean isRemoved = removePlayer(room, sessionId, removePlayer);

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

PlayerListResponse playerListResponse = toPlayerListResponse(room);

String destination = getDestination(roomId);

messageSender.send(destination, MessageType.PLAYER_LIST, playerListResponse);
messageSender.send(destination, MessageType.SYSTEM_NOTICE, systemNoticeResponse);
messageSender.send(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[L5-참고의견]
exit_success 타입의 메시지가 브로드캐스팅 되는 형태이기 때문에,
프론트에서 분기 처리가 필요하다는 요청이 전해져야 할 것 같습니다.
(조건 없이 exit_success를 받을 때 구독을 해제하는 형태로 구현하시면 많이 꼬일 것 같습니다..)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

경찬님! 진짜 중요포인트 찝어 주셔서 감사합니다. 브로드캐스팅이아니라 1:1 응답 줄 수 있는 방법 있는걸로 아는데 그렇게 구현 변경하도록 하겠습니다! 👍

destination, MessageType.EXIT_SUCCESS, new ExitSuccessResponse(isRemoved));
}
}

Expand Down Expand Up @@ -307,9 +312,8 @@ private void changeHost(Room room, String hostSessionId) {
log.info("user_id:{} 방장 변경 완료 ", nextHost.getId());
}

private void removePlayer(Room room, String sessionId, Player removePlayer) {
room.removeUserId(removePlayer.getId());
room.removeSessionId(sessionId);
private boolean removePlayer(Room room, String sessionId, Player removePlayer) {
return room.removeUserId(removePlayer.getId()) && room.removeSessionId(sessionId);
}

private String getDestination(Long roomId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public enum MessageType {
CHAT,
QUESTION_RESULT,
RANK_UPDATE,
EXIT_SUCCESS,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.f1.backend.domain.game.dto.response;

public record ExitSuccessResponse(boolean isSuccess) {}
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public void updateRoomState(RoomState newState) {
this.state = newState;
}

public void removeUserId(Long id) {
this.userIdSessionMap.remove(id);
public boolean removeUserId(Long id) {
return this.userIdSessionMap.remove(id) != null;
}

public void removeSessionId(String sessionId) {
this.playerSessionMap.remove(sessionId);
public boolean removeSessionId(String sessionId) {
return this.playerSessionMap.remove(sessionId) != null;
}

public void increasePlayerCorrectCount(String sessionId) {
Expand Down