mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-23 15:00:37 +01:00
Notify on disconnect when a new Geyser update is available
This commit is contained in:
parent
f9705c1e46
commit
6a6a601efc
3 changed files with 21 additions and 2 deletions
|
@ -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));
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit f6685c4ccc6e77b07402d45cb41213559004b7d6
|
||||
Subproject commit 24be9ef7f850f7d180650a65792c266c709cadf5
|
Loading…
Reference in a new issue