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 3d69064 commit 8596c28
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 7 deletions.
1 change: 0 additions & 1 deletion client/src/commonMain/kotlin/ui/waitingRoom.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ suspend fun waitingRoom(room: UUID) {
scroll.horizontal.view.visible = false
scroll.scrollTopRatio = 1f
onEvent(PacketEvent) { event ->
println("chat")
val packet = event.packet
if (packet !is ChatPacket) return@onEvent
val (username, message) = packet
Expand Down
2 changes: 1 addition & 1 deletion client/src/commonMain/kotlin/websocket/websocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ fun serverPacket(serverPacket: ServerPacket): PacketController<Any> = when(serve
PLAYER_LEAVE -> packet<PlayerLeavePacket>()
} as PacketController<Any>

private inline fun <reified T : Any> packet() = packet<T> { { sceneContainer.dispatch(PacketEvent(it)) } }
private inline fun <reified T : Any> packet() = packet<T> { sceneContainer.dispatch(PacketEvent(it)) }
5 changes: 1 addition & 4 deletions server/src/main/kotlin/application/websocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.util.*
import kotlin.collections.LinkedHashSet

val serverUUID = UUID.generateUUID()
val connections: MutableSet<Connection> = Collections.synchronizedSet<Connection?>(LinkedHashSet())
val connections: MutableSet<Connection> = Collections.synchronizedSet(LinkedHashSet())
fun getPlayersByRoom(room: UUID) =
connections.filter { runCatching { getPlayerBySession(it.session).room?.equals(room) }.getOrNull()?: false }

Expand Down Expand Up @@ -60,9 +60,6 @@ fun Application.configureWebsocket() {
suspend fun serverPacket(websocket: DefaultWebSocketSession, session: UUID, clientPacket: ClientPacket): PacketController<Any> = when(clientPacket) {
ClientPacket.GET_ROOM_NUMBER -> packet<UUID> {
transaction { Room.find(Rooms.id eq it).first().name }
}
ClientPacket.LEAVE_ROOM -> packet {

}
ClientPacket.CHAT -> packet<String> { received ->
val player = getPlayerBySession(session)
Expand Down
1 change: 0 additions & 1 deletion shared/src/commonMain/kotlin/network/Packets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import kotlinx.serialization.Serializable

enum class ClientPacket {
GET_ROOM_NUMBER,
LEAVE_ROOM,
CHAT
}

Expand Down

0 comments on commit 8596c28

Please sign in to comment.