Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce0203 committed Aug 4, 2023
1 parent f193c0a commit eb05a66
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions server/src/main/kotlin/application/websocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ suspend fun serverPacket(websocket: DefaultWebSocketSession, session: UUID, clie
ClientPacket.LEAVE_ROOM -> packet {

}
ClientPacket.CHAT -> packet<String> {
ClientPacket.CHAT -> packet<String> { 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<Any>

Expand Down

0 comments on commit eb05a66

Please sign in to comment.