diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHost.java b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHost.java index fb0a1223c..9febdb22e 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHost.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHost.java @@ -67,6 +67,7 @@ public class SelfHost implements ResourcePackHost { if (port < 0 || port > 65535) { throw new IllegalArgumentException("Illegal port: '" + port + "' for self host"); } + boolean oneTimeToken = (boolean) arguments.getOrDefault("one-time-token", true); String protocol = (String) arguments.getOrDefault("protocol", "http"); boolean denyNonMinecraftRequest = (boolean) arguments.getOrDefault("deny-non-minecraft-request", true); Map rateMap = MiscUtils.castToMap(arguments.get("rate-map"), true); @@ -76,7 +77,7 @@ public class SelfHost implements ResourcePackHost { maxRequests = (int) rateMap.getOrDefault("max-requests", 5); resetInterval = (int) rateMap.getOrDefault("reset-interval", 20) * 1000; } - selfHostHttpServer.updateProperties(ip, port, denyNonMinecraftRequest, protocol, maxRequests, resetInterval); + selfHostHttpServer.updateProperties(ip, port, denyNonMinecraftRequest, protocol, maxRequests, resetInterval, oneTimeToken); return INSTANCE; } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHostHttpServer.java b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHostHttpServer.java index cd1666c1f..0a08193e6 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHostHttpServer.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHostHttpServer.java @@ -49,6 +49,7 @@ public class SelfHostHttpServer { private int port = -1; private String protocol = "http"; private boolean denyNonMinecraft = true; + private boolean useToken; private volatile byte[] resourcePackBytes; private String packHash; @@ -59,12 +60,14 @@ public class SelfHostHttpServer { boolean denyNonMinecraft, String protocol, int maxRequests, - int resetInternal) { + int resetInternal, + boolean token) { this.ip = ip; this.denyNonMinecraft = denyNonMinecraft; this.protocol = protocol; this.rateLimit = maxRequests; this.rateLimitInterval = resetInternal; + this.useToken = token; if (port <= 0 || port > 65535) { throw new IllegalArgumentException("Invalid port number: " + port); } @@ -96,6 +99,9 @@ public class SelfHostHttpServer { if (this.resourcePackBytes == null) { return null; } + if (!this.useToken) { + return new ResourcePackDownloadData(url(), packUUID, packHash); + } String token = UUID.randomUUID().toString(); this.oneTimePackUrls.put(token, true); return new ResourcePackDownloadData( @@ -172,10 +178,12 @@ public class SelfHostHttpServer { handleBlockedRequest(exchange, 429, "Rate limit exceeded"); return; } - String token = parseToken(exchange); - if (!validateToken(token)) { - handleBlockedRequest(exchange, 403, "Invalid token"); - return; + if (useToken) { + String token = parseToken(exchange); + if (!validateToken(token)) { + handleBlockedRequest(exchange, 403, "Invalid token"); + return; + } } if (!validateClient(exchange)) { handleBlockedRequest(exchange, 403, "Invalid client");