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