feat(ui): Websocket
Started implementing functionality to Websocket.
This commit is contained in:
@@ -2,9 +2,11 @@ package model.sessions
|
||||
|
||||
import de.knockoutwhist.events.player.{RequestCardEvent, RequestTieChoiceEvent, RequestTrumpSuitEvent}
|
||||
import de.knockoutwhist.utils.events.SimpleEvent
|
||||
import logic.PodManager
|
||||
import logic.game.GameLobby
|
||||
import model.users.User
|
||||
import play.api.libs.json.JsObject
|
||||
import play.api.libs.json.Format.GenericFormat
|
||||
import play.api.libs.json.{JsError, JsObject, JsResult, JsSuccess, JsValue}
|
||||
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
@@ -26,7 +28,7 @@ class UserSession(val user: User, val host: Boolean, val gameLobby: GameLobby) e
|
||||
else canInteract = Some(InteractionType.Card)
|
||||
case _ =>
|
||||
}
|
||||
websocketActor.foreach(_.transmitEventToClient(event))
|
||||
websocketActor.foreach(_.transmitEventToClient(event, gameLobby))
|
||||
}
|
||||
|
||||
override def id: UUID = user.id
|
||||
@@ -44,6 +46,21 @@ class UserSession(val user: User, val host: Boolean, val gameLobby: GameLobby) e
|
||||
case "Ping" =>
|
||||
// No action needed for Ping
|
||||
()
|
||||
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)
|
||||
}
|
||||
}
|
||||
lock.unlock()
|
||||
|
||||
Reference in New Issue
Block a user