diff --git a/src/main/java/org/nethergames/proxytransport/impl/TransportClientConnection.java b/src/main/java/org/nethergames/proxytransport/impl/TransportClientConnection.java index 28a5d29..17bf4c4 100644 --- a/src/main/java/org/nethergames/proxytransport/impl/TransportClientConnection.java +++ b/src/main/java/org/nethergames/proxytransport/impl/TransportClientConnection.java @@ -10,11 +10,6 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.epoll.EpollSocketChannel; -import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.incubator.codec.quic.QuicChannel; -import io.netty.incubator.codec.quic.QuicConnectionStats; -import io.netty.util.concurrent.Future; import lombok.NonNull; import lombok.extern.log4j.Log4j2; import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec; @@ -168,39 +163,25 @@ public void enableEncryption(SecretKey secretKey) { @Override public long getPing() { - return latency; + return this.latency / 1000; } public void collectStats() { var connection = getPlayer().getDownstreamConnection(); if (connection instanceof TransportClientConnection && connection.getServerInfo().getServerName().equalsIgnoreCase(getServerInfo().getServerName())) { - if (this.channel instanceof NioSocketChannel) { - NetworkStackLatencyPacket packet = new NetworkStackLatencyPacket(); - packet.setTimestamp(0L); - packet.setFromServer(true); + NetworkStackLatencyPacket packet = new NetworkStackLatencyPacket(); + packet.setTimestamp(0L); + packet.setFromServer(true); - sendPacket(packet); + sendPacket(packet); - this.lastPingTimestamp = System.nanoTime(); - } else if (this.channel instanceof EpollSocketChannel epollChannel) { - this.latency = epollChannel.tcpInfo().rtt() / 2; - this.broadcastPing(); - } else if (this.channel instanceof QuicChannel quicChannel) { - quicChannel.collectStats().addListener((Future future) -> { - if (future.isSuccess()) { - QuicConnectionStats stats = future.getNow(); - - this.latency = stats.recv(); - this.broadcastPing(); - } - }); - } + this.lastPingTimestamp = System.nanoTime(); } } private void broadcastPing() { TickSyncPacket latencyPacket = new TickSyncPacket(); - latencyPacket.setRequestTimestamp(getPlayer().getPing() * 1000); + latencyPacket.setRequestTimestamp(getPlayer().getPing()); latencyPacket.setResponseTimestamp(this.latency); sendPacket(latencyPacket);