From 934fc12b161f10c4a4e325b69d0ef3ba0a65b29a Mon Sep 17 00:00:00 2001 From: Tim203 Date: Wed, 26 May 2021 20:20:59 +0200 Subject: [PATCH] Warn if we were unable to check if the system clock is accurate --- .../org/geysermc/floodgate/time/TimeSyncer.java | 13 ++++++++++++- .../org/geysermc/floodgate/util/BedrockData.java | 8 +------- .../connector/network/session/GeyserSession.java | 8 ++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/org/geysermc/floodgate/time/TimeSyncer.java b/common/src/main/java/org/geysermc/floodgate/time/TimeSyncer.java index 2d74e4b77..1e385b2c6 100644 --- a/common/src/main/java/org/geysermc/floodgate/time/TimeSyncer.java +++ b/common/src/main/java/org/geysermc/floodgate/time/TimeSyncer.java @@ -37,7 +37,7 @@ public final class TimeSyncer { public TimeSyncer(String timeServer) { ScheduledExecutorService service = Executors.newScheduledThreadPool(1); service.scheduleWithFixedDelay(() -> { - // 5 tries to get the time offset + // 5 tries to get the time offset, since UDP doesn't guaranty a response for (int i = 0; i < 5; i++) { long offset = SntpClientUtils.requestTimeOffset(timeServer, 3000); if (offset != Long.MIN_VALUE) { @@ -56,4 +56,15 @@ public final class TimeSyncer { public long getTimeOffset() { return timeOffset; } + + public long getRealMillis() { + if (hasUsefulOffset()) { + return System.currentTimeMillis() + getTimeOffset(); + } + return System.currentTimeMillis(); + } + + public boolean hasUsefulOffset() { + return timeOffset != Long.MIN_VALUE; + } } diff --git a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java index 46c1d3d1a..4f4325a9b 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java +++ b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java @@ -62,15 +62,9 @@ public final class BedrockData implements Cloneable { String languageCode, int uiProfile, int inputMode, String ip, LinkedPlayer linkedPlayer, boolean fromProxy, int subscribeId, String verifyCode, TimeSyncer timeSyncer) { - - long realMillis = System.currentTimeMillis(); - if (timeSyncer.getTimeOffset() != Long.MIN_VALUE) { - realMillis += timeSyncer.getTimeOffset(); - } - return new BedrockData(version, username, xuid, deviceOs, languageCode, inputMode, uiProfile, ip, linkedPlayer, fromProxy, subscribeId, verifyCode, - realMillis, EXPECTED_LENGTH); + timeSyncer.getRealMillis(), EXPECTED_LENGTH); } public static BedrockData of( diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 9068323e6..eddc4c5a1 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -695,6 +695,14 @@ public class GeyserSession implements CommandSender { skinUploader.getVerifyCode(), connector.getTimeSyncer() ).toString()); + + if (!connector.getTimeSyncer().hasUsefulOffset()) { + connector.getLogger().warning( + "We couldn't make sure that your system clock is accurate. " + + "This can cause issues with logging in." + ); + } + } catch (Exception e) { connector.getLogger().error(LanguageUtils.getLocaleStringLog("geyser.auth.floodgate.encrypt_fail"), e); disconnect(LanguageUtils.getPlayerLocaleString("geyser.auth.floodgate.encryption_fail", getClientData().getLanguageCode()));