fix(ui): Websocket

Fixed startGame to be correctly implemented
This commit is contained in:
LQ63
2025-11-26 09:52:16 +01:00
committed by Janis
parent e0f16a224d
commit 6402df43b1
5 changed files with 6 additions and 31 deletions

View File

@@ -39,7 +39,7 @@ class UserSession(val user: User, val host: Boolean, val gameLobby: GameLobby) e
canInteract = None
}
def handleWebResponse(eventType: String, data: JsObject): Unit = {
def handleWebResponse(eventType: String, data: JsObject, user: User, gameLobby: GameLobby): Unit = {
lock.lock()
Try {
eventType match {
@@ -48,19 +48,7 @@ class UserSession(val user: User, val host: Boolean, val gameLobby: GameLobby) e
()
case "Start Game" =>
println("INSIDE HANDLE WEB RESPONSE" + data)
val gameId: String = (data \ "gameId").get.toString
val cleanGameId: String = gameId.replaceAll("^[\"']|[\"']$", "")
val user: JsObject = (data \ "user").asOpt[JsObject].get
val gameLobby: GameLobby = PodManager.getGame(cleanGameId).get
val realUser: JsResult[User] = user.validate[User]
val uu: User = realUser match {
case JsSuccess(extractedUser, _) =>
extractedUser
case e: JsError =>
println("FAILED" + JsError.toJson(e).toString())
throw new Exception("Failed to deserialize User object: " + JsError.toJson(e).toString())
}
gameLobby.startGame(uu)
gameLobby.startGame(user)
}
}
lock.unlock()

View File

@@ -74,7 +74,7 @@ class UserWebsocketActor(
val event = eventOpt.get
val data = (json \ "data").asOpt[JsObject].getOrElse(Json.obj())
val result = Try {
session.handleWebResponse(event, data)
session.handleWebResponse(event, data, session.user, session.gameLobby)
}
if (result.isSuccess) {
transmitJsonToClient(Json.obj(

View File

@@ -18,7 +18,4 @@ case class User(
private def withPasswordHash(newPasswordHash: String): User = {
this.copy(passwordHash = newPasswordHash)
}
}
object User {
implicit val userFormat: Format[User] = Json.format[User]
}

View File

@@ -5,18 +5,8 @@ function handlePlayCard(card, dog) {
function handleSkipDogLife(button) {
// TODO needs implementation
}
function startGame(gameId, userId, username, userpasswordhash, userinternalid) {
const userpayload = {
internalId: userinternalid,
id: userId,
name: username,
passwordHash: userpasswordhash
}
const payload = {
gameId: gameId,
user: userpayload
};
sendEvent("Start Game", payload)
function startGame() {
sendEvent("Start Game")
}
function handleKickPlayer(playerId) {
// TODO needs implementation