mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-29 18:27:36 +02:00
Fix address rotating for contacting the Mojang API
This commit is contained in:
@ -1,27 +1,23 @@
|
||||
package com.github.games647.fastlogin.core;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
public class BalancedSSLFactory extends SSLSocketFactory {
|
||||
|
||||
private final SSLSocketFactory oldFactory;
|
||||
|
||||
//in order to be thread-safe
|
||||
private final List<InetAddress> localAddresses;
|
||||
|
||||
private AtomicInteger id;
|
||||
private final Iterator<InetAddress> iterator;
|
||||
private final SSLSocketFactory oldFactory;
|
||||
|
||||
public BalancedSSLFactory(SSLSocketFactory oldFactory, Iterable<InetAddress> localAddresses) {
|
||||
this.oldFactory = oldFactory;
|
||||
this.localAddresses = ImmutableList.copyOf(localAddresses);
|
||||
this.iterator = Iterables.cycle(localAddresses).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,7 +59,8 @@ public class BalancedSSLFactory extends SSLSocketFactory {
|
||||
}
|
||||
|
||||
private InetAddress getNextLocalAddress() {
|
||||
int index = id.incrementAndGet() % localAddresses.size();
|
||||
return localAddresses.get(index);
|
||||
synchronized (iterator) {
|
||||
return iterator.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,8 +68,7 @@ public class CommonUtil {
|
||||
Class<JDK14LoggerAdapter> adapterClass = JDK14LoggerAdapter.class;
|
||||
Constructor<JDK14LoggerAdapter> cons = adapterClass.getDeclaredConstructor(java.util.logging.Logger.class);
|
||||
cons.setAccessible(true);
|
||||
JDK14LoggerAdapter logger = cons.newInstance(parent);
|
||||
return logger;
|
||||
return cons.newInstance(parent);
|
||||
} catch (ReflectiveOperationException reflectEx) {
|
||||
parent.log(Level.WARNING, "Cannot create slf4j logging adapter", reflectEx);
|
||||
parent.log(Level.WARNING, "Creating logger instance manually...");
|
||||
|
@ -153,7 +153,7 @@ public class MojangApiConnector {
|
||||
}
|
||||
|
||||
private SSLSocketFactory buildAddresses(Logger logger, Collection<String> localAddresses) {
|
||||
if (!localAddresses.isEmpty()) {
|
||||
if (localAddresses.isEmpty()) {
|
||||
return HttpsURLConnection.getDefaultSSLSocketFactory();
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
||||
}
|
||||
|
||||
private boolean checkPremiumName(S source, String username, PlayerProfile profile) throws Exception {
|
||||
core.getPlugin().getLog().debug("GameProfile {} uses a premium username", username);
|
||||
core.getPlugin().getLog().info("GameProfile {} uses a premium username", username);
|
||||
if (core.getConfig().get("autoRegister", false) && (authHook == null || !authHook.isRegistered(username))) {
|
||||
requestPremiumLogin(source, profile, username, false);
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user