From 348db7d5af85a5d6f284f152c319686b94b1b15d Mon Sep 17 00:00:00 2001 From: Matthew Jordan Date: Sun, 27 Mar 2022 19:18:56 -0500 Subject: [PATCH] Server: Migrate getUptime() to uptime property --- src/jvmMain/kotlin/org/golem/raknet/Server.kt | 4 ++-- .../kotlin/org/golem/raknet/connection/Connection.kt | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/jvmMain/kotlin/org/golem/raknet/Server.kt b/src/jvmMain/kotlin/org/golem/raknet/Server.kt index 83aa2c7..a3ed590 100644 --- a/src/jvmMain/kotlin/org/golem/raknet/Server.kt +++ b/src/jvmMain/kotlin/org/golem/raknet/Server.kt @@ -32,6 +32,8 @@ class Server( private val group = NioEventLoopGroup() private val startTime: Long = System.currentTimeMillis() + val uptime: Long + get() = System.currentTimeMillis() - startTime private val connections: HashMap = HashMap() private lateinit var future: ChannelFuture @@ -67,8 +69,6 @@ class Server( return this.future } - fun getUptime(): Long = System.currentTimeMillis() - startTime - fun addConnection(connection: Connection) { eventBus.dispatch(ServerEvent.NewConnection(connection)) connections[connection.address] = connection diff --git a/src/jvmMain/kotlin/org/golem/raknet/connection/Connection.kt b/src/jvmMain/kotlin/org/golem/raknet/connection/Connection.kt index 406f473..c4f1c33 100644 --- a/src/jvmMain/kotlin/org/golem/raknet/connection/Connection.kt +++ b/src/jvmMain/kotlin/org/golem/raknet/connection/Connection.kt @@ -53,7 +53,7 @@ class Connection( clientAddress = this.address, systemIndex = 0, requestTime = packet.time, - time = server.getUptime() + time = server.uptime, )) } is NewIncomingConnection -> { @@ -68,11 +68,11 @@ class Connection( } is ConnectedPing -> internalsHandler.sendInternal(ConnectedPong( pingTime = packet.time, - pongTime = server.getUptime() + pongTime = server.uptime )) is ConnectedPong -> { // Compute latency - latency = server.getUptime() - packet.pingTime + latency = server.uptime - packet.pingTime eventBus.dispatch(ConnectionEvent.LatencyUpdated(latency)) } is DisconnectionNotification -> close(DisconnectionReason.ClientRequested) @@ -85,7 +85,7 @@ class Connection( fun send(packet: OnlineMessage, immediate: Boolean = false) = internalsHandler.send(packet, immediate) - fun ping() = send(ConnectedPing(time = server.getUptime()), true) + fun ping() = send(ConnectedPing(time = server.uptime), true) fun getEventBus() = eventBus