mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2026-01-03 14:12:25 +00:00
Added an error margin for the timestamp
This commit is contained in:
@@ -64,7 +64,7 @@ public final class FloodgateHandshakeHandler {
|
||||
private final Cache<String, Long> 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);
|
||||
|
||||
Reference in New Issue
Block a user