-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DRAW-412 이미 게임중인 유저 중복 참여 방지 #16
base: feature/DRAW-347
Are you sure you want to change the base?
Changes from 3 commits
f1729d9
099811d
b29f701
fd7d2ab
2c480ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,17 @@ package com.xorker.draw.websocket.handler | |
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.xorker.draw.auth.token.TokenUseCase | ||
import com.xorker.draw.exception.AlreadyPlayingPlayerException | ||
import com.xorker.draw.exception.InvalidRequestValueException | ||
import com.xorker.draw.exception.UnAuthenticationException | ||
import com.xorker.draw.exception.XorkerException | ||
import com.xorker.draw.mafia.MafiaGameUseCase | ||
import com.xorker.draw.support.logging.defaultApiJsonMap | ||
import com.xorker.draw.support.logging.logger | ||
import com.xorker.draw.support.logging.registerRequestId | ||
import com.xorker.draw.user.User | ||
import com.xorker.draw.user.UserId | ||
import com.xorker.draw.websocket.exception.WebSocketExceptionHandler | ||
import com.xorker.draw.websocket.message.request.RequestAction | ||
import com.xorker.draw.websocket.message.request.WebSocketRequest | ||
import com.xorker.draw.websocket.message.request.WebSocketRequestParser | ||
|
@@ -32,6 +35,7 @@ internal abstract class BaseWebSocketHandler( | |
private val parser: WebSocketRequestParser, | ||
private val tokenUseCase: TokenUseCase, | ||
private val gameUseCase: MafiaGameUseCase, | ||
private val webSocketExceptionHandler: WebSocketExceptionHandler, | ||
) : TextWebSocketHandler() { | ||
private val logger = logger() | ||
|
||
|
@@ -40,18 +44,26 @@ internal abstract class BaseWebSocketHandler( | |
abstract fun afterDisconnect(session: Session?, status: CloseStatus) | ||
|
||
override fun afterConnectionEstablished(session: WebSocketSession) { | ||
registerRequestId() | ||
val user = getUser(session) ?: throw UnAuthenticationException() | ||
val locale = session.getHeader(HEADER_LOCALE) ?: throw InvalidRequestValueException | ||
try { | ||
registerRequestId() | ||
val user = getUser(session) ?: throw UnAuthenticationException() | ||
|
||
val sessionDto = SessionWrapper(session, user, locale) | ||
setupMdc(sessionDto) | ||
sessionManager.registerSession(sessionDto) | ||
if (sessionManager.getSession(user.id) != null) { | ||
throw AlreadyPlayingPlayerException | ||
} | ||
|
||
val locale = session.getHeader(HEADER_LOCALE) ?: throw InvalidRequestValueException | ||
|
||
val sessionDto = SessionWrapper(session, user, locale) | ||
setupMdc(sessionDto) | ||
sessionManager.registerSession(sessionDto) | ||
|
||
try { | ||
afterConnect(sessionDto) | ||
} catch (ex: XorkerException) { | ||
webSocketExceptionHandler.handleXorkerException(session, RequestAction.INIT, ex) | ||
throw ex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P4 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. throw는 세션을 끊김 위해 던지는 것으로 공통 응답처리는 63번째 라인이 하고 있습니다 |
||
} finally { | ||
log(sessionDto.id, "WS_CONNECT") | ||
log(SessionId(session.id), "WS_CONNECT") | ||
MDC.clear() | ||
} | ||
} | ||
|
@@ -73,6 +85,8 @@ internal abstract class BaseWebSocketHandler( | |
|
||
try { | ||
action(sessionDto, request) | ||
} catch (ex: XorkerException) { | ||
webSocketExceptionHandler.handleXorkerException(session, request.action, ex) | ||
} finally { | ||
log(sessionId, request) | ||
MDC.clear() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ data object AlreadyJoinRoomException : ClientException("c005", "이미 참여한 | |
data object InvalidRequestOnlyMyTurnException : ClientException("c006", "요청자의 차례가 아니라서 처리 불가능") { private fun readResolve(): Any = InvalidRequestOnlyMyTurnException } | ||
data object InvalidRequestOtherPlayingException : ClientException("c007", "진행 중인 게임 방이 있습니다.") { private fun readResolve(): Any = InvalidRequestOtherPlayingException } | ||
data object AlreadyPlayingRoomException : ClientException("c008", "진행 중인 게임 방에는 참여할 수 없습니다.") { private fun readResolve(): Any = AlreadyPlayingRoomException } | ||
data object AlreadyPlayingPlayerException : ClientException("c010", "한 유저가 여러번 접속 시도를 하고 있습니다.") { private fun readResolve(): Any = AlreadyPlayingRoomException } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1 |
||
|
||
//endregion | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3
sessionManager.unregisterSession(session.id) 로직도 추가하면 좋을 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
세션 끊김 공통 부분이 실행되어 해당 파트에서 처리됩니다