mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-31 19:24:47 +02:00
Set default value for proxies
This commit is contained in:
@@ -10,6 +10,7 @@ import com.github.games647.fastlogin.core.importer.AutoInImporter;
|
|||||||
import com.github.games647.fastlogin.core.importer.ImportPlugin;
|
import com.github.games647.fastlogin.core.importer.ImportPlugin;
|
||||||
import com.github.games647.fastlogin.core.importer.Importer;
|
import com.github.games647.fastlogin.core.importer.Importer;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -70,7 +71,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
|
|
||||||
protected final Map<String, String> localeMessages = new ConcurrentHashMap<>();
|
protected final Map<String, String> localeMessages = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final ConcurrentMap<String, Object> pendingLogins = FastLoginCore.buildCache(5, 0);
|
private final ConcurrentMap<String, Object> pendingLogins = FastLoginCore.buildCache(5, -1);
|
||||||
private final Set<UUID> pendingConfirms = Sets.newHashSet();
|
private final Set<UUID> pendingConfirms = Sets.newHashSet();
|
||||||
private final T plugin;
|
private final T plugin;
|
||||||
|
|
||||||
@@ -127,7 +128,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
|
|
||||||
List<String> ipAddresses = sharedConfig.get("ip-addresses");
|
List<String> ipAddresses = sharedConfig.get("ip-addresses");
|
||||||
int requestLimit = sharedConfig.get("mojang-request-limit");
|
int requestLimit = sharedConfig.get("mojang-request-limit");
|
||||||
List<String> proxyList = sharedConfig.get("proxies");
|
List<String> proxyList = sharedConfig.get("proxies", Lists.newArrayList());
|
||||||
Map<String, Integer> proxies = proxyList.stream()
|
Map<String, Integer> proxies = proxyList.stream()
|
||||||
.collect(Collectors
|
.collect(Collectors
|
||||||
.toMap(line -> line.split(":")[0], line -> Integer.parseInt(line.split(":")[1])));
|
.toMap(line -> line.split(":")[0], line -> Integer.parseInt(line.split(":")[1])));
|
||||||
|
@@ -56,33 +56,8 @@ public abstract class MojangApiConnector {
|
|||||||
public MojangApiConnector(Logger logger, Collection<String> localAddresses, int rateLimit
|
public MojangApiConnector(Logger logger, Collection<String> localAddresses, int rateLimit
|
||||||
, Map<String, Integer> proxies) {
|
, Map<String, Integer> proxies) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.rateLimit = Math.max(rateLimit, 600);
|
||||||
if (rateLimit > 600) {
|
this.sslFactory = buildAddresses(logger, localAddresses);
|
||||||
this.rateLimit = 600;
|
|
||||||
} else {
|
|
||||||
this.rateLimit = rateLimit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (localAddresses.isEmpty()) {
|
|
||||||
this.sslFactory = null;
|
|
||||||
} else {
|
|
||||||
Set<InetAddress> addresses = Sets.newHashSet();
|
|
||||||
for (String localAddress : localAddresses) {
|
|
||||||
try {
|
|
||||||
InetAddress address = InetAddress.getByName(localAddress);
|
|
||||||
if (!address.isAnyLocalAddress()) {
|
|
||||||
logger.log(Level.WARNING, "Submitted IP-Address is not local {0}", address);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
addresses.add(address);
|
|
||||||
} catch (UnknownHostException ex) {
|
|
||||||
logger.log(Level.SEVERE, "IP-Address is unknown to us", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.sslFactory = new BalancedSSLFactory(HttpsURLConnection.getDefaultSSLSocketFactory(), addresses);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Proxy> proxyBuilder = Lists.newArrayList();
|
List<Proxy> proxyBuilder = Lists.newArrayList();
|
||||||
for (Entry<String, Integer> proxy : proxies.entrySet()) {
|
for (Entry<String, Integer> proxy : proxies.entrySet()) {
|
||||||
@@ -92,13 +67,15 @@ public abstract class MojangApiConnector {
|
|||||||
this.proxies = Iterables.cycle(proxyBuilder).iterator();
|
this.proxies = Iterables.cycle(proxyBuilder).iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null on non-premium
|
* @return null on non-premium
|
||||||
*/
|
*/
|
||||||
public UUID getPremiumUUID(String playerName) {
|
public UUID getPremiumUUID(String playerName) {
|
||||||
|
if (!nameMatcher.matcher(playerName).matches()) {
|
||||||
//check if it's a valid player name
|
//check if it's a valid player name
|
||||||
if (nameMatcher.matcher(playerName).matches()) {
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpsURLConnection connection;
|
HttpsURLConnection connection;
|
||||||
if (requests.size() >= rateLimit || System.currentTimeMillis() - lastRateLimit < 1_000 * 60 * 10) {
|
if (requests.size() >= rateLimit || System.currentTimeMillis() - lastRateLimit < 1_000 * 60 * 10) {
|
||||||
@@ -131,7 +108,6 @@ public abstract class MojangApiConnector {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.log(Level.SEVERE, "Failed to check if player has a paid account", ex);
|
logger.log(Level.SEVERE, "Failed to check if player has a paid account", ex);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -159,4 +135,27 @@ public abstract class MojangApiConnector {
|
|||||||
protected HttpsURLConnection getConnection(String url) throws IOException {
|
protected HttpsURLConnection getConnection(String url) throws IOException {
|
||||||
return getConnection(url, Proxy.NO_PROXY);
|
return getConnection(url, Proxy.NO_PROXY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BalancedSSLFactory buildAddresses(Logger logger, Collection<String> localAddresses) {
|
||||||
|
if (localAddresses.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
Set<InetAddress> addresses = Sets.newHashSet();
|
||||||
|
for (String localAddress : localAddresses) {
|
||||||
|
try {
|
||||||
|
InetAddress address = InetAddress.getByName(localAddress);
|
||||||
|
if (!address.isAnyLocalAddress()) {
|
||||||
|
logger.log(Level.WARNING, "Submitted IP-Address is not local {0}", address);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
addresses.add(address);
|
||||||
|
} catch (UnknownHostException ex) {
|
||||||
|
logger.log(Level.SEVERE, "IP-Address is unknown to us", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BalancedSSLFactory(HttpsURLConnection.getDefaultSSLSocketFactory(), addresses);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user