Skip to content

Commit 8be03f5

Browse files
committed
Update CraftAPI to 1.0-SNAPSHOT
1 parent c28c634 commit 8be03f5

File tree

3 files changed

+26
-50
lines changed

3 files changed

+26
-50
lines changed

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
<dependency>
204204
<groupId>com.github.games647</groupId>
205205
<artifactId>craftapi</artifactId>
206-
<version>0.8.1</version>
206+
<version>1.0-SNAPSHOT</version>
207207
</dependency>
208208

209209
<!-- Database driver included in Spigot -->

core/src/main/java/com/github/games647/fastlogin/core/ProxyAgnosticMojangResolver.java

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727

2828
import com.github.games647.craftapi.model.auth.Verification;
2929
import com.github.games647.craftapi.resolver.MojangResolver;
30+
import com.github.games647.craftapi.resolver.Options;
3031

3132
import java.io.IOException;
32-
import java.io.InputStream;
33-
import java.net.HttpURLConnection;
3433
import java.net.InetAddress;
3534
import java.util.Optional;
3635

@@ -43,39 +42,13 @@
4342
* @author games647, Enginecrafter77
4443
*/
4544
public class ProxyAgnosticMojangResolver extends MojangResolver {
46-
47-
private static final String HOST = "sessionserver.mojang.com";
48-
49-
/**
50-
* A formatting string containing a URL used to call the {@code hasJoined} method on mojang session servers.
51-
* <p>
52-
* Formatting parameters:
53-
* 1. The username of the player in question
54-
* 2. The serverId of this server
55-
*/
56-
public static final String ENDPOINT = "https://" + HOST + "/session/minecraft/hasJoined?username=%s&serverId=%s";
57-
45+
public ProxyAgnosticMojangResolver(Options options) {
46+
super(options);
47+
}
5848
@Override
5949
public Optional<Verification> hasJoined(String username, String serverHash, InetAddress hostIp)
6050
throws IOException {
61-
String url = String.format(ENDPOINT, username, serverHash);
62-
63-
HttpURLConnection conn = this.getConnection(url);
64-
int responseCode = conn.getResponseCode();
65-
66-
Verification verification = null;
67-
68-
// Mojang session servers send HTTP 204 (NO CONTENT) when the authentication seems invalid
69-
// If that's not our case, the authentication is valid, and so we can parse the response.
70-
if (responseCode != HttpURLConnection.HTTP_NO_CONTENT) {
71-
verification = this.parseRequest(conn, this::parseVerification);
72-
}
73-
74-
return Optional.ofNullable(verification);
51+
return super.hasJoined(username, serverHash, null);
7552
}
7653

77-
// Functional implementation of InputStreamAction, used in hasJoined method in parseRequest call
78-
protected Verification parseVerification(InputStream input) throws IOException {
79-
return this.readJson(input, Verification.class);
80-
}
8154
}

core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package com.github.games647.fastlogin.core.shared;
2727

2828
import com.github.games647.craftapi.resolver.MojangResolver;
29+
import com.github.games647.craftapi.resolver.Options;
2930
import com.github.games647.craftapi.resolver.http.RotatingProxySelector;
3031
import com.github.games647.fastlogin.core.CommonUtil;
3132
import com.github.games647.fastlogin.core.ProxyAgnosticMojangResolver;
@@ -48,11 +49,9 @@
4849
import java.io.IOException;
4950
import java.io.InputStream;
5051
import java.io.Reader;
51-
import java.net.InetAddress;
5252
import java.net.InetSocketAddress;
5353
import java.net.Proxy;
5454
import java.net.Proxy.Type;
55-
import java.net.UnknownHostException;
5655
import java.nio.file.Files;
5756
import java.nio.file.Path;
5857
import java.time.Duration;
@@ -121,30 +120,34 @@ public void load() {
121120
return;
122121
}
123122

124-
// Initialize the resolver based on the config parameter
125-
this.resolver = this.config.getBoolean("useProxyAgnosticResolver", false)
126-
? new ProxyAgnosticMojangResolver() : new MojangResolver();
123+
Options resolverOptions = new Options();
124+
resolverOptions.setMaxNameRequests(config.getInt("mojang-request-limit", 600));
127125

128-
antiBot = createAntiBotService(config.getSection("anti-bot"));
129126
Set<Proxy> proxies = config.getStringList("proxies")
130127
.stream()
131128
.map(proxy -> proxy.split(":"))
132129
.map(proxy -> new InetSocketAddress(proxy[0], Integer.parseInt(proxy[1])))
133130
.map(sa -> new Proxy(Type.HTTP, sa))
134131
.collect(toSet());
132+
resolverOptions.setProxySelector(new RotatingProxySelector(proxies));
133+
134+
// TODO: Fix this?
135+
// Collection<InetAddress> addresses = new HashSet<>();
136+
// for (String localAddress : config.getStringList("ip-addresses")) {
137+
// try {
138+
// addresses.add(InetAddress.getByName(localAddress.replace('-', '.')));
139+
// } catch (UnknownHostException ex) {
140+
// plugin.getLog().error("IP-Address is unknown to us", ex);
141+
// }
142+
// }
143+
// resolver.setOutgoingAddresses(addresses);
135144

136-
Collection<InetAddress> addresses = new HashSet<>();
137-
for (String localAddress : config.getStringList("ip-addresses")) {
138-
try {
139-
addresses.add(InetAddress.getByName(localAddress.replace('-', '.')));
140-
} catch (UnknownHostException ex) {
141-
plugin.getLog().error("IP-Address is unknown to us", ex);
142-
}
143-
}
145+
// Initialize the resolver based on the config parameter
146+
this.resolver = this.config.getBoolean("useProxyAgnosticResolver", false)
147+
? new ProxyAgnosticMojangResolver(resolverOptions) : new MojangResolver(resolverOptions);
148+
149+
antiBot = createAntiBotService(config.getSection("anti-bot"));
144150

145-
resolver.setMaxNameRequests(config.getInt("mojang-request-limit"));
146-
resolver.setProxySelector(new RotatingProxySelector(proxies));
147-
resolver.setOutgoingAddresses(addresses);
148151
}
149152

150153
private AntiBotService createAntiBotService(Configuration botSection) {

0 commit comments

Comments
 (0)