Create test for complete game

create notifications for reply the players
implement notifications on GameEventPlayerNotificationListener
add priority to the eventbus.subscribe()
improve JWT creation
update libs koin + ktor
remove output of GameCommandStream
improve logs
create a function disableShuffleDeck to disable the shuffle of the deck (for tests)
This commit is contained in:
2025-03-08 01:07:45 +01:00
parent 99f0760d3c
commit 51d857513c
55 changed files with 659 additions and 235 deletions

View File

@@ -1,6 +1,5 @@
package eventDemo.configuration
import eventDemo.app.eventListener.GameEventReactionListener
import io.ktor.server.application.Application
import org.koin.ktor.ext.get
@@ -17,6 +16,5 @@ fun Application.configure() {
configureHttpRouting()
declareHttpGameRoute()
GameEventReactionListener(get(), get())
.init()
configureGameListener()
}

View File

@@ -2,6 +2,7 @@ package eventDemo.configuration
import com.auth0.jwt.JWT
import com.auth0.jwt.algorithms.Algorithm
import eventDemo.app.entity.Player
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
import io.ktor.server.application.call
@@ -11,13 +12,15 @@ import io.ktor.server.auth.jwt.jwt
import io.ktor.server.response.respond
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
import kotlinx.serialization.json.Json
import java.util.Date
// TODO: read the jwt property from the config file
private val jwtRealm = "Play card game"
private val jwtIssuer = "PlayCardGame"
private val jwtSecret = "secret"
fun Application.configureSecurity() {
// TODO: read the jwt property from the config file
val jwtRealm = "Play card game"
val jwtIssuer = "PlayCardGame"
val jwtSecret = "secret"
authentication {
jwt {
realm = jwtRealm
@@ -42,17 +45,19 @@ fun Application.configureSecurity() {
routing {
post("login/{username}") {
val username = call.parameters["username"]
val username = call.parameters["username"]!!
val player = Player(name = username)
val token =
JWT
.create()
.withIssuer(jwtIssuer)
.withClaim("username", username)
.withExpiresAt(Date(System.currentTimeMillis() + 60000))
.sign(Algorithm.HMAC256(jwtSecret))
call.respond(hashMapOf("token" to token))
call.respond(hashMapOf("token" to player.makeJwt()))
}
}
}
fun Player.makeJwt(): String =
JWT
.create()
.withIssuer(jwtIssuer)
.withClaim("username", name)
.withPayload(Json.encodeToString(this))
.withExpiresAt(Date(System.currentTimeMillis() + 60000))
.sign(Algorithm.HMAC256(jwtSecret))

View File

@@ -0,0 +1,10 @@
package eventDemo.configuration
import eventDemo.app.eventListener.GameEventReactionListener
import io.ktor.server.application.Application
import org.koin.ktor.ext.get
fun Application.configureGameListener() {
GameEventReactionListener(get(), get())
.init()
}

View File

@@ -1,5 +1,7 @@
package eventDemo.configuration
import eventDemo.app.entity.GameId
import eventDemo.shared.GameIdSerializer
import eventDemo.shared.UUIDSerializer
import io.ktor.serialization.kotlinx.json.json
import io.ktor.server.application.Application
@@ -16,6 +18,7 @@ fun Application.configureSerialization() {
serializersModule =
SerializersModule {
contextual(UUID::class) { UUIDSerializer }
contextual(GameId::class) { GameIdSerializer }
}
},
)

View File

@@ -5,7 +5,9 @@ import eventDemo.app.command.gameSocket
import eventDemo.app.eventListener.GameEventPlayerNotificationListener
import io.ktor.server.application.Application
import io.ktor.server.routing.routing
import kotlinx.coroutines.DelicateCoroutinesApi
@OptIn(DelicateCoroutinesApi::class)
fun Application.declareWebSocketsGameRoute(
playerNotificationListener: GameEventPlayerNotificationListener,
commandHandler: GameCommandHandler,