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
private long lastWindowCloseTime = 0;
/**
* Saves the timestamp of the last keep alive packet
*/
@Setter
private long lastKeepAliveTimestamp = 0;
@Setter
private VillagerTrade[] villagerTrades;
@Setter

View file

@ -39,8 +39,6 @@ public class BedrockNetworkStackLatencyTranslator extends PacketTranslator<Netwo
@Override
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
ClientKeepAlivePacket keepAlivePacket = new ClientKeepAlivePacket(session.getLastKeepAliveTimestamp());
session.sendDownstreamPacket(keepAlivePacket);
session.sendDownstreamPacket(new ClientKeepAlivePacket(packet.getTimestamp() / 1000));
}
}

View file

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