Skip to content

Commit

Permalink
Server: Migrate getUptime() to uptime property
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvrs committed Mar 28, 2022
1 parent 7bf2de9 commit 34a3be4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/jvmMain/kotlin/org/golem/raknet/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<InetSocketAddress, Connection> = HashMap()

private lateinit var future: ChannelFuture
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/jvmMain/kotlin/org/golem/raknet/connection/Connection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Connection(
clientAddress = this.address,
systemIndex = 0,
requestTime = packet.time,
time = server.getUptime()
time = server.uptime,
))
}
is NewIncomingConnection -> {
Expand All @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 34a3be4

Please sign in to comment.