Skip to content
Merged
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 @@ -31,11 +31,12 @@
import io.f1.backend.domain.game.store.RoomRepository;
import io.f1.backend.domain.quiz.app.QuizService;
import io.f1.backend.domain.quiz.entity.Quiz;
import io.f1.backend.global.exception.CustomException;
import io.f1.backend.global.exception.errorcode.RoomErrorCode;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.hibernate.boot.model.naming.IllegalIdentifierException;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -91,18 +92,18 @@ public void enterRoom(RoomValidationRequest request) {
Room room = findRoom(request.roomId());

if (room.getState().equals(RoomState.PLAYING)) {
throw new IllegalArgumentException("403 게임이 진행중입니다.");
throw new CustomException(RoomErrorCode.ROOM_GAME_IN_PROGRESS);
}

int maxUserCnt = room.getRoomSetting().maxUserCount();
int currentCnt = room.getUserIdSessionMap().size();
if (maxUserCnt == currentCnt) {
throw new IllegalArgumentException("403 정원이 모두 찼습니다.");
throw new CustomException(RoomErrorCode.ROOM_USER_LIMIT_REACHED);
}

if (room.getRoomSetting().locked()
&& !room.getRoomSetting().password().equals(request.password())) {
throw new IllegalArgumentException("401 비밀번호가 일치하지 않습니다.");
throw new CustomException(RoomErrorCode.WRONG_PASSWORD);
}

room.getUserIdSessionMap().put(getCurrentUserId(), PENDING_SESSION_ID);
Expand Down Expand Up @@ -201,7 +202,7 @@ private Player getRemovePlayer(Room room, String sessionId) {
Player removePlayer = room.getPlayerSessionMap().get(sessionId);
if (removePlayer == null) {
room.removeUserId(getCurrentUserId());
throw new IllegalIdentifierException("404 세션 없음 비정상적인 퇴장 요청");
throw new CustomException(RoomErrorCode.SOCKET_SESSION_NOT_FOUND);
}
return removePlayer;
}
Expand All @@ -217,7 +218,7 @@ private Player createPlayer() {
private Room findRoom(Long roomId) {
return roomRepository
.findRoom(roomId)
.orElseThrow(() -> new IllegalArgumentException("404 존재하지 않는 방입니다."));
.orElseThrow(() -> new CustomException(RoomErrorCode.ROOM_NOT_FOUND));
}

private boolean isLastPlayer(Room room, String sessionId) {
Expand All @@ -244,9 +245,7 @@ private void changeHost(Room room, String hostSessionId) {
Player nextHost =
playerSessionMap.get(
nextHostSessionId.orElseThrow(
() ->
new IllegalArgumentException(
"방장 교체 불가 - 404 해당 세션 플레이어는 존재하지않습니다.")));
() -> new CustomException(RoomErrorCode.SOCKET_SESSION_NOT_FOUND)));

room.updateHost(nextHost);
log.info("user_id:{} 방장 변경 완료 ", nextHost.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,16 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
throw new IllegalArgumentException("Stomp command required");
}

switch (command) {
case CONNECT -> log.info("CONNECT : 세션 연결 - sessionId = {}", sessionId);

case SUBSCRIBE -> {
if (destination != null && sessionId != null) {
log.info("SUBSCRIBE : 구독 시작 destination = {}", destination);
}
if (command.equals(StompCommand.CONNECT)) {
log.info("CONNECT : 세션 연결 - sessionId = {}", sessionId);
} else if (command.equals(StompCommand.SUBSCRIBE)) {
if (destination != null && sessionId != null) {
log.info("SUBSCRIBE : 구독 시작 destination = {}", destination);
}

case SEND -> log.info("SEND : 요청 destination = {}", destination);

case DISCONNECT -> log.info("DISCONNECT : 연결 해제 sessionId = {}", sessionId);

default -> throw new IllegalStateException("Unexpected command: " + command);
} else if (command.equals(StompCommand.SEND)) {
log.info("SEND : 요청 destination = {}", destination);
} else if (command.equals(StompCommand.DISCONNECT)) {
log.info("DISCONNECT : 연결 해제 sessionId = {}", sessionId);
}

return message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public enum RoomErrorCode implements ErrorCode {
ROOM_USER_LIMIT_REACHED("E403002", HttpStatus.FORBIDDEN, "정원이 모두 찼습니다."),
ROOM_GAME_IN_PROGRESS("E403003", HttpStatus.FORBIDDEN, "게임이 진행 중 입니다."),
ROOM_NOT_FOUND("E404005", HttpStatus.NOT_FOUND, "존재하지 않는 방입니다."),
WRONG_PASSWORD("E401006", HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지않습니다.");
WRONG_PASSWORD("E401006", HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지않습니다."),
SOCKET_SESSION_NOT_FOUND("E404006", HttpStatus.NOT_FOUND, "존재하지 않는 소켓 세션입니다.");

private final String code;

Expand Down