mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-22 14:34:59 +01:00
Warn if we were unable to check if the system clock is accurate
This commit is contained in:
parent
776fc4e933
commit
934fc12b16
3 changed files with 21 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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()));
|
||||
|
|
Loading…
Reference in a new issue