From 626189fa25e51e905fbf2885e9169b3208d62cb3 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Thu, 21 Dec 2023 22:08:15 +0100 Subject: [PATCH] remove debug, ensure we fully check failed packs, merge master --- .../geysermc/geyser/network/GameProtocol.java | 4 ---- .../geyser/network/UpstreamPacketHandler.java | 22 +++++++++---------- .../registry/loader/ResourcePackLoader.java | 6 +++++ .../org/geysermc/geyser/util/WebUtils.java | 6 ++--- core/src/main/resources/config.yml | 1 + 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java index 9607486e4..42cce607b 100644 --- a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java +++ b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java @@ -88,10 +88,6 @@ public final class GameProtocol { return session.getUpstream().getProtocolVersion() < Bedrock_v630.CODEC.getProtocolVersion(); } - public static boolean isPre1_20_30(GeyserSession session) { - return session.getUpstream().getProtocolVersion() < Bedrock_v618.CODEC.getProtocolVersion(); - } - /** * Gets the {@link PacketCodec} for Minecraft: Java Edition. * 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 406d25630..8459e9f16 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -44,13 +44,13 @@ import org.geysermc.geyser.event.type.SessionLoadResourcePacksEventImpl; import org.geysermc.geyser.pack.GeyserResourcePack; import org.geysermc.geyser.registry.BlockRegistries; import org.geysermc.geyser.registry.Registries; +import org.geysermc.geyser.registry.loader.ResourcePackLoader; import org.geysermc.geyser.session.GeyserSession; 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 org.geysermc.geyser.util.WebUtils; import java.io.IOException; import java.nio.ByteBuffer; @@ -61,7 +61,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { private boolean networkSettingsRequested = false; private final Deque packsToSent = new ArrayDeque<>(); - private final List brokenResourcePacks = new ArrayList<>(); + private final Set brokenResourcePacks = new HashSet<>(); private SessionLoadResourcePacksEventImpl resourcePackLoadEvent; @@ -186,7 +186,6 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { } resourcePacksInfo.setForcedToAccept(GeyserImpl.getInstance().getConfig().isForceResourcePacks()); - GeyserImpl.getInstance().getLogger().info(resourcePacksInfo.toString()); session.sendUpstreamPacket(resourcePacksInfo); GeyserLocale.loadGeyserLocale(session.locale()); @@ -280,16 +279,15 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { ResourcePack pack = this.resourcePackLoadEvent.getPacks().get(packet.getPackId().toString()); PackCodec codec = pack.codec(); - // Check for packs that the client should normally download on its own. If the client cannot find the pack, we provide it instead. + // If a remote pack ends up here, that usually implies that a platform was not able to download the pack if (codec instanceof UrlPackCodec urlPackCodec) { - if (!GameProtocol.isPre1_20_30(this.session)) { - // Ensure we don't a. spam console, and b. spam download/check requests - if (!brokenResourcePacks.contains(packet.getPackId())) { - brokenResourcePacks.add(packet.getPackId()); - GeyserImpl.getInstance().getLogger().warning("Received a request for a remote pack that the client should have already downloaded!" + - "Is the pack at the URL " + urlPackCodec.url() + " still available?"); - WebUtils.checkUrlAndDownloadRemotePack(urlPackCodec.url()); - } + // Ensure we don't a. spam console, and b. spam download/check requests + if (!brokenResourcePacks.contains(packet.getPackId())) { + brokenResourcePacks.add(packet.getPackId()); + GeyserImpl.getInstance().getLogger().warning("Received a request for a remote pack that the client should have already downloaded!" + + "Is the pack at the URL " + urlPackCodec.url() + " still available?"); + // not actually interested in using the download, but this does all the checks we need + ResourcePackLoader.downloadPack(urlPackCodec.url()); } } diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ResourcePackLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ResourcePackLoader.java index 8f387ba8d..6680c3825 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ResourcePackLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ResourcePackLoader.java @@ -100,6 +100,8 @@ public class ResourcePackLoader implements RegistryLoader downloadPack(String url) throws IllegalArgumentException { + + //TODO check if our cache pack is fine (size, url hash; head req) + return WebUtils.checkUrlAndDownloadRemotePack(url).whenCompleteAsync((cachedPath, throwable) -> { if (cachedPath == null) { + // already warned about in WebUtils return; } diff --git a/core/src/main/java/org/geysermc/geyser/util/WebUtils.java b/core/src/main/java/org/geysermc/geyser/util/WebUtils.java index b66d3f292..487b9b198 100644 --- a/core/src/main/java/org/geysermc/geyser/util/WebUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/WebUtils.java @@ -115,12 +115,12 @@ public class WebUtils { if (size <= 0) { GeyserImpl.getInstance().getLogger().error(String.format("Invalid size from remote pack URL: %s (size: %d)", url, size)); - //return null; + return null; } if (type == null || !type.equals("application/zip")) { GeyserImpl.getInstance().getLogger().error(String.format("Invalid application type from remote pack URL: %s (type: %s)", url, type)); - //return null; + return null; } InputStream in = con.getInputStream(); @@ -137,7 +137,7 @@ public class WebUtils { } catch (MalformedURLException e) { throw new IllegalArgumentException("Malformed URL: " + url); } catch (IOException e) { - throw new RuntimeException("Unable to download and save file: " + url + ")"); + throw new RuntimeException("Unable to download and save remote resource pack from: " + url + ")"); } }); } diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 6358a00a5..6f282dbf5 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -174,6 +174,7 @@ force-resource-packs: true # A list of links to send to the client to download resource packs from. # These must be direct links to the resource pack, not a link to a page containing the resource pack. +# If you enter a link here, Geyser will download the resource pack once to check if it's in a valid format. resource-pack-urls: # Example: GeyserOptionalPack - "https://ci.opencollab.dev/job/GeyserMC/job/GeyserOptionalPack/job/master/lastSuccessfulBuild/artifact/GeyserOptionalPack.mcpack"