feat: Update routing and websocket configuration for game state management (#109)
Reviewed-on: #109
This commit is contained in:
@@ -21,7 +21,7 @@ class WebsocketController @Inject()(
|
||||
)(implicit system: ActorSystem, mat: Materializer) extends AbstractController(cc) {
|
||||
|
||||
def socket(): WebSocket = WebSocket.accept[String, String] { request =>
|
||||
val session = request.cookies.get("sessionId")
|
||||
val session = request.cookies.get("accessToken")
|
||||
if (session.isEmpty) throw new Exception("No session cookie found")
|
||||
val userOpt = sessionManger.getUserBySession(session.get.value)
|
||||
if (userOpt.isEmpty) throw new Exception("Invalid session")
|
||||
|
||||
@@ -2,13 +2,13 @@ package dto.subDTO
|
||||
|
||||
import de.knockoutwhist.cards.Hand
|
||||
|
||||
case class HandDTO(card: List[CardDTO])
|
||||
case class HandDTO(cards: List[CardDTO])
|
||||
|
||||
object HandDTO {
|
||||
|
||||
def apply(hand: Hand): HandDTO = {
|
||||
HandDTO(
|
||||
card = hand.cards.zipWithIndex.map { case (card, idx) => CardDTO(card, idx) }
|
||||
cards = hand.cards.zipWithIndex.map { case (card, idx) => CardDTO(card, idx) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ object TrickDTO {
|
||||
|
||||
def apply(trick: Trick): TrickDTO = {
|
||||
TrickDTO(
|
||||
cards = trick.cards.map { case (card, player) => player.id.toString -> CardDTO(card) },
|
||||
cards = trick.cards.map { case (card, player) => player.name -> CardDTO(card) },
|
||||
firstCard = trick.firstCard.map(card => CardDTO(card)),
|
||||
winner = trick.winner.map(player => PlayerDTO(player))
|
||||
)
|
||||
|
||||
@@ -46,13 +46,13 @@ class UserSession(val user: User, val host: Boolean, val gameLobby: GameLobby) e
|
||||
case "StartGame" =>
|
||||
gameLobby.startGame(user)
|
||||
case "PlayCard" =>
|
||||
val maybeCardIndex: Option[String] = (data \ "cardindex").asOpt[String]
|
||||
val maybeCardIndex: Option[Int] = (data \ "cardindex").asOpt[Int]
|
||||
maybeCardIndex match {
|
||||
case Some(index) =>
|
||||
val session = gameLobby.getUserSession(user.id)
|
||||
gameLobby.playCard(session, index.toInt)
|
||||
gameLobby.playCard(session, index)
|
||||
case None =>
|
||||
println("Card Index not found or is not a number.")
|
||||
println("Card Index not found or is not a number." + data)
|
||||
}
|
||||
case "PickTrumpsuit" =>
|
||||
val maybeSuitIndex: Option[Int] = (data \ "suitIndex").asOpt[Int]
|
||||
@@ -74,6 +74,10 @@ class UserSession(val user: User, val host: Boolean, val gameLobby: GameLobby) e
|
||||
}
|
||||
case "ReturnToLobby" =>
|
||||
gameLobby.returnToLobby(this)
|
||||
case "LeaveGame" =>
|
||||
gameLobby.leaveGame(user.id, false)
|
||||
case _ =>
|
||||
println("Unknown event type: " + eventType + " with data: " + data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user