3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 06:50:09 +01:00

Notify on disconnect when a new Geyser update is available

Dieser Commit ist enthalten in:
Camotoy 2023-02-15 00:01:33 -05:00
Ursprung f9705c1e46
Commit 6a6a601efc
3 geänderte Dateien mit 21 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -31,6 +31,7 @@ import com.nukkitx.protocol.bedrock.data.ExperimentData;
import com.nukkitx.protocol.bedrock.data.PacketCompressionAlgorithm; import com.nukkitx.protocol.bedrock.data.PacketCompressionAlgorithm;
import com.nukkitx.protocol.bedrock.data.ResourcePackType; import com.nukkitx.protocol.bedrock.data.ResourcePackType;
import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.packet.*;
import org.geysermc.geyser.Constants;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.network.AuthType; import org.geysermc.geyser.api.network.AuthType;
import org.geysermc.geyser.configuration.GeyserConfiguration; 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.text.GeyserLocale;
import org.geysermc.geyser.util.LoginEncryptionUtils; import org.geysermc.geyser.util.LoginEncryptionUtils;
import org.geysermc.geyser.util.MathUtils; import org.geysermc.geyser.util.MathUtils;
import org.geysermc.geyser.util.VersionCheckUtils;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Deque; import java.util.Deque;
import java.util.OptionalInt;
public class UpstreamPacketHandler extends LoggingPacketHandler { public class UpstreamPacketHandler extends LoggingPacketHandler {
@ -74,7 +77,14 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
String supportedVersions = GameProtocol.getAllSupportedBedrockVersions(); String supportedVersions = GameProtocol.getAllSupportedBedrockVersions();
if (protocolVersion > GameProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()) { if (protocolVersion > GameProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()) {
// Too early to determine session locale // 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; return false;
} else if (protocolVersion < GameProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()) { } else if (protocolVersion < GameProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()) {
session.disconnect(GeyserLocale.getLocaleStringLog("geyser.network.outdated.client", supportedVersions)); session.disconnect(GeyserLocale.getLocaleStringLog("geyser.network.outdated.client", supportedVersions));

Datei anzeigen

@ -38,10 +38,13 @@ import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.network.GameProtocol;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
import javax.annotation.Nonnull;
import java.util.OptionalInt;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier; import java.util.function.Supplier;
public final class VersionCheckUtils { public final class VersionCheckUtils {
private static @Nonnull OptionalInt LATEST_BEDROCK_RELEASE = OptionalInt.empty();
public static void checkForOutdatedFloodgate(GeyserLogger logger) { public static void checkForOutdatedFloodgate(GeyserLogger logger) {
try { try {
@ -61,10 +64,12 @@ public final class VersionCheckUtils {
JsonNode bedrock = json.get("bedrock").get("protocol"); JsonNode bedrock = json.get("bedrock").get("protocol");
int protocolVersion = bedrock.get("id").asInt(); int protocolVersion = bedrock.get("id").asInt();
if (GameProtocol.getBedrockCodec(protocolVersion) != null) { if (GameProtocol.getBedrockCodec(protocolVersion) != null) {
LATEST_BEDROCK_RELEASE = OptionalInt.empty();
// We support the latest version! No need to print a message. // We support the latest version! No need to print a message.
return; return;
} }
LATEST_BEDROCK_RELEASE = OptionalInt.of(protocolVersion);
final String newBedrockVersion = bedrock.get("name").asText(); final String newBedrockVersion = bedrock.get("name").asText();
// Delayed for two reasons: save unnecessary processing, and wait to load locale if this is on join. // 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() { private VersionCheckUtils() {
} }
} }

@ -1 +1 @@
Subproject commit f6685c4ccc6e77b07402d45cb41213559004b7d6 Subproject commit 24be9ef7f850f7d180650a65792c266c709cadf5