Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-10-04 00:41:13 +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:
Ursprung
498a415ac5
Commit
0004f5b051
@ -27,10 +27,22 @@ package org.geysermc.geyser.api.pack;
|
|||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
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 {
|
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
|
* @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.
|
* If the remote pack has an encryption key, it must be specified here.
|
||||||
* Otherwise, leave empty.
|
* Otherwise, leave empty.
|
||||||
*
|
* @return the encryption key of the resource pack
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public abstract String contentKey();
|
public abstract String contentKey();
|
||||||
|
@ -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.
|
// 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 (codec instanceof UrlPackCodec urlPackCodec) {
|
||||||
if (!GameProtocol.isPre1_20_30(this.session)) {
|
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 a request for a remote pack that the client should have already downloaded!" +
|
||||||
GeyserImpl.getInstance().getLogger().warning("Received ResourcePackChunkRequestPacket for URL pack " + urlPackCodec.url());
|
"Is the pack at the URL " + urlPackCodec.url() + " still available?");
|
||||||
|
|
||||||
WebUtils.checkUrlAndDownloadRemotePack(urlPackCodec.url());
|
WebUtils.checkUrlAndDownloadRemotePack(urlPackCodec.url());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ public class GeyserUrlPackCodec extends UrlPackCodec {
|
|||||||
throw new IllegalArgumentException("Unable to download pack from " + url, e);
|
throw new IllegalArgumentException("Unable to download pack from " + url, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ResourcePackLoader.loadDownloadedPack(this);
|
return ResourcePackLoader.readPack(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -113,7 +113,7 @@ public class ResourcePackLoader implements RegistryLoader<Path, Map<String, Reso
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load CDN entries
|
// Load CDN entries
|
||||||
packMap.putAll(loadCdnEntries());
|
packMap.putAll(loadRemotePacks());
|
||||||
|
|
||||||
GeyserDefineResourcePacksEventImpl defineEvent = new GeyserDefineResourcePacksEventImpl(packMap);
|
GeyserDefineResourcePacksEventImpl defineEvent = new GeyserDefineResourcePacksEventImpl(packMap);
|
||||||
packMap = defineEvent.getPacks();
|
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
|
* @throws IllegalArgumentException if the pack manifest was invalid or there was any processing exception
|
||||||
*/
|
*/
|
||||||
public static GeyserResourcePack readPack(Path path) throws IllegalArgumentException {
|
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!");
|
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);
|
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();
|
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.");
|
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");
|
final Path cachedCdnPacksDirectory = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("cache").resolve("remote_packs");
|
||||||
|
|
||||||
// Download CDN packs to get the pack uuid's
|
// 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 {
|
public static CompletableFuture<@Nullable Path> downloadPack(String url) throws IllegalArgumentException {
|
||||||
CompletableFuture<Path> future = WebUtils.checkUrlAndDownloadRemotePack(url);
|
return WebUtils.checkUrlAndDownloadRemotePack(url).whenCompleteAsync((cachedPath, throwable) -> {
|
||||||
future.whenCompleteAsync((cachedPath, throwable) -> {
|
|
||||||
if (cachedPath == null) {
|
if (cachedPath == null) {
|
||||||
return;
|
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);
|
throw new IllegalArgumentException(GeyserLocale.getLocaleStringLog("geyser.resource_pack.broken", url), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return future;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,12 +115,12 @@ public class WebUtils {
|
|||||||
|
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
GeyserImpl.getInstance().getLogger().error(String.format("Invalid size from remote pack URL: %s (size: %d)", url, size));
|
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")) {
|
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));
|
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();
|
InputStream in = con.getInputStream();
|
||||||
@ -128,9 +128,9 @@ public class WebUtils {
|
|||||||
Files.copy(in, fileLocation, StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(in, fileLocation, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
if (Files.size(fileLocation) != size) {
|
if (Files.size(fileLocation) != size) {
|
||||||
GeyserImpl.getInstance().getLogger().error("Server sent " + Files.size(fileLocation) + " bytes, expected " + size + " bytes");
|
GeyserImpl.getInstance().getLogger().error("Downloaded pack has " + Files.size(fileLocation) + " bytes, expected " + size + " bytes");
|
||||||
Files.delete(fileLocation);
|
//Files.delete(fileLocation);
|
||||||
return null;
|
//return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileLocation;
|
return fileLocation;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren