Handle keepalives better (Closes #965)

Bedrock cuts off the last 3 digits consistently every time, meaning that the keepalive returned from bedrock is never fully accurate. However, if we multiply the value by 1000, then divide by 1000 when sending back to java, the proper value is returned.
This commit is contained in:
RednedEpic 2020-12-12 00:45:41 -06:00
parent a60ab4e80e
commit 70031c65e7
3 changed files with 2 additions and 11 deletions

View file

@ -196,12 +196,6 @@ public class GeyserSession implements CommandSender {
@Setter @Setter
private long lastWindowCloseTime = 0; private long lastWindowCloseTime = 0;
/**
* Saves the timestamp of the last keep alive packet
*/
@Setter
private long lastKeepAliveTimestamp = 0;
@Setter @Setter
private VillagerTrade[] villagerTrades; private VillagerTrade[] villagerTrades;
@Setter @Setter

View file

@ -39,8 +39,6 @@ public class BedrockNetworkStackLatencyTranslator extends PacketTranslator<Netwo
@Override @Override
public void translate(NetworkStackLatencyPacket packet, GeyserSession session) { public void translate(NetworkStackLatencyPacket packet, GeyserSession session) {
// The client sends a timestamp back but it's rounded and therefore unreliable when we need the exact number session.sendDownstreamPacket(new ClientKeepAlivePacket(packet.getTimestamp() / 1000));
ClientKeepAlivePacket keepAlivePacket = new ClientKeepAlivePacket(session.getLastKeepAliveTimestamp());
session.sendDownstreamPacket(keepAlivePacket);
} }
} }

View file

@ -39,10 +39,9 @@ public class JavaKeepAliveTranslator extends PacketTranslator<ServerKeepAlivePac
@Override @Override
public void translate(ServerKeepAlivePacket packet, GeyserSession session) { public void translate(ServerKeepAlivePacket packet, GeyserSession session) {
session.setLastKeepAliveTimestamp(packet.getPingId());
NetworkStackLatencyPacket latencyPacket = new NetworkStackLatencyPacket(); NetworkStackLatencyPacket latencyPacket = new NetworkStackLatencyPacket();
latencyPacket.setFromServer(true); latencyPacket.setFromServer(true);
latencyPacket.setTimestamp(packet.getPingId()); latencyPacket.setTimestamp(packet.getPingId() * 1000);
session.sendUpstreamPacket(latencyPacket); session.sendUpstreamPacket(latencyPacket);
} }
} }