feat: Update Dockerfile for multi-platform support and add nginx configuration

This commit is contained in:
2026-01-06 16:38:33 +01:00
parent 06d150b8c5
commit b2527ed041
7 changed files with 65 additions and 5 deletions

View File

@@ -0,0 +1,45 @@
package logic
import de.knockoutwhist.data.Pod
import de.knockoutwhist.data.redis.RedisManager
import org.apache.pekko.actor.ActorSystem
import org.redisson.config.Config
import play.api.inject.ApplicationLifecycle
import java.util.UUID
import javax.inject.*
import scala.concurrent.ExecutionContext
import scala.jdk.CollectionConverters.*
@Singleton
class Gateway @Inject()(
lifecycle: ApplicationLifecycle,
actorSystem: ActorSystem
)(implicit ec: ExecutionContext) {
val redis: RedisManager = {
val config: Config = Config()
config.useSingleServer.setAddress("valkey://" + sys.env.getOrElse("VALKEY_HOST", "localhost") + ":" + sys.env.getOrElse("VALKEY_PORT", "6379"))
RedisManager(config)
}
redis.continuousSyncPod(() => {
createPod()
})
def syncPod(): Unit = {
redis.syncPod(createPod())
}
private def createPod(): Pod = {
Pod(
UUID.randomUUID().toString,
PodManager.podName,
PodManager.podIp,
9000,
PodManager.getAllGameIds().asJava,
PodManager.allBoundUsers().asJava
)
}
}

View File

@@ -21,6 +21,8 @@ object PodManager {
private val userSession: mutable.Map[User, String] = mutable.Map()
private val injector: Injector = Guice.createInjector(KnockOutWebConfigurationModule())
private[logic] var redis: Option[Gateway] = None
def createGame(
host: User,
name: String,
@@ -35,7 +37,8 @@ object PodManager {
host = host
)
sessions += (gameLobby.id -> gameLobby)
userSession += (host -> gameLobby.id)
registerUserToGame(host, gameLobby.id)
redis.foreach(gateway => gateway.syncPod())
gameLobby
}
@@ -46,6 +49,7 @@ object PodManager {
def registerUserToGame(user: User, gameId: String): Boolean = {
if (sessions.contains(gameId)) {
userSession += (user -> gameId)
redis.foreach(gateway => gateway.syncPod())
true
} else {
false
@@ -54,6 +58,7 @@ object PodManager {
def unregisterUserFromGame(user: User): Unit = {
userSession.remove(user)
redis.foreach(gateway => gateway.redis.invalidateUser(user.id.toString))
}
def identifyGameOfUser(user: User): Option[GameLobby] = {
@@ -65,9 +70,12 @@ object PodManager {
private[logic] def removeGame(gameId: String): Unit = {
sessions.remove(gameId)
redis.foreach(gateway => gateway.redis.invalidateGame(gameId))
// Also remove all user sessions associated with this game
userSession.filterInPlace((_, v) => v != gameId)
}
private[logic] def getAllGameIds(): List[String] = sessions.keys.toList
private[logic] def allBoundUsers(): List[String] = userSession.keys.map(_.id.toString).toList
}

View File

@@ -106,6 +106,9 @@ class GameLobby private(
}
if (sessionOpt.get.host) {
logic.invoke(SessionClosed())
for (session <- users.values) {
PodManager.unregisterUserFromGame(session.user)
}
users.clear()
PodManager.removeGame(id)
return

View File

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