From 8be03f5c8afb4a6fc980c84ebd189956aeeed4f9 Mon Sep 17 00:00:00 2001 From: WuzzyLV Date: Thu, 12 Jun 2025 19:42:57 +0300 Subject: [PATCH] Update CraftAPI to 1.0-SNAPSHOT --- core/pom.xml | 2 +- .../core/ProxyAgnosticMojangResolver.java | 37 +++---------------- .../fastlogin/core/shared/FastLoginCore.java | 37 ++++++++++--------- 3 files changed, 26 insertions(+), 50 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 937d97cad..6780f2da3 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -203,7 +203,7 @@ com.github.games647 craftapi - 0.8.1 + 1.0-SNAPSHOT diff --git a/core/src/main/java/com/github/games647/fastlogin/core/ProxyAgnosticMojangResolver.java b/core/src/main/java/com/github/games647/fastlogin/core/ProxyAgnosticMojangResolver.java index e57680378..798d14472 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/ProxyAgnosticMojangResolver.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/ProxyAgnosticMojangResolver.java @@ -27,10 +27,9 @@ import com.github.games647.craftapi.model.auth.Verification; import com.github.games647.craftapi.resolver.MojangResolver; +import com.github.games647.craftapi.resolver.Options; import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; import java.net.InetAddress; import java.util.Optional; @@ -43,39 +42,13 @@ * @author games647, Enginecrafter77 */ public class ProxyAgnosticMojangResolver extends MojangResolver { - - private static final String HOST = "sessionserver.mojang.com"; - - /** - * A formatting string containing a URL used to call the {@code hasJoined} method on mojang session servers. - *

- * Formatting parameters: - * 1. The username of the player in question - * 2. The serverId of this server - */ - public static final String ENDPOINT = "https://" + HOST + "/session/minecraft/hasJoined?username=%s&serverId=%s"; - + public ProxyAgnosticMojangResolver(Options options) { + super(options); + } @Override public Optional hasJoined(String username, String serverHash, InetAddress hostIp) throws IOException { - String url = String.format(ENDPOINT, username, serverHash); - - HttpURLConnection conn = this.getConnection(url); - int responseCode = conn.getResponseCode(); - - Verification verification = null; - - // Mojang session servers send HTTP 204 (NO CONTENT) when the authentication seems invalid - // If that's not our case, the authentication is valid, and so we can parse the response. - if (responseCode != HttpURLConnection.HTTP_NO_CONTENT) { - verification = this.parseRequest(conn, this::parseVerification); - } - - return Optional.ofNullable(verification); + return super.hasJoined(username, serverHash, null); } - // Functional implementation of InputStreamAction, used in hasJoined method in parseRequest call - protected Verification parseVerification(InputStream input) throws IOException { - return this.readJson(input, Verification.class); - } } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java index c1fca7db3..7f692b335 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java @@ -26,6 +26,7 @@ package com.github.games647.fastlogin.core.shared; import com.github.games647.craftapi.resolver.MojangResolver; +import com.github.games647.craftapi.resolver.Options; import com.github.games647.craftapi.resolver.http.RotatingProxySelector; import com.github.games647.fastlogin.core.CommonUtil; import com.github.games647.fastlogin.core.ProxyAgnosticMojangResolver; @@ -48,11 +49,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.Reader; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.Proxy.Type; -import java.net.UnknownHostException; import java.nio.file.Files; import java.nio.file.Path; import java.time.Duration; @@ -121,30 +120,34 @@ public void load() { return; } - // Initialize the resolver based on the config parameter - this.resolver = this.config.getBoolean("useProxyAgnosticResolver", false) - ? new ProxyAgnosticMojangResolver() : new MojangResolver(); + Options resolverOptions = new Options(); + resolverOptions.setMaxNameRequests(config.getInt("mojang-request-limit", 600)); - antiBot = createAntiBotService(config.getSection("anti-bot")); Set proxies = config.getStringList("proxies") .stream() .map(proxy -> proxy.split(":")) .map(proxy -> new InetSocketAddress(proxy[0], Integer.parseInt(proxy[1]))) .map(sa -> new Proxy(Type.HTTP, sa)) .collect(toSet()); + resolverOptions.setProxySelector(new RotatingProxySelector(proxies)); + +// TODO: Fix this? +// Collection addresses = new HashSet<>(); +// for (String localAddress : config.getStringList("ip-addresses")) { +// try { +// addresses.add(InetAddress.getByName(localAddress.replace('-', '.'))); +// } catch (UnknownHostException ex) { +// plugin.getLog().error("IP-Address is unknown to us", ex); +// } +// } +// resolver.setOutgoingAddresses(addresses); - Collection addresses = new HashSet<>(); - for (String localAddress : config.getStringList("ip-addresses")) { - try { - addresses.add(InetAddress.getByName(localAddress.replace('-', '.'))); - } catch (UnknownHostException ex) { - plugin.getLog().error("IP-Address is unknown to us", ex); - } - } + // Initialize the resolver based on the config parameter + this.resolver = this.config.getBoolean("useProxyAgnosticResolver", false) + ? new ProxyAgnosticMojangResolver(resolverOptions) : new MojangResolver(resolverOptions); + + antiBot = createAntiBotService(config.getSection("anti-bot")); - resolver.setMaxNameRequests(config.getInt("mojang-request-limit")); - resolver.setProxySelector(new RotatingProxySelector(proxies)); - resolver.setOutgoingAddresses(addresses); } private AntiBotService createAntiBotService(Configuration botSection) {