From 203461af9bf832e66a322e99a0ce0275aee47b6f Mon Sep 17 00:00:00 2001 From: Dries C Date: Mon, 4 Mar 2024 11:04:29 +0100 Subject: [PATCH] Switch to microseconds for statistics --- .../proxytransport/impl/TransportClientConnection.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/nethergames/proxytransport/impl/TransportClientConnection.java b/src/main/java/org/nethergames/proxytransport/impl/TransportClientConnection.java index d689654..28a5d29 100644 --- a/src/main/java/org/nethergames/proxytransport/impl/TransportClientConnection.java +++ b/src/main/java/org/nethergames/proxytransport/impl/TransportClientConnection.java @@ -51,7 +51,7 @@ public class TransportClientConnection extends BedrockClientConnection { private final Channel channel; private long lastPingTimestamp; - private long latency; + private long latency; // Latency in microseconds private final List> scheduledTasks = new ArrayList<>(); @@ -105,7 +105,7 @@ private void onBedrockBatch(@NonNull BedrockBatchWrapper batch) { wrapper.release(); // release batch.modify(); - this.latency = (System.currentTimeMillis() - this.lastPingTimestamp) / 2; + this.latency = (System.nanoTime() - this.lastPingTimestamp) / 2000; this.broadcastPing(); } } @@ -181,7 +181,7 @@ public void collectStats() { sendPacket(packet); - this.lastPingTimestamp = System.currentTimeMillis(); + this.lastPingTimestamp = System.nanoTime(); } else if (this.channel instanceof EpollSocketChannel epollChannel) { this.latency = epollChannel.tcpInfo().rtt() / 2; this.broadcastPing(); @@ -200,7 +200,7 @@ public void collectStats() { private void broadcastPing() { TickSyncPacket latencyPacket = new TickSyncPacket(); - latencyPacket.setRequestTimestamp(getPlayer().getPing()); + latencyPacket.setRequestTimestamp(getPlayer().getPing() * 1000); latencyPacket.setResponseTimestamp(this.latency); sendPacket(latencyPacket);