3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-10-03 16:31:14 +02:00

Testing: Don't require application/zip or size or weird zip format, since it seems to work without it !?

Dieser Commit ist enthalten in:
onebeastchris 2023-11-09 12:13:59 +01:00
Ursprung 498a415ac5
Commit 0004f5b051
5 geänderte Dateien mit 28 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -27,10 +27,22 @@ package org.geysermc.geyser.api.pack;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Represents a pack codec that creates a resource
* pack from a URL.
* <p>
* Due to Bedrock limitations, the URL must:
* <ul>
* <li>be a direct download link to a .zip or .mcpack resource pack</li>
* <li>Use application type `application/zip` and set a correct content length</li>
* </ul>
*
* Additionally, the ResourcePack must be zipped in a folder enclosing the resource pack, instead of the resource pack being at the root of the zip.
*/
public abstract class UrlPackCodec extends PackCodec {
/**
* Gets the URL of the resource pack.
* Gets the URL to the resource pack location.
*
* @return the URL of the resource pack
*/
@ -40,7 +52,7 @@ public abstract class UrlPackCodec extends PackCodec {
/**
* If the remote pack has an encryption key, it must be specified here.
* Otherwise, leave empty.
*
* @return the encryption key of the resource pack
*/
@NonNull
public abstract String contentKey();

Datei anzeigen

@ -279,9 +279,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
// Check for packs that the client should normally download on its own. If the client cannot find the pack, we provide it instead.
if (codec instanceof UrlPackCodec urlPackCodec) {
if (!GameProtocol.isPre1_20_30(this.session)) {
// TODO: Proper pack checking - could be that the remote url is offline, the pack changed, or.. something?
GeyserImpl.getInstance().getLogger().warning("Received ResourcePackChunkRequestPacket for URL pack " + urlPackCodec.url());
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());
}
}

Datei anzeigen

@ -92,7 +92,7 @@ public class GeyserUrlPackCodec extends UrlPackCodec {
throw new IllegalArgumentException("Unable to download pack from " + url, e);
}
}
return ResourcePackLoader.loadDownloadedPack(this);
return ResourcePackLoader.readPack(this);
}
@Override

Datei anzeigen

@ -113,7 +113,7 @@ public class ResourcePackLoader implements RegistryLoader<Path, Map<String, Reso
}
// Load CDN entries
packMap.putAll(loadCdnEntries());
packMap.putAll(loadRemotePacks());
GeyserDefineResourcePacksEventImpl defineEvent = new GeyserDefineResourcePacksEventImpl(packMap);
packMap = defineEvent.getPacks();
@ -130,7 +130,7 @@ public class ResourcePackLoader implements RegistryLoader<Path, Map<String, Reso
* @throws IllegalArgumentException if the pack manifest was invalid or there was any processing exception
*/
public static GeyserResourcePack readPack(Path path) throws IllegalArgumentException {
if (!path.getFileName().toString().endsWith(".mcpack") && !path.getFileName().toString().endsWith(".zip")) {
if (!PACK_MATCHER.matches(path)) {
throw new IllegalArgumentException("Resource pack " + path.getFileName() + " must be a .zip or .mcpack file!");
}
@ -150,9 +150,9 @@ public class ResourcePackLoader implements RegistryLoader<Path, Map<String, Reso
return new GeyserResourcePack(new GeyserPathPackCodec(path), manifest, contentKey);
}
public static ResourcePack loadDownloadedPack(GeyserUrlPackCodec codec) throws IllegalArgumentException {
public static GeyserResourcePack readPack(GeyserUrlPackCodec codec) throws IllegalArgumentException {
Path path = codec.getFallback().path();
if (!path.getFileName().toString().endsWith(".mcpack") && !path.getFileName().toString().endsWith(".zip")) {
if (!PACK_MATCHER.matches(path)) {
throw new IllegalArgumentException("The url " + codec.url() + " did not provide a valid resource pack! Please check the url and try again.");
}
@ -198,7 +198,7 @@ public class ResourcePackLoader implements RegistryLoader<Path, Map<String, Reso
}
}
public Map<String, ResourcePack> loadCdnEntries() {
public Map<String, ResourcePack> loadRemotePacks() {
final Path cachedCdnPacksDirectory = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("cache").resolve("remote_packs");
// Download CDN packs to get the pack uuid's
@ -230,8 +230,7 @@ public class ResourcePackLoader implements RegistryLoader<Path, Map<String, Reso
}
public static CompletableFuture<@Nullable Path> downloadPack(String url) throws IllegalArgumentException {
CompletableFuture<Path> future = WebUtils.checkUrlAndDownloadRemotePack(url);
future.whenCompleteAsync((cachedPath, throwable) -> {
return WebUtils.checkUrlAndDownloadRemotePack(url).whenCompleteAsync((cachedPath, throwable) -> {
if (cachedPath == null) {
return;
}
@ -263,6 +262,5 @@ public class ResourcePackLoader implements RegistryLoader<Path, Map<String, Reso
throw new IllegalArgumentException(GeyserLocale.getLocaleStringLog("geyser.resource_pack.broken", url), e);
}
});
return future;
}
}

Datei anzeigen

@ -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();
@ -128,9 +128,9 @@ public class WebUtils {
Files.copy(in, fileLocation, StandardCopyOption.REPLACE_EXISTING);
if (Files.size(fileLocation) != size) {
GeyserImpl.getInstance().getLogger().error("Server sent " + Files.size(fileLocation) + " bytes, expected " + size + " bytes");
Files.delete(fileLocation);
return null;
GeyserImpl.getInstance().getLogger().error("Downloaded pack has " + Files.size(fileLocation) + " bytes, expected " + size + " bytes");
//Files.delete(fileLocation);
//return null;
}
return fileLocation;