From b86c42c7eb2ae03bf23397ab246a5bc8d30fc4c3 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Fri, 28 May 2021 16:33:11 +0200 Subject: [PATCH] Added an error margin for the timestamp --- .../player/FloodgateHandshakeHandler.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/org/geysermc/floodgate/player/FloodgateHandshakeHandler.java b/common/src/main/java/org/geysermc/floodgate/player/FloodgateHandshakeHandler.java index fe9b3851..fa34e8ea 100644 --- a/common/src/main/java/org/geysermc/floodgate/player/FloodgateHandshakeHandler.java +++ b/common/src/main/java/org/geysermc/floodgate/player/FloodgateHandshakeHandler.java @@ -64,7 +64,7 @@ public final class FloodgateHandshakeHandler { private final Cache handleCache = CacheBuilder.newBuilder() .maximumSize(500) - .expireAfterWrite(1, TimeUnit.MINUTES) + .expireAfterWrite(10, TimeUnit.SECONDS) .build(); private final HandshakeHandlersImpl handshakeHandlers; @@ -118,8 +118,11 @@ public final class FloodgateHandshakeHandler { "This can cause issues with logging in."); } + // the time syncer is accurate, but we have to account for some minor differences + final int errorMargin = 150; // 150ms + long timeDifference = timeSyncer.getRealMillis() - bedrockData.getTimestamp(); - if (timeDifference > 6000 || timeDifference < 0) { + if (timeDifference > 6000 + errorMargin || timeDifference < -errorMargin) { if (Constants.DEBUG_MODE || logger.isDebug()) { logger.info("Current time: " + System.currentTimeMillis()); logger.info("Stored time: " + bedrockData.getTimestamp()); @@ -132,9 +135,10 @@ public final class FloodgateHandshakeHandler { Long cachedTimestamp = handleCache.getIfPresent(bedrockData.getXuid()); if (cachedTimestamp != null) { - // the cached timestamp is newer than the gotten timestamp - // you also can't reuse the data (the timestamp is there to prevent that as well) - if (cachedTimestamp >= bedrockData.getTimestamp()) { + // the cached timestamp should be older than the received timestamp + // and it should also not be possible to reuse the handshake + long diff = bedrockData.getTimestamp() - cachedTimestamp; + if (diff == 0 || diff < 0 && -diff > errorMargin) { return callHandlerAndReturnResult( ResultType.TIMESTAMP_DENIED, channel, bedrockData, hostname);