Skip to content

Commit

Permalink
Merge pull request #82 from YAPP-Github/develop
Browse files Browse the repository at this point in the history
2024.08.27 운영 배포
  • Loading branch information
comforest authored Aug 27, 2024
2 parents 9c2fc01 + 1bb6b50 commit 3547c79
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.xorker.draw.log

import org.springframework.boot.web.servlet.FilterRegistrationBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.Ordered

@Configuration
class ApiLoggerFilterConfig {
@Bean
fun apiLogFilter(filter: ApiLoggingFilter): FilterRegistrationBean<ApiLoggingFilter> {
val bean = FilterRegistrationBean<ApiLoggingFilter>()

bean.filter = filter
bean.order = Ordered.HIGHEST_PRECEDENCE
bean.urlPatterns = listOf("/api/*")

return bean
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ import jakarta.servlet.Filter
import jakarta.servlet.FilterChain
import jakarta.servlet.ServletRequest
import jakarta.servlet.ServletResponse
import jakarta.servlet.annotation.WebFilter
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.slf4j.MDC
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import org.springframework.stereotype.Component
import org.springframework.web.util.ContentCachingRequestWrapper
import org.springframework.web.util.ContentCachingResponseWrapper

@Component
@WebFilter(urlPatterns = ["/api/*"])
@Order(Ordered.HIGHEST_PRECEDENCE)
class ApiLoggingFilter(
private val objectMapper: ObjectMapper,
) : Filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.xorker.draw.mafia.MafiaKeyword
import com.xorker.draw.mafia.MafiaPhase
import com.xorker.draw.mafia.MafiaPhaseMessenger
import com.xorker.draw.mafia.MafiaPlayer
import com.xorker.draw.room.RoomId
import com.xorker.draw.user.UserId
import com.xorker.draw.websocket.SessionMessage
import com.xorker.draw.websocket.broker.WebSocketBroadcaster
Expand Down Expand Up @@ -48,14 +49,21 @@ internal class MafiaPhaseMessengerImpl(
MafiaPhaseWaitBody(
room.id,
room.players.map { it.toResponse(room.owner) }.toList(),
this.gameOption.toResponse(),
gameOption.toResponse(),
),
)

is MafiaPhase.Ready -> MafiaPhaseReadyMessage(
MafiaPhaseReadyBody(
startTime = phase.job.startTime,
mafiaGameInfo = generateMafiaGameInfoMessage(phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption),
mafiaGameInfo = generateMafiaGameInfoMessage(
roomId = room.id,
isRandomMatching = room.isRandomMatching,
mafiaPlayer = phase.mafiaPlayer,
turnList = phase.turnList,
keyword = phase.keyword,
gameOption = gameOption,
),
),
)

Expand All @@ -66,15 +74,29 @@ internal class MafiaPhaseMessengerImpl(
startTurnTime = phase.job.startTime,
draw = phase.getDraw(),
currentDraw = phase.getCurrentDraw(),
mafiaGameInfo = generateMafiaGameInfoMessage(phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption),
mafiaGameInfo = generateMafiaGameInfoMessage(
roomId = room.id,
isRandomMatching = room.isRandomMatching,
mafiaPlayer = phase.mafiaPlayer,
turnList = phase.turnList,
keyword = phase.keyword,
gameOption = gameOption,
),
),
)

is MafiaPhase.Vote -> MafiaPhaseVoteMessage(
MafiaPhaseVoteBody(
startTime = phase.job.startTime,
mafiaGameInfo = if (isOrigin.not()) {
generateMafiaGameInfoMessage(phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption)
generateMafiaGameInfoMessage(
roomId = room.id,
isRandomMatching = room.isRandomMatching,
mafiaPlayer = phase.mafiaPlayer,
turnList = phase.turnList,
keyword = phase.keyword,
gameOption = gameOption,
)
} else {
null
},
Expand All @@ -87,7 +109,14 @@ internal class MafiaPhaseMessengerImpl(
MafiaPhaseInferAnswerBody(
startTime = phase.job.startTime,
mafiaGameInfo = if (isOrigin.not()) {
generateMafiaGameInfoMessage(phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption)
generateMafiaGameInfoMessage(
roomId = room.id,
isRandomMatching = room.isRandomMatching,
mafiaPlayer = phase.mafiaPlayer,
turnList = phase.turnList,
keyword = phase.keyword,
gameOption = gameOption,
)
} else {
null
},
Expand All @@ -100,7 +129,14 @@ internal class MafiaPhaseMessengerImpl(
MafiaPhaseEndBody(
startTime = phase.job.startTime,
mafiaGameInfo = if (isOrigin.not()) {
generateMafiaGameInfoMessage(phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption)
generateMafiaGameInfoMessage(
roomId = room.id,
isRandomMatching = room.isRandomMatching,
mafiaPlayer = phase.mafiaPlayer,
turnList = phase.turnList,
keyword = phase.keyword,
gameOption = gameOption,
)
} else {
null
},
Expand All @@ -114,13 +150,17 @@ internal class MafiaPhaseMessengerImpl(
}

private fun generateMafiaGameInfoMessage(
roomId: RoomId,
isRandomMatching: Boolean,
mafiaPlayer: MafiaPlayer,
turnList: List<MafiaPlayer>,
keyword: MafiaKeyword,
gameOption: MafiaGameOption,
): MafiaGameInfoMessage =
MafiaGameInfoMessage(
MafiaGameInfoBody(
roomId = roomId,
isRandomMatching = isRandomMatching,
mafiaUserId = mafiaPlayer.userId,
turnList = turnList,
category = keyword.category,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.xorker.draw.websocket.message.response.dto.phase

import com.xorker.draw.mafia.MafiaGameOption
import com.xorker.draw.mafia.MafiaPlayer
import com.xorker.draw.room.RoomId
import com.xorker.draw.user.UserId
import com.xorker.draw.websocket.ResponseAction
import com.xorker.draw.websocket.SessionMessage
Expand All @@ -14,6 +15,8 @@ data class MafiaGameInfoMessage(
}

data class MafiaGameInfoBody(
val roomId: RoomId,
val isRandomMatching: Boolean,
val mafiaUserId: UserId,
val turnList: List<MafiaPlayer>,
val category: String,
Expand Down
22 changes: 14 additions & 8 deletions core/src/main/kotlin/com/xorker/draw/mafia/MafiaGameRoomService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal class MafiaGameRoomService(
if (gameInfo == null) {
val player = MafiaPlayer(user.id, user.name, generateColor(null))

gameInfo = createGameInfo(session, locale, player)
gameInfo = createGameInfo(session, locale, player, true)
} else {
val room = gameInfo.room

Expand Down Expand Up @@ -108,22 +108,28 @@ internal class MafiaGameRoomService(
.first()
}

private fun createGameInfo(session: Session, locale: String, player: MafiaPlayer): MafiaGameInfo {
val room = createRoom(session, locale, player)
private fun createGameInfo(session: Session, locale: String, player: MafiaPlayer, isRandomMatching: Boolean = false): MafiaGameInfo {
val room = createRoom(session, locale, player, isRandomMatching)
return MafiaGameInfo(
room,
MafiaPhase.Wait,
MafiaGameOption(),
room = room,
phase = MafiaPhase.Wait,
gameOption = MafiaGameOption(),
)
}

private fun createRoom(session: Session, locale: String, player: MafiaPlayer): Room<MafiaPlayer> {
private fun createRoom(session: Session, locale: String, player: MafiaPlayer, isRandomMatching: Boolean): Room<MafiaPlayer> {
val language = locale.lowercase()
if (language !in languages) {
throw InvalidRequestValueException
}

val room = Room(session.roomId, language, player, 10)
val room = Room(
id = session.roomId,
locale = language,
owner = player,
maxMemberNum = 10,
isRandomMatching = isRandomMatching,
)
return room
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ internal class MafiaPhaseEndGameProcessor(
val keyword = endPhase.keyword

endPhase.isMafiaWin = endPhase.answer?.let {
keyword.answer.lowercase() == it.lowercase() // TODO 동의어 처리
val trimmedAnswer = keyword.answer.replace(" ", "")
val trimmedMafiaAnswer = it.replace(" ", "")

trimmedAnswer.lowercase() == trimmedMafiaAnswer.lowercase() // TODO 동의어 처리
} ?: false
}
}
7 changes: 5 additions & 2 deletions domain/src/main/kotlin/com/xorker/draw/room/Room.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface Room<P : Player> {
var owner: P
val maxMemberNum: Int
val players: List<P>
val isRandomMatching: Boolean

fun size(): Int = players.size
fun isEmpty(): Boolean = size() == 0
Expand All @@ -31,14 +32,16 @@ fun <P : Player> Room(
owner: P,
maxMemberNum: Int,
players: MutableList<P> = mutableListOf(owner),
): Room<P> = RoomImpl(id, locale, owner, maxMemberNum, players)
isRandomMatching: Boolean = false,
): Room<P> = RoomImpl(id, locale, owner, maxMemberNum, players, isRandomMatching)

class RoomImpl<P : Player>(
override val id: RoomId,
override val locale: String,
override var owner: P,
override val maxMemberNum: Int,
private val _players: MutableList<P> = mutableListOf(owner),
override val isRandomMatching: Boolean,
) : Room<P> {
override val players: List<P> = _players

Expand All @@ -64,5 +67,5 @@ class RoomImpl<P : Player>(
_players.clear()
}

override fun copy(): Room<P> = RoomImpl(id, locale, owner, maxMemberNum, _players)
override fun copy(): Room<P> = RoomImpl(id, locale, owner, maxMemberNum, _players, isRandomMatching)
}

0 comments on commit 3547c79

Please sign in to comment.