Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3d10f31ac | ||
| e4384ee894 | |||
|
|
d667a2f68c | ||
| 35f608513d | |||
|
|
13038b0cb9 | ||
| b17aae5795 | |||
|
|
421f769cb6 | ||
| bd7a055a09 | |||
|
|
e2a2b56174 | ||
| 2a29ca8cdd | |||
|
|
266cbe7509 | ||
| e8b31b1748 | |||
|
|
8812b0fad4 | ||
| dd5e8e65e5 | |||
|
|
bf6ffeadb0 | ||
| fa3d21e303 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -134,6 +134,7 @@ target
|
||||
/.project
|
||||
/.settings
|
||||
/RUNNING_PID
|
||||
/knockoutwhistwebfrontend/
|
||||
/knockoutwhist/
|
||||
/knockoutwhistweb/.g8/
|
||||
/knockoutwhistweb/.bsp/
|
||||
|
||||
40
CHANGELOG.md
40
CHANGELOG.md
@@ -219,3 +219,43 @@
|
||||
### 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))
|
||||
## (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))
|
||||
|
||||
Submodule knockoutwhistfrontend updated: 5d080bba47...30798ce723
@@ -23,12 +23,12 @@ class AuthAction @Inject()(val sessionManager: SessionManager, val parser: BodyP
|
||||
case Some(user) =>
|
||||
block(new AuthenticatedRequest(user, request))
|
||||
case None =>
|
||||
Future.successful(Results.Redirect(routes.UserController.login()))
|
||||
Future.successful(Results.Unauthorized)
|
||||
}
|
||||
}
|
||||
|
||||
protected def getUserFromSession(request: RequestHeader): Option[User] = {
|
||||
val session = request.cookies.get("sessionId")
|
||||
val session = request.cookies.get("accessToken")
|
||||
if (session.isDefined)
|
||||
return sessionManager.getUserBySession(session.get.value)
|
||||
None
|
||||
|
||||
@@ -44,8 +44,7 @@ class MainMenuController @Inject()(
|
||||
)
|
||||
Ok(Json.obj(
|
||||
"status" -> "success",
|
||||
"redirectUrl" -> routes.IngameController.game(gameLobby.id).url,
|
||||
"content" -> IngameController.returnInnerHTML(gameLobby, gameLobby.logic.getCurrentState, request.user).toString
|
||||
"gameId" -> gameLobby.id,
|
||||
))
|
||||
} else {
|
||||
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("accessToken")
|
||||
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
|
||||
|
||||
import auth.{AuthAction, AuthenticatedRequest}
|
||||
import dto.subDTO.UserDTO
|
||||
import logic.user.{SessionManager, UserManager}
|
||||
import model.users.User
|
||||
import play.api.*
|
||||
import play.api.libs.json.Json
|
||||
import play.api.mvc.*
|
||||
import play.api.mvc.Cookie.SameSite.{Lax, None, Strict}
|
||||
|
||||
import javax.inject.*
|
||||
|
||||
@@ -21,22 +24,6 @@ class UserController @Inject()(
|
||||
val authAction: AuthAction
|
||||
) 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] = {
|
||||
Action { implicit request =>
|
||||
val jsonBody = request.body.asJson
|
||||
@@ -51,12 +38,17 @@ class UserController @Inject()(
|
||||
val possibleUser = userManager.authenticate(username.get, password.get)
|
||||
if (possibleUser.isDefined) {
|
||||
Ok(Json.obj(
|
||||
"status" -> "success",
|
||||
"redirectUrl" -> routes.MainMenuController.mainMenu().url,
|
||||
"content" -> views.html.mainmenu.creategame(possibleUser).toString
|
||||
)).withCookies(
|
||||
Cookie("sessionId", sessionManager.createSession(possibleUser.get))
|
||||
)
|
||||
"user" -> Json.obj(
|
||||
"id" -> possibleUser.get.id,
|
||||
"username" -> possibleUser.get.name
|
||||
)
|
||||
)).withCookies(Cookie(
|
||||
name = "accessToken",
|
||||
value = sessionManager.createSession(possibleUser.get),
|
||||
httpOnly = true,
|
||||
secure = false,
|
||||
sameSite = Some(Lax)
|
||||
))
|
||||
} else {
|
||||
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 logout(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
|
||||
val sessionCookie = request.cookies.get("sessionId")
|
||||
def logoutPost(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
|
||||
val sessionCookie = request.cookies.get("accessToken")
|
||||
if (sessionCookie.isDefined) {
|
||||
sessionManager.invalidateSession(sessionCookie.get.value)
|
||||
}
|
||||
Redirect(routes.UserController.login()).discardingCookies(DiscardingCookie("sessionId"))
|
||||
NoContent.discardingCookies(DiscardingCookie("accessToken"))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
@@ -28,7 +28,7 @@ object GameInfoDTO {
|
||||
hand = selfPlayer.flatMap(_.currentHand()).map(HandDTO(_)),
|
||||
playerQueue = PlayerQueueDTO(lobby.logic),
|
||||
currentTrick = lobby.logic.getCurrentTrick.map(TrickDTO(_)),
|
||||
currentRound = lobby.logic.getCurrentRound.map(RoundDTO(_))
|
||||
currentRound = lobby.logic.getCurrentRound.map(r => RoundDTO(r, lobby.logic.getCurrentMatch))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import dto.subDTO.UserDTO
|
||||
import logic.game.GameLobby
|
||||
import model.users.User
|
||||
|
||||
case class LobbyInfoDTO(users: List[UserDTO], self: UserDTO, maxPlayers: Int)
|
||||
case class LobbyInfoDTO(gameId: String, users: List[UserDTO], self: UserDTO, maxPlayers: Int)
|
||||
|
||||
object LobbyInfoDTO {
|
||||
|
||||
@@ -12,6 +12,7 @@ object 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,
|
||||
|
||||
@@ -6,7 +6,7 @@ import model.users.User
|
||||
|
||||
import scala.util.Try
|
||||
|
||||
case class TieInfoDTO(currentPlayer: Option[PlayerDTO], self: Option[PlayerDTO], tiedPlayers: Seq[PlayerDTO], highestAmount: Int)
|
||||
case class TieInfoDTO(gameId: String, currentPlayer: Option[PlayerDTO], self: Option[PlayerDTO], tiedPlayers: Seq[PlayerDTO], highestAmount: Int)
|
||||
|
||||
object TieInfoDTO {
|
||||
|
||||
@@ -16,6 +16,7 @@ object TieInfoDTO {
|
||||
}.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),
|
||||
|
||||
@@ -7,6 +7,7 @@ import model.users.User
|
||||
import scala.util.Try
|
||||
|
||||
case class TrumpInfoDTO(
|
||||
gameId: String,
|
||||
chooser: Option[PlayerDTO],
|
||||
self: Option[PlayerDTO],
|
||||
selfHand: Option[HandDTO],
|
||||
@@ -20,6 +21,7 @@ object TrumpInfoDTO {
|
||||
}.getOrElse(None)
|
||||
|
||||
TrumpInfoDTO(
|
||||
gameId = lobby.id,
|
||||
chooser = lobby.logic.getTrumpPlayer.map(PlayerDTO(_)),
|
||||
self = selfPlayer.map(PlayerDTO(_)),
|
||||
selfHand = selfPlayer.flatMap(_.currentHand()).map(HandDTO(_))
|
||||
|
||||
@@ -5,6 +5,7 @@ import logic.game.GameLobby
|
||||
import model.users.User
|
||||
|
||||
case class WonInfoDTO(
|
||||
gameId: String,
|
||||
winner: Option[PodiumPlayerDTO],
|
||||
allPlayers: Seq[PodiumPlayerDTO]
|
||||
)
|
||||
@@ -24,6 +25,7 @@ object WonInfoDTO {
|
||||
val winnerDTO = lobby.logic.getWinner
|
||||
|
||||
WonInfoDTO(
|
||||
gameId = lobby.id,
|
||||
winner = winnerDTO.map(player => PodiumPlayerDTO(lobby.logic, player)),
|
||||
allPlayers = allPlayersDTO
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ package dto.subDTO
|
||||
import de.knockoutwhist.cards.Card
|
||||
import util.WebUIUtils
|
||||
|
||||
case class CardDTO(identifier: String, path: String, idx: Int) {
|
||||
case class CardDTO(identifier: String, path: String, idx: Option[Int]) {
|
||||
|
||||
def toCard: Card = {
|
||||
WebUIUtils.stringToCard(identifier)
|
||||
@@ -13,11 +13,19 @@ case class CardDTO(identifier: String, path: String, idx: Int) {
|
||||
|
||||
object CardDTO {
|
||||
|
||||
def apply(card: Card, index: Int = 0): CardDTO = {
|
||||
def apply(card: Card, index: Int): CardDTO = {
|
||||
CardDTO(
|
||||
identifier = WebUIUtils.cardtoString(card),
|
||||
path = WebUIUtils.cardToPath(card),
|
||||
idx = index
|
||||
idx = Some(index)
|
||||
)
|
||||
}
|
||||
|
||||
def apply(card: Card): CardDTO = {
|
||||
CardDTO(
|
||||
identifier = WebUIUtils.cardtoString(card),
|
||||
path = WebUIUtils.cardToPath(card),
|
||||
idx = None
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,16 +2,18 @@ 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, firstRound: Boolean, tricklist: List[TrickDTO])
|
||||
case class RoundDTO(trumpSuit: CardDTO, playersIn: Seq[PlayerDTO], firstRound: Boolean, trickList: List[TrickDTO])
|
||||
|
||||
object RoundDTO {
|
||||
|
||||
def apply(round: de.knockoutwhist.rounds.Round): 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))
|
||||
trickList = round.tricklist.map(trick => TrickDTO(trick))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@ package dto.subDTO
|
||||
|
||||
import de.knockoutwhist.rounds.Trick
|
||||
|
||||
case class TrickDTO(cards: Map[PlayerDTO, CardDTO], firstCard: Option[CardDTO], winner: Option[PlayerDTO])
|
||||
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) => PlayerDTO(player) -> 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))
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ trait SessionManager {
|
||||
|
||||
def createSession(user: User): String
|
||||
|
||||
|
||||
def getUserBySession(sessionId: String): Option[User]
|
||||
|
||||
def invalidateSession(sessionId: String): Unit
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,12 +57,13 @@ object WebsocketEventMapper {
|
||||
Json.obj(
|
||||
"id" -> ("request-" + java.util.UUID.randomUUID().toString),
|
||||
"event" -> obj.id,
|
||||
"state" -> toJson(session),
|
||||
"state" -> session.gameLobby.getLogic.getCurrentState.toString,
|
||||
"stateData" -> stateToJson(session),
|
||||
"data" -> data
|
||||
)
|
||||
}
|
||||
|
||||
def toJson(session: UserSession): JsValue = {
|
||||
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))
|
||||
|
||||
@@ -45,15 +45,9 @@
|
||||
<li><a class="dropdown-item disabled" href="#" tabindex="-1" aria-disabled="true">
|
||||
Settings</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item" href="@routes.UserController.logout()">Logout</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</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>
|
||||
|
||||
@@ -13,3 +13,12 @@ auth {
|
||||
publicKeyFile = ${?PUBLIC_KEY_FILE}
|
||||
publicKeyPem = ${?PUBLIC_KEY_PEM}
|
||||
}
|
||||
|
||||
play.filters.enabled += "play.filters.cors.CORSFilter"
|
||||
|
||||
play.filters.cors {
|
||||
allowedOrigins = ["http://localhost:5173", "http://localhost:3000"]
|
||||
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()
|
||||
|
||||
# User authentication routes
|
||||
GET /login controllers.UserController.login()
|
||||
POST /login controllers.UserController.login_Post()
|
||||
|
||||
GET /logout controllers.UserController.logout()
|
||||
POST /logout controllers.UserController.logoutPost()
|
||||
GET /userInfo controllers.UserController.getUserInfo()
|
||||
|
||||
# In-game routes
|
||||
GET /game/:id controllers.IngameController.game(id: String)
|
||||
|
||||
# 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,11 +1,9 @@
|
||||
// javascript
|
||||
let ws = null; // will be created by connectWebSocket()
|
||||
const pending = new Map(); // id -> { resolve, reject, timer }
|
||||
const handlers = new Map(); // eventType -> handler(data) -> (value|Promise)
|
||||
let ws = null;
|
||||
const pending = new Map();
|
||||
const handlers = new Map();
|
||||
|
||||
let timer = null;
|
||||
|
||||
// helper to attach message/error/close handlers to a socket
|
||||
function setupSocketHandlers(socket) {
|
||||
socket.onmessage = (event) => {
|
||||
console.debug("SERVER MESSAGE:", event.data);
|
||||
@@ -48,7 +46,6 @@ function setupSocketHandlers(socket) {
|
||||
};
|
||||
|
||||
if (!handler) {
|
||||
// no handler: respond with an error object in data so server can fail it
|
||||
console.warn("No handler for event:", eventType);
|
||||
sendResponse({error: "No handler for event: " + eventType});
|
||||
return;
|
||||
@@ -91,7 +88,6 @@ function setupSocketHandlers(socket) {
|
||||
};
|
||||
}
|
||||
|
||||
// connect/disconnect helpers
|
||||
function connectWebSocket(url = null) {
|
||||
if (!url) {
|
||||
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.CONNECTING) {
|
||||
// already connecting - return a promise that resolves on open
|
||||
return new Promise((resolve, reject) => {
|
||||
const prevOnOpen = ws.onopen;
|
||||
const prevOnError = ws.onerror;
|
||||
@@ -121,7 +116,6 @@ function connectWebSocket(url = null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
ws.onopen = () => {
|
||||
console.log("WebSocket connection established!");
|
||||
// start heartbeat
|
||||
timer = setInterval(() => {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
sendEventAndWait("ping", {}).then(
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
MAJOR=4
|
||||
MINOR=9
|
||||
MINOR=16
|
||||
PATCH=0
|
||||
|
||||
Reference in New Issue
Block a user