Skip to content

Commit

Permalink
Merge pull request #9 from TeamTroublePainter/feature/DRAW-400
Browse files Browse the repository at this point in the history
DRAW-400  빠른 매칭 다시 하기
  • Loading branch information
comforest authored Oct 21, 2024
2 parents e948732 + ca96b8c commit c757d3b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ enum class RequestAction(

@Deprecated("handshake 할 때 초기화")
RANDOM_MATCHING("마피아 게임 랜덤 매칭"),

REMATCHING("새로운 게임 매칭"),
START_GAME("마피아 게임 시작"),
DRAW("그림 그리기"),
END_TURN("턴 넘기기"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit c757d3b

Please sign in to comment.