From c0a86474d7153f96b32e4535a07c97a9a193838a Mon Sep 17 00:00:00 2001 From: HoYeon Lee Date: Wed, 16 Oct 2024 20:44:56 +0900 Subject: [PATCH 1/2] =?UTF-8?q?DRAW-400=20feat:=20Rematching=20Action=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/xorker/draw/websocket/WebSocketController.kt | 6 ++++++ .../kotlin/com/xorker/draw/websocket/WebSocketRouter.kt | 2 ++ .../xorker/draw/websocket/message/request/RequestAction.kt | 2 ++ .../kotlin/com/xorker/draw/mafia/MafiaGameRoomService.kt | 4 ++-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/WebSocketController.kt b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/WebSocketController.kt index 60e40666..413514e4 100644 --- a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/WebSocketController.kt +++ b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/WebSocketController.kt @@ -11,6 +11,7 @@ import com.xorker.draw.mafia.WaitingQueueUseCase import com.xorker.draw.room.RoomId import com.xorker.draw.websocket.message.request.mafia.MafiaGameRandomMatchingRequest import com.xorker.draw.websocket.message.request.mafia.SessionInitializeRequest +import com.xorker.draw.websocket.session.Session import com.xorker.draw.websocket.session.SessionFactory import com.xorker.draw.websocket.session.SessionManager import org.slf4j.MDC @@ -26,6 +27,11 @@ internal class WebSocketController( private val userConnectionUseCase: UserConnectionUseCase, ) { + fun rematch(session: Session) { + userConnectionUseCase.disconnectUser(session.user) + waitingQueueUseCase.enqueue(session.user, session.locale) + } + fun initializeWaitingQueueSession(session: WebSocketSession, request: MafiaGameRandomMatchingRequest) { val sessionDto = sessionFactory.create(session, request) diff --git a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/WebSocketRouter.kt b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/WebSocketRouter.kt index 6ba17b67..1427cc3f 100644 --- a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/WebSocketRouter.kt +++ b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/WebSocketRouter.kt @@ -30,6 +30,7 @@ internal class WebSocketRouter( RequestAction.PING -> sessionManager.setPing(session.id) RequestAction.INIT -> throw InvalidRequestValueException RequestAction.RANDOM_MATCHING -> throw InvalidRequestValueException + RequestAction.REMATCHING -> webSocketController.rematch(session) RequestAction.START_GAME -> mafiaPhaseUseCase.startGame(session.user) RequestAction.DRAW -> mafiaGameUseCase.draw(session.user, request.extractBody()) RequestAction.END_TURN -> mafiaGameUseCase.nextTurnByUser(session.user) @@ -77,6 +78,7 @@ internal class WebSocketRouter( RequestAction.PING -> throw UnSupportedException RequestAction.INIT -> throw UnSupportedException RequestAction.RANDOM_MATCHING -> throw UnSupportedException + RequestAction.REMATCHING -> webSocketController.rematch(sessionDto) RequestAction.START_GAME -> mafiaPhaseUseCase.startGame(sessionDto.user) RequestAction.DRAW -> mafiaGameUseCase.draw(sessionDto.user, request.extractBody()) diff --git a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/request/RequestAction.kt b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/request/RequestAction.kt index ee509e41..8ea9789c 100644 --- a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/request/RequestAction.kt +++ b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/request/RequestAction.kt @@ -10,6 +10,8 @@ enum class RequestAction( @Deprecated("handshake 할 때 초기화") RANDOM_MATCHING("마피아 게임 랜덤 매칭"), + + REMATCHING("새로운 게임 매칭"), START_GAME("마피아 게임 시작"), DRAW("그림 그리기"), END_TURN("턴 넘기기"), diff --git a/core/src/main/kotlin/com/xorker/draw/mafia/MafiaGameRoomService.kt b/core/src/main/kotlin/com/xorker/draw/mafia/MafiaGameRoomService.kt index d4539488..220e82bc 100644 --- a/core/src/main/kotlin/com/xorker/draw/mafia/MafiaGameRoomService.kt +++ b/core/src/main/kotlin/com/xorker/draw/mafia/MafiaGameRoomService.kt @@ -81,7 +81,7 @@ internal class MafiaGameRoomService( val userId = user.id val gameInfo = mafiaGameRepository.getGameInfo(userId) ?: return - if (gameInfo.phase == MafiaPhase.Wait) { + if (gameInfo.phase == MafiaPhase.Wait || gameInfo.phase is MafiaPhase.End) { exitUser(user) return } @@ -102,7 +102,7 @@ internal class MafiaGameRoomService( val userId = user.id val gameInfo = mafiaGameRepository.getGameInfo(userId) ?: return - if (gameInfo.phase != MafiaPhase.Wait) { + if (gameInfo.phase != MafiaPhase.Wait && gameInfo.phase !is MafiaPhase.End) { disconnectUser(user) return } From ca96b8c864e9eab3deda222c00a1d46058275954 Mon Sep 17 00:00:00 2001 From: HoYeon Lee Date: Wed, 16 Oct 2024 22:30:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?DRAW-400=20feat:=20=EA=B2=8C=EC=9E=84=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=ED=99=94=EB=A9=B4=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=B9=A0=EB=A5=B8=20=EB=A7=A4=EC=B9=AD=20=EC=BC=80=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../draw/mafia/phase/MafiaPhaseEndGameProcessor.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhaseEndGameProcessor.kt b/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhaseEndGameProcessor.kt index dc21d8ef..19f489b1 100644 --- a/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhaseEndGameProcessor.kt +++ b/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhaseEndGameProcessor.kt @@ -8,6 +8,7 @@ import com.xorker.draw.mafia.MafiaGameResultRepository import com.xorker.draw.mafia.MafiaPhase import com.xorker.draw.mafia.assertIs import com.xorker.draw.timer.TimerRepository +import java.time.Duration import org.springframework.stereotype.Component @Component @@ -25,10 +26,6 @@ internal class MafiaPhaseEndGameProcessor( val room = gameInfo.room - timerRepository.startTimer(room.id, gameOption.endTime) { - processEndGame(gameInfo) - } - val endPhase = assertAndGetEndPhase(phase) judgeGameResult(endPhase) @@ -39,6 +36,15 @@ internal class MafiaPhaseEndGameProcessor( mafiaGameResultRepository.saveMafiaGameResult(gameInfo) + if (room.isRandomMatching) { + timerRepository.startTimer(room.id, Duration.ofMillis(1)) { + mafiaGameRepository.removeGameInfo(gameInfo) + } + } else { + timerRepository.startTimer(room.id, gameOption.endTime) { + processEndGame(gameInfo) + } + } return endPhase }