Warn if we were unable to check if the system clock is accurate

This commit is contained in:
Tim203 2021-05-26 20:20:59 +02:00
parent 776fc4e933
commit 934fc12b16
No known key found for this signature in database
GPG Key ID: 064EE9F5BF7C3EE8
3 changed files with 21 additions and 8 deletions

View File

@ -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;
}
}

View File

@ -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(

View File

@ -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()));