Compare commits

...

10 Commits
4.11.0 ... main

Author SHA1 Message Date
TeamCity
c3d10f31ac ci: bump version to v4.16.0 2025-12-18 08:51:00 +00:00
e4384ee894 feat(ui): FRO-36 PWA (#110)
Added localhost:3000 to CORS for PWA to work

Co-authored-by: LQ63 <lkhermann@web.de>
Reviewed-on: #110
Reviewed-by: Janis <janis-e@gmx.de>
Co-authored-by: lq64 <lq@blackhole.local>
Co-committed-by: lq64 <lq@blackhole.local>
2025-12-18 09:47:25 +01:00
TeamCity
d667a2f68c ci: bump version to v4.15.0 2025-12-14 14:15:11 +00:00
35f608513d feat: Update routing and websocket configuration for game state management (#109)
Reviewed-on: #109
2025-12-14 15:10:43 +01:00
TeamCity
13038b0cb9 ci: bump version to v4.14.0 2025-12-11 06:13:24 +00:00
b17aae5795 feat: FRO-31 Small backend changes (#108)
Force pushing Janis changes

Co-authored-by: Janis <janis.e.20@gmx.de>
Co-authored-by: Janis <janis-e@gmx.de>
Reviewed-on: #108
Co-authored-by: lq64 <lq@blackhole.local>
Co-committed-by: lq64 <lq@blackhole.local>
2025-12-11 07:10:24 +01:00
TeamCity
421f769cb6 ci: bump version to v4.13.0 2025-12-10 14:19:44 +00:00
bd7a055a09 feat(api): FRO-14 Create Game (#107)
Added functionality to create Game so that it creates a game in the Backend

Co-authored-by: LQ63 <lkhermann@web.de>
Reviewed-on: #107
Reviewed-by: Janis <janis-e@gmx.de>
Co-authored-by: lq64 <lq@blackhole.local>
Co-committed-by: lq64 <lq@blackhole.local>
2025-12-10 15:16:53 +01:00
TeamCity
e2a2b56174 ci: bump version to v4.12.0 2025-12-10 13:15:50 +00:00
2a29ca8cdd feat: FRO-20 Create scoreboard component (#106)
Reviewed-on: #106
Co-authored-by: Janis <janis.e.20@gmx.de>
Co-committed-by: Janis <janis.e.20@gmx.de>
2025-12-10 14:12:48 +01:00
14 changed files with 53 additions and 28 deletions

View File

@@ -234,3 +234,28 @@
### Features ### 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)) * 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))
## (2025-12-11)
### Features
* FRO-31 Small backend changes ([#108](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/108)) ([b17aae5](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/b17aae5795b35ce3805db87c9bf741a5a96cd5ac))
## (2025-12-14)
### Features
* Update routing and websocket configuration for game state management ([#109](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/109)) ([35f6085](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/35f608513dd80eece46d49b40ecf31c8e915d307))
## (2025-12-18)
### Features
* **ui:** FRO-36 PWA ([#110](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/110)) ([e4384ee](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/e4384ee8945ac462fe1f3580215117e0a438f71a))

View File

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

View File

@@ -34,7 +34,7 @@ class StatusController @Inject()(
Json.obj( Json.obj(
"status" -> "authenticated", "status" -> "authenticated",
"username" -> user.name, "username" -> user.name,
"inGame" -> "false" "inGame" -> false
) )
) )
} else { } else {
@@ -43,7 +43,7 @@ class StatusController @Inject()(
Json.obj( Json.obj(
"status" -> "authenticated", "status" -> "authenticated",
"username" -> user.name, "username" -> user.name,
"inGame" -> "true", "inGame" -> true,
"gameId" -> game.id "gameId" -> game.id
) )
) )
@@ -80,7 +80,7 @@ class StatusController @Inject()(
}} }}
private def getUserFromSession(request: RequestHeader): Option[User] = { private 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

View File

@@ -21,7 +21,7 @@ class WebsocketController @Inject()(
)(implicit system: ActorSystem, mat: Materializer) extends AbstractController(cc) { )(implicit system: ActorSystem, mat: Materializer) extends AbstractController(cc) {
def socket(): WebSocket = WebSocket.accept[String, String] { request => 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") if (session.isEmpty) throw new Exception("No session cookie found")
val userOpt = sessionManger.getUserBySession(session.get.value) val userOpt = sessionManger.getUserBySession(session.get.value)
if (userOpt.isEmpty) throw new Exception("Invalid session") if (userOpt.isEmpty) throw new Exception("Invalid session")

View File

@@ -28,7 +28,7 @@ object GameInfoDTO {
hand = selfPlayer.flatMap(_.currentHand()).map(HandDTO(_)), hand = selfPlayer.flatMap(_.currentHand()).map(HandDTO(_)),
playerQueue = PlayerQueueDTO(lobby.logic), playerQueue = PlayerQueueDTO(lobby.logic),
currentTrick = lobby.logic.getCurrentTrick.map(TrickDTO(_)), currentTrick = lobby.logic.getCurrentTrick.map(TrickDTO(_)),
currentRound = lobby.logic.getCurrentRound.map(RoundDTO(_)) currentRound = lobby.logic.getCurrentRound.map(r => RoundDTO(r, lobby.logic.getCurrentMatch))
) )
} }

View File

@@ -2,13 +2,13 @@ package dto.subDTO
import de.knockoutwhist.cards.Hand import de.knockoutwhist.cards.Hand
case class HandDTO(card: List[CardDTO]) case class HandDTO(cards: List[CardDTO])
object HandDTO { object HandDTO {
def apply(hand: Hand): HandDTO = { def apply(hand: Hand): HandDTO = {
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

@@ -2,14 +2,16 @@ package dto.subDTO
import de.knockoutwhist.cards.Card import de.knockoutwhist.cards.Card
import de.knockoutwhist.cards.CardValue.Ace import de.knockoutwhist.cards.CardValue.Ace
import de.knockoutwhist.rounds.{Match, Round}
case class RoundDTO(trumpSuit: CardDTO, firstRound: Boolean, trickList: List[TrickDTO]) case class RoundDTO(trumpSuit: CardDTO, playersIn: Seq[PlayerDTO], firstRound: Boolean, trickList: List[TrickDTO])
object RoundDTO { object RoundDTO {
def apply(round: de.knockoutwhist.rounds.Round): RoundDTO = { def apply(round: Round, matchImpl: Option[Match]): RoundDTO = {
RoundDTO( RoundDTO(
trumpSuit = CardDTO(Card(Ace, round.trumpSuit)), trumpSuit = CardDTO(Card(Ace, round.trumpSuit)),
playersIn = matchImpl.map(_.playersIn.map(PlayerDTO(_))).getOrElse(Seq.empty),
firstRound = round.firstRound, firstRound = round.firstRound,
trickList = round.tricklist.map(trick => TrickDTO(trick)) trickList = round.tricklist.map(trick => TrickDTO(trick))
) )

View File

@@ -8,7 +8,7 @@ object TrickDTO {
def apply(trick: Trick): TrickDTO = { def apply(trick: Trick): TrickDTO = {
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)), firstCard = trick.firstCard.map(card => CardDTO(card)),
winner = trick.winner.map(player => PlayerDTO(player)) 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" => case "StartGame" =>
gameLobby.startGame(user) gameLobby.startGame(user)
case "PlayCard" => case "PlayCard" =>
val maybeCardIndex: Option[String] = (data \ "cardindex").asOpt[String] val maybeCardIndex: Option[Int] = (data \ "cardindex").asOpt[Int]
maybeCardIndex match { maybeCardIndex match {
case Some(index) => case Some(index) =>
val session = gameLobby.getUserSession(user.id) val session = gameLobby.getUserSession(user.id)
gameLobby.playCard(session, index.toInt) gameLobby.playCard(session, index)
case None => 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" => case "PickTrumpsuit" =>
val maybeSuitIndex: Option[Int] = (data \ "suitIndex").asOpt[Int] 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" => case "ReturnToLobby" =>
gameLobby.returnToLobby(this) gameLobby.returnToLobby(this)
case "LeaveGame" =>
gameLobby.leaveGame(user.id, false)
case _ =>
println("Unknown event type: " + eventType + " with data: " + data)
} }
} }

View File

@@ -57,7 +57,8 @@ object WebsocketEventMapper {
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), "state" -> session.gameLobby.getLogic.getCurrentState.toString,
"stateData" -> stateToJson(session),
"data" -> data "data" -> data
) )
} }

View File

@@ -17,7 +17,7 @@ auth {
play.filters.enabled += "play.filters.cors.CORSFilter" play.filters.enabled += "play.filters.cors.CORSFilter"
play.filters.cors { play.filters.cors {
allowedOrigins = ["http://localhost:5173"] allowedOrigins = ["http://localhost:5173", "http://localhost:3000"]
allowedCredentials = true allowedCredentials = true
allowedHttpMethods = ["GET", "POST", "PUT", "DELETE", "OPTIONS"] allowedHttpMethods = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
allowedHttpHeaders = ["Accept", "Content-Type", "Origin", "X-Requested-With"] allowedHttpHeaders = ["Accept", "Content-Type", "Origin", "X-Requested-With"]

View File

@@ -1,11 +1,9 @@
// javascript let ws = null;
let ws = null; // will be created by connectWebSocket() const pending = new Map();
const pending = new Map(); // id -> { resolve, reject, timer } const handlers = new Map();
const handlers = new Map(); // eventType -> handler(data) -> (value|Promise)
let timer = null; let timer = null;
// helper to attach message/error/close handlers to a socket
function setupSocketHandlers(socket) { function setupSocketHandlers(socket) {
socket.onmessage = (event) => { socket.onmessage = (event) => {
console.debug("SERVER MESSAGE:", event.data); console.debug("SERVER MESSAGE:", event.data);
@@ -48,7 +46,6 @@ function setupSocketHandlers(socket) {
}; };
if (!handler) { if (!handler) {
// no handler: respond with an error object in data so server can fail it
console.warn("No handler for event:", eventType); console.warn("No handler for event:", eventType);
sendResponse({error: "No handler for event: " + eventType}); sendResponse({error: "No handler for event: " + eventType});
return; return;
@@ -91,7 +88,6 @@ function setupSocketHandlers(socket) {
}; };
} }
// connect/disconnect helpers
function connectWebSocket(url = null) { function connectWebSocket(url = null) {
if (!url) { if (!url) {
const loc = window.location; const loc = window.location;
@@ -100,7 +96,6 @@ function connectWebSocket(url = null) {
} }
if (ws && ws.readyState === WebSocket.OPEN) return Promise.resolve(); if (ws && ws.readyState === WebSocket.OPEN) return Promise.resolve();
if (ws && ws.readyState === WebSocket.CONNECTING) { if (ws && ws.readyState === WebSocket.CONNECTING) {
// already connecting - return a promise that resolves on open
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const prevOnOpen = ws.onopen; const prevOnOpen = ws.onopen;
const prevOnError = ws.onerror; const prevOnError = ws.onerror;
@@ -121,7 +116,6 @@ function connectWebSocket(url = null) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ws.onopen = () => { ws.onopen = () => {
console.log("WebSocket connection established!"); console.log("WebSocket connection established!");
// start heartbeat
timer = setInterval(() => { timer = setInterval(() => {
if (ws && ws.readyState === WebSocket.OPEN) { if (ws && ws.readyState === WebSocket.OPEN) {
sendEventAndWait("ping", {}).then( sendEventAndWait("ping", {}).then(

View File

@@ -1,3 +1,3 @@
MAJOR=4 MAJOR=4
MINOR=11 MINOR=16
PATCH=0 PATCH=0