From 6a6a601efc3a73281210842e7f9a39fc8ef21db2 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Wed, 15 Feb 2023 00:01:33 -0500 Subject: [PATCH] Notify on disconnect when a new Geyser update is available --- .../geyser/network/UpstreamPacketHandler.java | 12 +++++++++++- .../org/geysermc/geyser/util/VersionCheckUtils.java | 9 +++++++++ core/src/main/resources/languages | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index 227f0ed5a..a72d8ab9e 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -31,6 +31,7 @@ import com.nukkitx.protocol.bedrock.data.ExperimentData; import com.nukkitx.protocol.bedrock.data.PacketCompressionAlgorithm; import com.nukkitx.protocol.bedrock.data.ResourcePackType; import com.nukkitx.protocol.bedrock.packet.*; +import org.geysermc.geyser.Constants; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.network.AuthType; import org.geysermc.geyser.configuration.GeyserConfiguration; @@ -43,11 +44,13 @@ import org.geysermc.geyser.session.PendingMicrosoftAuthentication; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.util.LoginEncryptionUtils; import org.geysermc.geyser.util.MathUtils; +import org.geysermc.geyser.util.VersionCheckUtils; import java.io.FileInputStream; import java.io.InputStream; import java.util.ArrayDeque; import java.util.Deque; +import java.util.OptionalInt; public class UpstreamPacketHandler extends LoggingPacketHandler { @@ -74,7 +77,14 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { String supportedVersions = GameProtocol.getAllSupportedBedrockVersions(); if (protocolVersion > GameProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()) { // Too early to determine session locale - session.disconnect(GeyserLocale.getLocaleStringLog("geyser.network.outdated.server", supportedVersions)); + String disconnectMessage = GeyserLocale.getLocaleStringLog("geyser.network.outdated.server", supportedVersions); + // If the latest release matches this version, then let the user know. + OptionalInt latestRelease = VersionCheckUtils.getLatestBedrockRelease(); + if (latestRelease.isPresent() && latestRelease.getAsInt() == protocolVersion) { + // Random note: don't make the disconnect message too long or Bedrock will cut it off on smaller screens + disconnectMessage += "\n" + GeyserLocale.getLocaleStringLog("geyser.version.new.on_disconnect", Constants.GEYSER_DOWNLOAD_LOCATION); + } + session.disconnect(disconnectMessage); return false; } else if (protocolVersion < GameProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()) { session.disconnect(GeyserLocale.getLocaleStringLog("geyser.network.outdated.client", supportedVersions)); diff --git a/core/src/main/java/org/geysermc/geyser/util/VersionCheckUtils.java b/core/src/main/java/org/geysermc/geyser/util/VersionCheckUtils.java index 049d78619..dc0edd37a 100644 --- a/core/src/main/java/org/geysermc/geyser/util/VersionCheckUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/VersionCheckUtils.java @@ -38,10 +38,13 @@ import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.text.GeyserLocale; +import javax.annotation.Nonnull; +import java.util.OptionalInt; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; public final class VersionCheckUtils { + private static @Nonnull OptionalInt LATEST_BEDROCK_RELEASE = OptionalInt.empty(); public static void checkForOutdatedFloodgate(GeyserLogger logger) { try { @@ -61,10 +64,12 @@ public final class VersionCheckUtils { JsonNode bedrock = json.get("bedrock").get("protocol"); int protocolVersion = bedrock.get("id").asInt(); if (GameProtocol.getBedrockCodec(protocolVersion) != null) { + LATEST_BEDROCK_RELEASE = OptionalInt.empty(); // We support the latest version! No need to print a message. return; } + LATEST_BEDROCK_RELEASE = OptionalInt.of(protocolVersion); final String newBedrockVersion = bedrock.get("name").asText(); // Delayed for two reasons: save unnecessary processing, and wait to load locale if this is on join. @@ -89,6 +94,10 @@ public final class VersionCheckUtils { }); } + public static @Nonnull OptionalInt getLatestBedrockRelease() { + return LATEST_BEDROCK_RELEASE; + } + private VersionCheckUtils() { } } diff --git a/core/src/main/resources/languages b/core/src/main/resources/languages index f6685c4cc..24be9ef7f 160000 --- a/core/src/main/resources/languages +++ b/core/src/main/resources/languages @@ -1 +1 @@ -Subproject commit f6685c4ccc6e77b07402d45cb41213559004b7d6 +Subproject commit 24be9ef7f850f7d180650a65792c266c709cadf5