Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
421f769cb6 | ||
| bd7a055a09 | |||
|
|
e2a2b56174 | ||
| 2a29ca8cdd | |||
|
|
266cbe7509 | ||
| e8b31b1748 | |||
|
|
8812b0fad4 | ||
| dd5e8e65e5 | |||
|
|
bf6ffeadb0 | ||
| fa3d21e303 | |||
|
|
33efc4e107 | ||
| 8d697fd311 | |||
|
|
b9e60b5d4a | ||
| 270f44cc1f |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -134,6 +134,7 @@ target
|
|||||||
/.project
|
/.project
|
||||||
/.settings
|
/.settings
|
||||||
/RUNNING_PID
|
/RUNNING_PID
|
||||||
|
/knockoutwhistwebfrontend/
|
||||||
/knockoutwhist/
|
/knockoutwhist/
|
||||||
/knockoutwhistweb/.g8/
|
/knockoutwhistweb/.g8/
|
||||||
/knockoutwhistweb/.bsp/
|
/knockoutwhistweb/.bsp/
|
||||||
|
|||||||
35
CHANGELOG.md
35
CHANGELOG.md
@@ -209,3 +209,38 @@
|
|||||||
### Features
|
### Features
|
||||||
|
|
||||||
* FRO-3 FRO-4 Added vue compontents to ingame and lobby ([#100](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/100)) ([194df56](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/194df5691ccda1c21ebe9157c4396a4a21aa921d))
|
* FRO-3 FRO-4 Added vue compontents to ingame and lobby ([#100](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/100)) ([194df56](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/194df5691ccda1c21ebe9157c4396a4a21aa921d))
|
||||||
|
## (2025-12-05)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* BAC-29 Implement Mappers for Common Classes ([#101](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/101)) ([270f44c](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/270f44cc1f3447ffcc33fb19a47c52391c69972b))
|
||||||
|
## (2025-12-06)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* BAC-30 Implement Jackson Mapping via DTOs ([#102](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/102)) ([8d697fd](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/8d697fd311478cf792b4631377de4522ecbda9f7))
|
||||||
|
## (2025-12-10)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* FRO-29 Websocket Communication ([#104](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/104)) ([fa3d21e](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/fa3d21e3038eb07369764850a9ad9badd269ac57))
|
||||||
|
## (2025-12-10)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* BAC-27 Implemented endpoint which returns information about the current state ([#103](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/103)) ([dd5e8e6](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/dd5e8e65e55f02a7618b3c60e8fc7087774e5106))
|
||||||
|
## (2025-12-10)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* FRO-2 Implement Login Component ([#105](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/105)) ([e8b31b1](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/e8b31b174819b5f033034501856c4b1189c4c4ee))
|
||||||
|
## (2025-12-10)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* FRO-20 Create scoreboard component ([#106](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/106)) ([2a29ca8](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/2a29ca8cdd3ef55f6f66f00b5e7727e1b1af1458))
|
||||||
|
## (2025-12-10)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **api:** FRO-14 Create Game ([#107](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/107)) ([bd7a055](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/bd7a055a0944a1c5219f21bb080bf658229f49e9))
|
||||||
|
|||||||
Submodule knockoutwhist updated: ef7397f7f1...10fa4badf0
Submodule knockoutwhistfrontend updated: 575d1b5e8e...0b8a1794a0
@@ -23,12 +23,12 @@ class AuthAction @Inject()(val sessionManager: SessionManager, val parser: BodyP
|
|||||||
case Some(user) =>
|
case Some(user) =>
|
||||||
block(new AuthenticatedRequest(user, request))
|
block(new AuthenticatedRequest(user, request))
|
||||||
case None =>
|
case None =>
|
||||||
Future.successful(Results.Redirect(routes.UserController.login()))
|
Future.successful(Results.Unauthorized)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def getUserFromSession(request: RequestHeader): Option[User] = {
|
protected def getUserFromSession(request: RequestHeader): Option[User] = {
|
||||||
val session = request.cookies.get("sessionId")
|
val session = request.cookies.get("accessToken")
|
||||||
if (session.isDefined)
|
if (session.isDefined)
|
||||||
return sessionManager.getUserBySession(session.get.value)
|
return sessionManager.getUserBySession(session.get.value)
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ class MainMenuController @Inject()(
|
|||||||
)
|
)
|
||||||
Ok(Json.obj(
|
Ok(Json.obj(
|
||||||
"status" -> "success",
|
"status" -> "success",
|
||||||
"redirectUrl" -> routes.IngameController.game(gameLobby.id).url,
|
"gameId" -> gameLobby.id,
|
||||||
"content" -> IngameController.returnInnerHTML(gameLobby, gameLobby.logic.getCurrentState, request.user).toString
|
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
BadRequest(Json.obj(
|
BadRequest(Json.obj(
|
||||||
|
|||||||
94
knockoutwhistweb/app/controllers/StatusController.scala
Normal file
94
knockoutwhistweb/app/controllers/StatusController.scala
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import auth.AuthAction
|
||||||
|
import logic.PodManager
|
||||||
|
import logic.game.GameLobby
|
||||||
|
import logic.user.SessionManager
|
||||||
|
import model.users.User
|
||||||
|
import play.api.libs.json.{JsValue, Json}
|
||||||
|
import play.api.mvc.*
|
||||||
|
import util.WebsocketEventMapper
|
||||||
|
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class StatusController @Inject()(
|
||||||
|
val controllerComponents: ControllerComponents,
|
||||||
|
val sessionManager: SessionManager,
|
||||||
|
val authAction: AuthAction
|
||||||
|
) extends BaseController {
|
||||||
|
|
||||||
|
def requestStatus(): Action[AnyContent] = {
|
||||||
|
Action { implicit request =>
|
||||||
|
val userOpt = getUserFromSession(request)
|
||||||
|
if (userOpt.isEmpty) {
|
||||||
|
Ok(
|
||||||
|
Json.obj(
|
||||||
|
"status" -> "unauthenticated"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
val user = userOpt.get
|
||||||
|
val gameOpt = PodManager.identifyGameOfUser(user)
|
||||||
|
if (gameOpt.isEmpty) {
|
||||||
|
Ok(
|
||||||
|
Json.obj(
|
||||||
|
"status" -> "authenticated",
|
||||||
|
"username" -> user.name,
|
||||||
|
"inGame" -> "false"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
val game = gameOpt.get
|
||||||
|
Ok(
|
||||||
|
Json.obj(
|
||||||
|
"status" -> "authenticated",
|
||||||
|
"username" -> user.name,
|
||||||
|
"inGame" -> "true",
|
||||||
|
"gameId" -> game.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def game(gameId: String): Action[AnyContent] = {
|
||||||
|
Action { implicit request =>
|
||||||
|
val userOpt = getUserFromSession(request)
|
||||||
|
if (userOpt.isEmpty) {
|
||||||
|
Unauthorized("User not authenticated")
|
||||||
|
} else {
|
||||||
|
val user = userOpt.get
|
||||||
|
val gameOpt = PodManager.getGame(gameId)
|
||||||
|
if (gameOpt.isEmpty) {
|
||||||
|
NotFound("Game not found")
|
||||||
|
} else {
|
||||||
|
val game = gameOpt.get
|
||||||
|
if (!game.getPlayers.contains(user.id)) {
|
||||||
|
Forbidden("User not part of this game")
|
||||||
|
} else {
|
||||||
|
Ok(
|
||||||
|
Json.obj(
|
||||||
|
"gameId" -> game.id,
|
||||||
|
"state" -> game.logic.getCurrentState.toString,
|
||||||
|
"data" -> mapGameState(game, user)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
private def getUserFromSession(request: RequestHeader): Option[User] = {
|
||||||
|
val session = request.cookies.get("sessionId")
|
||||||
|
if (session.isDefined)
|
||||||
|
return sessionManager.getUserBySession(session.get.value)
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
private def mapGameState(gameLobby: GameLobby, user: User): JsValue = {
|
||||||
|
val userSession = gameLobby.getUserSession(user.id)
|
||||||
|
WebsocketEventMapper.stateToJson(userSession)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import auth.{AuthAction, AuthenticatedRequest}
|
import auth.{AuthAction, AuthenticatedRequest}
|
||||||
|
import dto.subDTO.UserDTO
|
||||||
import logic.user.{SessionManager, UserManager}
|
import logic.user.{SessionManager, UserManager}
|
||||||
|
import model.users.User
|
||||||
import play.api.*
|
import play.api.*
|
||||||
import play.api.libs.json.Json
|
import play.api.libs.json.Json
|
||||||
import play.api.mvc.*
|
import play.api.mvc.*
|
||||||
|
import play.api.mvc.Cookie.SameSite.{Lax, None, Strict}
|
||||||
|
|
||||||
import javax.inject.*
|
import javax.inject.*
|
||||||
|
|
||||||
@@ -21,22 +24,6 @@ class UserController @Inject()(
|
|||||||
val authAction: AuthAction
|
val authAction: AuthAction
|
||||||
) extends BaseController {
|
) extends BaseController {
|
||||||
|
|
||||||
def login(): Action[AnyContent] = {
|
|
||||||
Action { implicit request =>
|
|
||||||
val session = request.cookies.get("sessionId")
|
|
||||||
if (session.isDefined) {
|
|
||||||
val possibleUser = sessionManager.getUserBySession(session.get.value)
|
|
||||||
if (possibleUser.isDefined) {
|
|
||||||
Redirect(routes.MainMenuController.mainMenu())
|
|
||||||
} else {
|
|
||||||
Ok(views.html.main("Login")(views.html.login.login()))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Ok(views.html.main("Login")(views.html.login.login()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def login_Post(): Action[AnyContent] = {
|
def login_Post(): Action[AnyContent] = {
|
||||||
Action { implicit request =>
|
Action { implicit request =>
|
||||||
val jsonBody = request.body.asJson
|
val jsonBody = request.body.asJson
|
||||||
@@ -51,12 +38,17 @@ class UserController @Inject()(
|
|||||||
val possibleUser = userManager.authenticate(username.get, password.get)
|
val possibleUser = userManager.authenticate(username.get, password.get)
|
||||||
if (possibleUser.isDefined) {
|
if (possibleUser.isDefined) {
|
||||||
Ok(Json.obj(
|
Ok(Json.obj(
|
||||||
"status" -> "success",
|
"user" -> Json.obj(
|
||||||
"redirectUrl" -> routes.MainMenuController.mainMenu().url,
|
"id" -> possibleUser.get.id,
|
||||||
"content" -> views.html.mainmenu.creategame(possibleUser).toString
|
"username" -> possibleUser.get.name
|
||||||
)).withCookies(
|
)
|
||||||
Cookie("sessionId", sessionManager.createSession(possibleUser.get))
|
)).withCookies(Cookie(
|
||||||
)
|
name = "accessToken",
|
||||||
|
value = sessionManager.createSession(possibleUser.get),
|
||||||
|
httpOnly = true,
|
||||||
|
secure = false,
|
||||||
|
sameSite = Some(Lax)
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Unauthorized("Invalid username or password")
|
Unauthorized("Invalid username or password")
|
||||||
}
|
}
|
||||||
@@ -65,14 +57,21 @@ class UserController @Inject()(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getUserInfo(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
|
||||||
|
val user: User = request.user
|
||||||
|
Ok(Json.obj(
|
||||||
|
"id" -> user.id,
|
||||||
|
"username" -> user.name
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
// Pass the request-handling function directly to authAction (no nested Action)
|
def logoutPost(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
|
||||||
def logout(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
|
val sessionCookie = request.cookies.get("accessToken")
|
||||||
val sessionCookie = request.cookies.get("sessionId")
|
|
||||||
if (sessionCookie.isDefined) {
|
if (sessionCookie.isDefined) {
|
||||||
sessionManager.invalidateSession(sessionCookie.get.value)
|
sessionManager.invalidateSession(sessionCookie.get.value)
|
||||||
}
|
}
|
||||||
Redirect(routes.UserController.login()).discardingCookies(DiscardingCookie("sessionId"))
|
NoContent.discardingCookies(DiscardingCookie("accessToken"))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
35
knockoutwhistweb/app/dto/GameInfoDTO.scala
Normal file
35
knockoutwhistweb/app/dto/GameInfoDTO.scala
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import dto.subDTO.*
|
||||||
|
import logic.game.GameLobby
|
||||||
|
import model.users.User
|
||||||
|
|
||||||
|
import scala.util.Try
|
||||||
|
|
||||||
|
case class GameInfoDTO(
|
||||||
|
gameId: String,
|
||||||
|
self: Option[PlayerDTO],
|
||||||
|
hand: Option[HandDTO],
|
||||||
|
playerQueue: PlayerQueueDTO,
|
||||||
|
currentTrick: Option[TrickDTO],
|
||||||
|
currentRound: Option[RoundDTO]
|
||||||
|
)
|
||||||
|
|
||||||
|
object GameInfoDTO {
|
||||||
|
|
||||||
|
def apply(lobby: GameLobby, user: User): GameInfoDTO = {
|
||||||
|
val selfPlayer = Try {
|
||||||
|
Some(lobby.getPlayerByUser(user))
|
||||||
|
}.getOrElse(None)
|
||||||
|
|
||||||
|
GameInfoDTO(
|
||||||
|
gameId = lobby.id,
|
||||||
|
self = selfPlayer.map(PlayerDTO(_)),
|
||||||
|
hand = selfPlayer.flatMap(_.currentHand()).map(HandDTO(_)),
|
||||||
|
playerQueue = PlayerQueueDTO(lobby.logic),
|
||||||
|
currentTrick = lobby.logic.getCurrentTrick.map(TrickDTO(_)),
|
||||||
|
currentRound = lobby.logic.getCurrentRound.map(r => RoundDTO(r, lobby.logic.getCurrentMatch))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
knockoutwhistweb/app/dto/LobbyInfoDTO.scala
Normal file
22
knockoutwhistweb/app/dto/LobbyInfoDTO.scala
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import dto.subDTO.UserDTO
|
||||||
|
import logic.game.GameLobby
|
||||||
|
import model.users.User
|
||||||
|
|
||||||
|
case class LobbyInfoDTO(gameId: String, users: List[UserDTO], self: UserDTO, maxPlayers: Int)
|
||||||
|
|
||||||
|
object LobbyInfoDTO {
|
||||||
|
|
||||||
|
def apply(lobby: GameLobby, user: User): LobbyInfoDTO = {
|
||||||
|
val session = lobby.getUserSession(user.id)
|
||||||
|
|
||||||
|
LobbyInfoDTO(
|
||||||
|
gameId = lobby.id,
|
||||||
|
users = lobby.getPlayers.values.map(user => UserDTO(user)).toList,
|
||||||
|
self = UserDTO(session),
|
||||||
|
maxPlayers = lobby.maxPlayers,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
27
knockoutwhistweb/app/dto/TieInfoDTO.scala
Normal file
27
knockoutwhistweb/app/dto/TieInfoDTO.scala
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import dto.subDTO.PlayerDTO
|
||||||
|
import logic.game.GameLobby
|
||||||
|
import model.users.User
|
||||||
|
|
||||||
|
import scala.util.Try
|
||||||
|
|
||||||
|
case class TieInfoDTO(gameId: String, currentPlayer: Option[PlayerDTO], self: Option[PlayerDTO], tiedPlayers: Seq[PlayerDTO], highestAmount: Int)
|
||||||
|
|
||||||
|
object TieInfoDTO {
|
||||||
|
|
||||||
|
def apply(lobby: GameLobby, user: User): TieInfoDTO = {
|
||||||
|
val selfPlayer = Try {
|
||||||
|
Some(lobby.getPlayerByUser(user))
|
||||||
|
}.getOrElse(None)
|
||||||
|
|
||||||
|
TieInfoDTO(
|
||||||
|
gameId = lobby.id,
|
||||||
|
currentPlayer = lobby.logic.playerTieLogic.currentTiePlayer().map(PlayerDTO.apply),
|
||||||
|
self = selfPlayer.map(PlayerDTO.apply),
|
||||||
|
tiedPlayers = lobby.logic.playerTieLogic.getTiedPlayers.map(PlayerDTO.apply),
|
||||||
|
highestAmount = lobby.logic.playerTieLogic.highestAllowedNumber()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
31
knockoutwhistweb/app/dto/TrumpInfoDTO.scala
Normal file
31
knockoutwhistweb/app/dto/TrumpInfoDTO.scala
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import dto.subDTO.{HandDTO, PlayerDTO}
|
||||||
|
import logic.game.GameLobby
|
||||||
|
import model.users.User
|
||||||
|
|
||||||
|
import scala.util.Try
|
||||||
|
|
||||||
|
case class TrumpInfoDTO(
|
||||||
|
gameId: String,
|
||||||
|
chooser: Option[PlayerDTO],
|
||||||
|
self: Option[PlayerDTO],
|
||||||
|
selfHand: Option[HandDTO],
|
||||||
|
)
|
||||||
|
|
||||||
|
object TrumpInfoDTO {
|
||||||
|
|
||||||
|
def apply(lobby: GameLobby, user: User): TrumpInfoDTO = {
|
||||||
|
val selfPlayer = Try {
|
||||||
|
Some(lobby.getPlayerByUser(user))
|
||||||
|
}.getOrElse(None)
|
||||||
|
|
||||||
|
TrumpInfoDTO(
|
||||||
|
gameId = lobby.id,
|
||||||
|
chooser = lobby.logic.getTrumpPlayer.map(PlayerDTO(_)),
|
||||||
|
self = selfPlayer.map(PlayerDTO(_)),
|
||||||
|
selfHand = selfPlayer.flatMap(_.currentHand()).map(HandDTO(_))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
34
knockoutwhistweb/app/dto/WonInfoDTO.scala
Normal file
34
knockoutwhistweb/app/dto/WonInfoDTO.scala
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import dto.subDTO.PodiumPlayerDTO
|
||||||
|
import logic.game.GameLobby
|
||||||
|
import model.users.User
|
||||||
|
|
||||||
|
case class WonInfoDTO(
|
||||||
|
gameId: String,
|
||||||
|
winner: Option[PodiumPlayerDTO],
|
||||||
|
allPlayers: Seq[PodiumPlayerDTO]
|
||||||
|
)
|
||||||
|
|
||||||
|
object WonInfoDTO {
|
||||||
|
|
||||||
|
def apply(lobby: GameLobby, user: User): WonInfoDTO = {
|
||||||
|
val matchImpl = lobby.logic.getCurrentMatch
|
||||||
|
if (matchImpl.isEmpty) {
|
||||||
|
throw new IllegalStateException("No current match available in game logic")
|
||||||
|
}
|
||||||
|
val allPlayersDTO: Seq[PodiumPlayerDTO] = matchImpl.get.totalplayers.map { player =>
|
||||||
|
PodiumPlayerDTO(lobby.logic, player)
|
||||||
|
}
|
||||||
|
|
||||||
|
val selfPlayerDTO = lobby.getPlayerByUser(user)
|
||||||
|
val winnerDTO = lobby.logic.getWinner
|
||||||
|
|
||||||
|
WonInfoDTO(
|
||||||
|
gameId = lobby.id,
|
||||||
|
winner = winnerDTO.map(player => PodiumPlayerDTO(lobby.logic, player)),
|
||||||
|
allPlayers = allPlayersDTO
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
31
knockoutwhistweb/app/dto/subDTO/CardDTO.scala
Normal file
31
knockoutwhistweb/app/dto/subDTO/CardDTO.scala
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package dto.subDTO
|
||||||
|
|
||||||
|
import de.knockoutwhist.cards.Card
|
||||||
|
import util.WebUIUtils
|
||||||
|
|
||||||
|
case class CardDTO(identifier: String, path: String, idx: Option[Int]) {
|
||||||
|
|
||||||
|
def toCard: Card = {
|
||||||
|
WebUIUtils.stringToCard(identifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
object CardDTO {
|
||||||
|
|
||||||
|
def apply(card: Card, index: Int): CardDTO = {
|
||||||
|
CardDTO(
|
||||||
|
identifier = WebUIUtils.cardtoString(card),
|
||||||
|
path = WebUIUtils.cardToPath(card),
|
||||||
|
idx = Some(index)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
def apply(card: Card): CardDTO = {
|
||||||
|
CardDTO(
|
||||||
|
identifier = WebUIUtils.cardtoString(card),
|
||||||
|
path = WebUIUtils.cardToPath(card),
|
||||||
|
idx = None
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
15
knockoutwhistweb/app/dto/subDTO/HandDTO.scala
Normal file
15
knockoutwhistweb/app/dto/subDTO/HandDTO.scala
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package dto.subDTO
|
||||||
|
|
||||||
|
import de.knockoutwhist.cards.Hand
|
||||||
|
|
||||||
|
case class HandDTO(card: List[CardDTO])
|
||||||
|
|
||||||
|
object HandDTO {
|
||||||
|
|
||||||
|
def apply(hand: Hand): HandDTO = {
|
||||||
|
HandDTO(
|
||||||
|
card = hand.cards.zipWithIndex.map { case (card, idx) => CardDTO(card, idx) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
17
knockoutwhistweb/app/dto/subDTO/PlayerDTO.scala
Normal file
17
knockoutwhistweb/app/dto/subDTO/PlayerDTO.scala
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package dto.subDTO
|
||||||
|
|
||||||
|
import de.knockoutwhist.player.AbstractPlayer
|
||||||
|
|
||||||
|
case class PlayerDTO(id: String, name: String, dogLife: Boolean)
|
||||||
|
|
||||||
|
object PlayerDTO {
|
||||||
|
|
||||||
|
def apply(player: AbstractPlayer): PlayerDTO = {
|
||||||
|
PlayerDTO(
|
||||||
|
id = player.id.toString,
|
||||||
|
name = player.name,
|
||||||
|
dogLife = player.isInDogLife
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
19
knockoutwhistweb/app/dto/subDTO/PlayerQueueDTO.scala
Normal file
19
knockoutwhistweb/app/dto/subDTO/PlayerQueueDTO.scala
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package dto.subDTO
|
||||||
|
|
||||||
|
import de.knockoutwhist.control.GameLogic
|
||||||
|
|
||||||
|
case class PlayerQueueDTO(currentPlayer: Option[PlayerDTO], queue: Seq[PlayerDTO])
|
||||||
|
|
||||||
|
object PlayerQueueDTO {
|
||||||
|
|
||||||
|
def apply(logic: GameLogic): PlayerQueueDTO = {
|
||||||
|
val currentPlayerDTO = logic.getCurrentPlayer.map(PlayerDTO(_))
|
||||||
|
val queueDTO = logic.getPlayerQueue.map(_.duplicate().flatMap(player => Some(PlayerDTO(player))).toSeq)
|
||||||
|
if (queueDTO.isEmpty) {
|
||||||
|
PlayerQueueDTO(currentPlayerDTO, Seq.empty)
|
||||||
|
} else {
|
||||||
|
PlayerQueueDTO(currentPlayerDTO, queueDTO.get)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
47
knockoutwhistweb/app/dto/subDTO/PodiumPlayerDTO.scala
Normal file
47
knockoutwhistweb/app/dto/subDTO/PodiumPlayerDTO.scala
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package dto.subDTO
|
||||||
|
|
||||||
|
import de.knockoutwhist.control.GameLogic
|
||||||
|
import de.knockoutwhist.player.AbstractPlayer
|
||||||
|
import de.knockoutwhist.rounds.Match
|
||||||
|
|
||||||
|
case class PodiumPlayerDTO(
|
||||||
|
player: PlayerDTO,
|
||||||
|
position: Int,
|
||||||
|
roundsWon: Int,
|
||||||
|
tricksWon: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
object PodiumPlayerDTO {
|
||||||
|
|
||||||
|
def apply(gameLogic: GameLogic, player: AbstractPlayer): PodiumPlayerDTO = {
|
||||||
|
val matchImplOpt = gameLogic.getCurrentMatch
|
||||||
|
if (matchImplOpt.isEmpty) {
|
||||||
|
throw new IllegalStateException("No current match available in game logic")
|
||||||
|
}
|
||||||
|
val matchImpl: Match = matchImplOpt.get
|
||||||
|
var roundsWon = 0
|
||||||
|
var tricksWon = 0
|
||||||
|
for (round <- matchImpl.roundlist) {
|
||||||
|
if (round.winner.contains(player)) {
|
||||||
|
roundsWon += 1
|
||||||
|
}
|
||||||
|
for (trick <- round.tricklist) {
|
||||||
|
if (trick.winner.contains(player)) {
|
||||||
|
tricksWon += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PodiumPlayerDTO(
|
||||||
|
player = PlayerDTO(player),
|
||||||
|
position = if (gameLogic.getWinner.contains(player)) {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
2
|
||||||
|
},
|
||||||
|
roundsWon = roundsWon,
|
||||||
|
tricksWon = tricksWon
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
20
knockoutwhistweb/app/dto/subDTO/RoundDTO.scala
Normal file
20
knockoutwhistweb/app/dto/subDTO/RoundDTO.scala
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package dto.subDTO
|
||||||
|
|
||||||
|
import de.knockoutwhist.cards.Card
|
||||||
|
import de.knockoutwhist.cards.CardValue.Ace
|
||||||
|
import de.knockoutwhist.rounds.{Match, Round}
|
||||||
|
|
||||||
|
case class RoundDTO(trumpSuit: CardDTO, playersIn: Seq[PlayerDTO], firstRound: Boolean, trickList: List[TrickDTO])
|
||||||
|
|
||||||
|
object RoundDTO {
|
||||||
|
|
||||||
|
def apply(round: Round, matchImpl: Option[Match]): RoundDTO = {
|
||||||
|
RoundDTO(
|
||||||
|
trumpSuit = CardDTO(Card(Ace, round.trumpSuit)),
|
||||||
|
playersIn = matchImpl.map(_.playersIn.map(PlayerDTO(_))).getOrElse(Seq.empty),
|
||||||
|
firstRound = round.firstRound,
|
||||||
|
trickList = round.tricklist.map(trick => TrickDTO(trick))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
17
knockoutwhistweb/app/dto/subDTO/TrickDTO.scala
Normal file
17
knockoutwhistweb/app/dto/subDTO/TrickDTO.scala
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package dto.subDTO
|
||||||
|
|
||||||
|
import de.knockoutwhist.rounds.Trick
|
||||||
|
|
||||||
|
case class TrickDTO(cards: Map[String, CardDTO], firstCard: Option[CardDTO], winner: Option[PlayerDTO])
|
||||||
|
|
||||||
|
object TrickDTO {
|
||||||
|
|
||||||
|
def apply(trick: Trick): TrickDTO = {
|
||||||
|
TrickDTO(
|
||||||
|
cards = trick.cards.map { case (card, player) => player.id.toString -> CardDTO(card) },
|
||||||
|
firstCard = trick.firstCard.map(card => CardDTO(card)),
|
||||||
|
winner = trick.winner.map(player => PlayerDTO(player))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
17
knockoutwhistweb/app/dto/subDTO/UserDTO.scala
Normal file
17
knockoutwhistweb/app/dto/subDTO/UserDTO.scala
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package dto.subDTO
|
||||||
|
|
||||||
|
import model.sessions.UserSession
|
||||||
|
|
||||||
|
case class UserDTO(id: String, username: String, host: Boolean = false)
|
||||||
|
|
||||||
|
object UserDTO {
|
||||||
|
|
||||||
|
def apply(user: UserSession): UserDTO = {
|
||||||
|
UserDTO(
|
||||||
|
id = user.id.toString,
|
||||||
|
username = user.name,
|
||||||
|
host = user.host
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ trait SessionManager {
|
|||||||
|
|
||||||
def createSession(user: User): String
|
def createSession(user: User): String
|
||||||
|
|
||||||
|
|
||||||
def getUserBySession(sessionId: String): Option[User]
|
def getUserBySession(sessionId: String): Option[User]
|
||||||
|
|
||||||
def invalidateSession(sessionId: String): Unit
|
def invalidateSession(sessionId: String): Unit
|
||||||
|
|||||||
@@ -9,10 +9,14 @@ import scalafx.scene.image.Image
|
|||||||
|
|
||||||
object WebUIUtils {
|
object WebUIUtils {
|
||||||
def cardtoImage(card: Card): Html = {
|
def cardtoImage(card: Card): Html = {
|
||||||
views.html.render.card.apply(f"images/cards/${cardtoString(card)}.png")(card.toString)
|
views.html.render.card.apply(cardToPath(card))(card.toString)
|
||||||
|
}
|
||||||
|
|
||||||
|
def cardToPath(card: Card): String = {
|
||||||
|
f"images/cards/${cardtoString(card)}.png"
|
||||||
}
|
}
|
||||||
|
|
||||||
def cardtoString(card: Card) = {
|
def cardtoString(card: Card): String = {
|
||||||
val s = card.suit match {
|
val s = card.suit match {
|
||||||
case Spades => "S"
|
case Spades => "S"
|
||||||
case Hearts => "H"
|
case Hearts => "H"
|
||||||
@@ -36,6 +40,31 @@ object WebUIUtils {
|
|||||||
}
|
}
|
||||||
f"$cv$s"
|
f"$cv$s"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def stringToCard(cardStr: String): Card = {
|
||||||
|
val cv = cardStr.charAt(0) match {
|
||||||
|
case 'A' => Ace
|
||||||
|
case 'K' => King
|
||||||
|
case 'Q' => Queen
|
||||||
|
case 'J' => Jack
|
||||||
|
case 'T' => Ten
|
||||||
|
case '9' => Nine
|
||||||
|
case '8' => Eight
|
||||||
|
case '7' => Seven
|
||||||
|
case '6' => Six
|
||||||
|
case '5' => Five
|
||||||
|
case '4' => Four
|
||||||
|
case '3' => Three
|
||||||
|
case '2' => Two
|
||||||
|
}
|
||||||
|
val s = cardStr.charAt(1) match {
|
||||||
|
case 'S' => Spades
|
||||||
|
case 'H' => Hearts
|
||||||
|
case 'C' => Clubs
|
||||||
|
case 'D' => Diamonds
|
||||||
|
}
|
||||||
|
Card(cv, s)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map a Hand to a JsArray of cards
|
* Map a Hand to a JsArray of cards
|
||||||
|
|||||||
@@ -1,25 +1,37 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
|
import de.knockoutwhist.control.GameState
|
||||||
|
import de.knockoutwhist.control.GameState.{FinishedMatch, InGame, Lobby, SelectTrump, TieBreak}
|
||||||
import de.knockoutwhist.utils.events.SimpleEvent
|
import de.knockoutwhist.utils.events.SimpleEvent
|
||||||
|
import dto.subDTO.{CardDTO, HandDTO, PlayerDTO, PlayerQueueDTO, PodiumPlayerDTO, RoundDTO, TrickDTO, UserDTO}
|
||||||
|
import dto.{GameInfoDTO, LobbyInfoDTO, TieInfoDTO, TrumpInfoDTO, WonInfoDTO}
|
||||||
import model.sessions.UserSession
|
import model.sessions.UserSession
|
||||||
import play.api.libs.json.{JsValue, Json}
|
import play.api.libs.json.{JsValue, Json, OFormat}
|
||||||
import tools.jackson.databind.json.JsonMapper
|
import tools.jackson.databind.json.JsonMapper
|
||||||
import tools.jackson.module.scala.ScalaModule
|
import tools.jackson.module.scala.ScalaModule
|
||||||
import util.mapper.*
|
import util.mapper.*
|
||||||
|
|
||||||
object WebsocketEventMapper {
|
object WebsocketEventMapper {
|
||||||
|
|
||||||
private val scalaModule = ScalaModule.builder()
|
implicit val cardFormat: OFormat[CardDTO] = Json.format[CardDTO]
|
||||||
.addAllBuiltinModules()
|
implicit val handFormat: OFormat[HandDTO] = Json.format[HandDTO]
|
||||||
.supportScala3Classes(true)
|
implicit val playerFormat: OFormat[PlayerDTO] = Json.format[PlayerDTO]
|
||||||
.build()
|
implicit val queueFormat: OFormat[PlayerQueueDTO] = Json.format[PlayerQueueDTO]
|
||||||
|
implicit val podiumPlayerFormat: OFormat[PodiumPlayerDTO] = Json.format[PodiumPlayerDTO]
|
||||||
|
implicit val roundFormat: OFormat[RoundDTO] = Json.format[RoundDTO]
|
||||||
|
implicit val trickFormat: OFormat[TrickDTO] = Json.format[TrickDTO]
|
||||||
|
implicit val userFormat: OFormat[UserDTO] = Json.format[UserDTO]
|
||||||
|
|
||||||
private val mapper = JsonMapper.builder().addModule(scalaModule).build()
|
implicit val gameInfoDTOFormat: OFormat[GameInfoDTO] = Json.format[GameInfoDTO]
|
||||||
|
implicit val lobbyFormat: OFormat[LobbyInfoDTO] = Json.format[LobbyInfoDTO]
|
||||||
private var customMappers: Map[String,SimpleEventMapper[SimpleEvent]] = Map()
|
implicit val tieInfoFormat: OFormat[TieInfoDTO] = Json.format[TieInfoDTO]
|
||||||
|
implicit val trumpInfoFormat: OFormat[TrumpInfoDTO] = Json.format[TrumpInfoDTO]
|
||||||
|
implicit val wonInfoDTOFormat: OFormat[WonInfoDTO] = Json.format[WonInfoDTO]
|
||||||
|
|
||||||
|
private var specialMappers: Map[String,SimpleEventMapper[SimpleEvent]] = Map()
|
||||||
|
|
||||||
private def registerCustomMapper[T <: SimpleEvent](mapper: SimpleEventMapper[T]): Unit = {
|
private def registerCustomMapper[T <: SimpleEvent](mapper: SimpleEventMapper[T]): Unit = {
|
||||||
customMappers = customMappers + (mapper.id -> mapper.asInstanceOf[SimpleEventMapper[SimpleEvent]])
|
specialMappers = specialMappers + (mapper.id -> mapper.asInstanceOf[SimpleEventMapper[SimpleEvent]])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register all custom mappers here
|
// Register all custom mappers here
|
||||||
@@ -37,19 +49,28 @@ object WebsocketEventMapper {
|
|||||||
registerCustomMapper(TurnEventMapper)
|
registerCustomMapper(TurnEventMapper)
|
||||||
|
|
||||||
def toJson(obj: SimpleEvent, session: UserSession): JsValue = {
|
def toJson(obj: SimpleEvent, session: UserSession): JsValue = {
|
||||||
val data: Option[JsValue] = if (customMappers.contains(obj.id)) {
|
val data: Option[JsValue] = if (specialMappers.contains(obj.id)) {
|
||||||
Some(customMappers(obj.id).toJson(obj, session))
|
Some(specialMappers(obj.id).toJson(obj, session))
|
||||||
}else {
|
}else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
if (data.isEmpty) {
|
|
||||||
return Json.obj()
|
|
||||||
}
|
|
||||||
Json.obj(
|
Json.obj(
|
||||||
"id" -> ("request-" + java.util.UUID.randomUUID().toString),
|
"id" -> ("request-" + java.util.UUID.randomUUID().toString),
|
||||||
"event" -> obj.id,
|
"event" -> obj.id,
|
||||||
|
"state" -> stateToJson(session),
|
||||||
"data" -> data
|
"data" -> data
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def stateToJson(session: UserSession): JsValue = {
|
||||||
|
session.gameLobby.getLogic.getCurrentState match {
|
||||||
|
case Lobby => Json.toJson(LobbyInfoDTO(session.gameLobby, session.user))
|
||||||
|
case InGame => Json.toJson(GameInfoDTO(session.gameLobby, session.user))
|
||||||
|
case SelectTrump => Json.toJson(TrumpInfoDTO(session.gameLobby, session.user))
|
||||||
|
case TieBreak => Json.toJson(TieInfoDTO(session.gameLobby, session.user))
|
||||||
|
case FinishedMatch => Json.toJson(WonInfoDTO(session.gameLobby, session.user))
|
||||||
|
case _ => Json.obj()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if(player.equals(gamelobby.logic.playerTieLogic.currentTiePlayer())) {
|
@if(gamelobby.logic.playerTieLogic.currentTiePlayer().contains(player)) {
|
||||||
@defining(gamelobby.logic.playerTieLogic.highestAllowedNumber()) { maxNum =>
|
@defining(gamelobby.logic.playerTieLogic.highestAllowedNumber()) { maxNum =>
|
||||||
<div class="alert alert-info" role="alert" aria-live="polite">
|
<div class="alert alert-info" role="alert" aria-live="polite">
|
||||||
Pick a number between 1 and @{
|
Pick a number between 1 and @{
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
<div class="alert alert-warning" role="alert" aria-live="polite">
|
<div class="alert alert-warning" role="alert" aria-live="polite">
|
||||||
<strong>@gamelobby.logic.playerTieLogic.currentTiePlayer()</strong>
|
<strong>@gamelobby.logic.playerTieLogic.currentTiePlayer().get</strong>
|
||||||
is currently picking a number for the cut.
|
is currently picking a number for the cut.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -45,15 +45,9 @@
|
|||||||
<li><a class="dropdown-item disabled" href="#" tabindex="-1" aria-disabled="true">
|
<li><a class="dropdown-item disabled" href="#" tabindex="-1" aria-disabled="true">
|
||||||
Settings</a></li>
|
Settings</a></li>
|
||||||
<li><hr class="dropdown-divider"></li>
|
<li><hr class="dropdown-divider"></li>
|
||||||
<li><a class="dropdown-item" href="@routes.UserController.logout()">Logout</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
} else {
|
|
||||||
<div class="d-flex ms-auto">
|
|
||||||
<a class="btn btn-outline-primary me-2" href="@routes.UserController.login()">Login</a>
|
|
||||||
<a class="btn btn-primary" href="@routes.UserController.login()">Sign Up</a>
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,3 +13,12 @@ auth {
|
|||||||
publicKeyFile = ${?PUBLIC_KEY_FILE}
|
publicKeyFile = ${?PUBLIC_KEY_FILE}
|
||||||
publicKeyPem = ${?PUBLIC_KEY_PEM}
|
publicKeyPem = ${?PUBLIC_KEY_PEM}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
play.filters.enabled += "play.filters.cors.CORSFilter"
|
||||||
|
|
||||||
|
play.filters.cors {
|
||||||
|
allowedOrigins = ["http://localhost:5173"]
|
||||||
|
allowedCredentials = true
|
||||||
|
allowedHttpMethods = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
|
||||||
|
allowedHttpHeaders = ["Accept", "Content-Type", "Origin", "X-Requested-With"]
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,13 +18,16 @@ POST /createGame controllers.MainMenuController.createGame()
|
|||||||
POST /joinGame controllers.MainMenuController.joinGame()
|
POST /joinGame controllers.MainMenuController.joinGame()
|
||||||
|
|
||||||
# User authentication routes
|
# User authentication routes
|
||||||
GET /login controllers.UserController.login()
|
|
||||||
POST /login controllers.UserController.login_Post()
|
POST /login controllers.UserController.login_Post()
|
||||||
|
POST /logout controllers.UserController.logoutPost()
|
||||||
GET /logout controllers.UserController.logout()
|
GET /userInfo controllers.UserController.getUserInfo()
|
||||||
|
|
||||||
# In-game routes
|
# In-game routes
|
||||||
GET /game/:id controllers.IngameController.game(id: String)
|
GET /game/:id controllers.IngameController.game(id: String)
|
||||||
|
|
||||||
# Websocket
|
# Websocket
|
||||||
GET /websocket controllers.WebsocketController.socket()
|
GET /websocket controllers.WebsocketController.socket()
|
||||||
|
|
||||||
|
# Status
|
||||||
|
GET /status controllers.StatusController.requestStatus()
|
||||||
|
GET /status/:gameId controllers.StatusController.game(gameId: String)
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
MAJOR=4
|
MAJOR=4
|
||||||
MINOR=8
|
MINOR=13
|
||||||
PATCH=0
|
PATCH=0
|
||||||
|
|||||||
Reference in New Issue
Block a user