feat: Update routing and websocket configuration for game state management

This commit is contained in:
2025-12-11 10:24:51 +01:00
parent 13038b0cb9
commit 683ad58efe
6 changed files with 11 additions and 17 deletions

View File

@@ -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")

View File

@@ -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) }
)
}

View File

@@ -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))
)

View File

@@ -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]