mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 10:47:33 +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,45 +67,46 @@ 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) {
|
||||||
//check if it's a valid player name
|
if (!nameMatcher.matcher(playerName).matches()) {
|
||||||
if (nameMatcher.matcher(playerName).matches()) {
|
//check if it's a valid player name
|
||||||
try {
|
return null;
|
||||||
HttpsURLConnection connection;
|
}
|
||||||
if (requests.size() >= rateLimit || System.currentTimeMillis() - lastRateLimit < 1_000 * 60 * 10) {
|
|
||||||
synchronized (proxies) {
|
|
||||||
if (proxies.hasNext()) {
|
|
||||||
connection = getConnection(UUID_LINK + playerName, proxies.next());
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
requests.put(new Object(), new Object());
|
|
||||||
connection = getConnection(UUID_LINK + playerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
try {
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
HttpsURLConnection connection;
|
||||||
String line = reader.readLine();
|
if (requests.size() >= rateLimit || System.currentTimeMillis() - lastRateLimit < 1_000 * 60 * 10) {
|
||||||
if (!"null".equals(line)) {
|
synchronized (proxies) {
|
||||||
return FastLoginCore.parseId(getUUIDFromJson(line));
|
if (proxies.hasNext()) {
|
||||||
}
|
connection = getConnection(UUID_LINK + playerName, proxies.next());
|
||||||
} else if (connection.getResponseCode() == RATE_LIMIT_CODE) {
|
} else {
|
||||||
logger.info("RATE_LIMIT REACHED");
|
return null;
|
||||||
lastRateLimit = System.currentTimeMillis();
|
|
||||||
if (!connection.usingProxy()) {
|
|
||||||
return getPremiumUUID(playerName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//204 - no content for not found
|
} else {
|
||||||
} catch (Exception ex) {
|
requests.put(new Object(), new Object());
|
||||||
logger.log(Level.SEVERE, "Failed to check if player has a paid account", ex);
|
connection = getConnection(UUID_LINK + playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
String line = reader.readLine();
|
||||||
|
if (!"null".equals(line)) {
|
||||||
|
return FastLoginCore.parseId(getUUIDFromJson(line));
|
||||||
|
}
|
||||||
|
} else if (connection.getResponseCode() == RATE_LIMIT_CODE) {
|
||||||
|
logger.info("RATE_LIMIT REACHED");
|
||||||
|
lastRateLimit = System.currentTimeMillis();
|
||||||
|
if (!connection.usingProxy()) {
|
||||||
|
return getPremiumUUID(playerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//204 - no content for not found
|
||||||
|
} catch (Exception 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