diff --git a/server/src/main/kotlin/application/configuration/authentication.kt b/server/src/main/kotlin/application/configuration/authentication.kt index f89568a..38ba6b4 100644 --- a/server/src/main/kotlin/application/configuration/authentication.kt +++ b/server/src/main/kotlin/application/configuration/authentication.kt @@ -20,12 +20,11 @@ fun Application.configureAuthentication() { install(Authentication) { basic { validate { session -> - println("session=$session") - println(transaction { Session.all().map { it.id } }) //throw exception when not found val uuid = UUID(session.password) - transaction { Session.find(model.Sessions.id eq uuid).first() } - UserSession(uuid) + runCatching { transaction { + Session.find(model.Sessions.id eq uuid).first().id.value.run(::UserSession) + } }.getOrNull() } } } diff --git a/server/src/main/kotlin/application/websocket.kt b/server/src/main/kotlin/application/websocket.kt index 6d9b42b..542a25f 100644 --- a/server/src/main/kotlin/application/websocket.kt +++ b/server/src/main/kotlin/application/websocket.kt @@ -62,10 +62,12 @@ suspend fun serverPacket(websocket: DefaultWebSocketSession, session: UUID, clie ClientPacket.LEAVE_ROOM -> packet { } - ClientPacket.CHAT -> packet { + ClientPacket.CHAT -> packet { received -> val player = getPlayerBySession(session) - connections.mapNotNull { runCatching { getPlayerBySession(it.session).room?.equals(player.room) }.getOrNull() } - websocket.sendToClient(ServerPacket.CHAT, Chat(player.name, it)) + connections.filter { runCatching { getPlayerBySession(it.session).room?.equals(player.room) }.getOrNull()?: false } + .forEach { + it.websocket.sendToClient(ServerPacket.CHAT, Chat(player.name, received)) + } } } as PacketController