1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-19 14:59:20 +00:00

Make sure that the time we use is always the same across servers

This commit is contained in:
Tim203
2021-05-26 01:57:46 +02:00
parent a80d0e18e1
commit bfa40f5f08
4 changed files with 54 additions and 5 deletions

View File

@@ -47,6 +47,7 @@ import org.geysermc.floodgate.link.PlayerLinkLoader;
import org.geysermc.floodgate.module.ConfigLoadedModule;
import org.geysermc.floodgate.module.PostInitializeModule;
import org.geysermc.floodgate.util.PrefixCheckTask;
import org.geysermc.floodgate.util.TimeSyncerHolder;
public class FloodgatePlatform {
private static final UUID KEY = UUID.randomUUID();
@@ -97,6 +98,8 @@ public class FloodgatePlatform {
guice = guice.createChildInjector(new ConfigLoadedModule(config));
PlayerLink link = guice.getInstance(PlayerLinkLoader.class).load();
TimeSyncerHolder.init();
InstanceHolder.set(api, link, this.injector, packetHandlers, handshakeHandlers, KEY);
}

View File

@@ -39,10 +39,12 @@ import org.geysermc.floodgate.api.handshake.HandshakeData;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
import org.geysermc.floodgate.api.player.PropertyKey;
import org.geysermc.floodgate.api.player.PropertyKey.Result;
import org.geysermc.floodgate.time.TimeSyncer;
import org.geysermc.floodgate.util.BedrockData;
import org.geysermc.floodgate.util.DeviceOs;
import org.geysermc.floodgate.util.InputMode;
import org.geysermc.floodgate.util.LinkedPlayer;
import org.geysermc.floodgate.util.TimeSyncerHolder;
import org.geysermc.floodgate.util.UiProfile;
import org.geysermc.floodgate.util.Utils;
@@ -77,10 +79,7 @@ public final class FloodgatePlayerImpl implements FloodgatePlayer {
*/
@Setter private boolean login = true;
protected static FloodgatePlayerImpl from(
BedrockData data,
HandshakeData handshakeData) {
protected static FloodgatePlayerImpl from(BedrockData data, HandshakeData handshakeData) {
FloodgateApi api = InstanceHolder.getApi();
UUID javaUniqueId = Utils.getJavaUuid(data.getXuid());
@@ -109,9 +108,11 @@ public final class FloodgatePlayerImpl implements FloodgatePlayer {
}
public BedrockData toBedrockData() {
TimeSyncer timeSyncer = TimeSyncerHolder.get();
return BedrockData.of(version, username, xuid, deviceOs.ordinal(), languageCode,
uiProfile.ordinal(), inputMode.ordinal(), ip, linkedPlayer, proxy, subscribeId,
verifyCode);
verifyCode, timeSyncer);
}
@Override

View File

@@ -38,6 +38,7 @@ public final class Constants {
public static final boolean DEBUG_MODE = true;
public static final String NTP_SERVER = "time.cloudflare.com";
public static final String TIMESTAMP_DENIED_MESSAGE =
"Something isn't right with this data." +
" Try logging in again or contact a server administrator if the issue persists.";

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Floodgate
*/
package org.geysermc.floodgate.util;
import org.geysermc.floodgate.time.TimeSyncer;
public final class TimeSyncerHolder {
private static TimeSyncer timeSyncer;
public static void init() {
timeSyncer = new TimeSyncer(Constants.NTP_SERVER);
}
public static void set(TimeSyncer syncer) {
timeSyncer = syncer;
}
public static TimeSyncer get() {
return timeSyncer;
}
}