Add support for IPv6 proxies

This commit is contained in:
games647 committed 2017-09-22 21:08:24 +02:00
1 parent 16f7461568
commit 2932de5588
7 files changed
+34 -38

No files matched your search

@@ -8,6 +8,9 @@ import java.util.concurrent.TimeUnit;
public class CommonUtil {
private static final char COLOR_CHAR = '&';
private static final char TRANSLATED_CHAR = '§';
public static <K, V> ConcurrentMap<K, V> buildCache(int expireAfterWrite, int maxSize) {
CompatibleCacheBuilder<Object, Object> builder = CompatibleCacheBuilder.newBuilder();
@@ -36,6 +39,18 @@ public class CommonUtil {
+ '-' + withoutDashes.substring(20, 32));
}
public static String translateColorCodes(String rawMessage) {
char[] chars = rawMessage.toCharArray();
for (int i = 0; i < chars.length - 1; i++) {
if (chars[i] == COLOR_CHAR && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(chars[i + 1]) > -1) {
chars[i] = TRANSLATED_CHAR;
chars[i + 1] = Character.toLowerCase(chars[i + 1]);
}
}
return new String(chars);
}
private CommonUtil() {
//Utility class
}
@@ -6,6 +6,7 @@ import com.github.games647.fastlogin.core.shared.LoginSession;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.net.HostAndPort;
import com.google.gson.Gson;
import java.io.BufferedReader;
@@ -22,7 +23,6 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
@@ -56,14 +56,14 @@ public class MojangApiConnector {
protected final Logger logger;
public MojangApiConnector(Logger logger, Collection<String> localAddresses, int rateLimit
, Map<String, Integer> proxies) {
, List<HostAndPort> proxies) {
this.logger = logger;
this.rateLimit = Math.max(rateLimit, 600);
this.sslFactory = buildAddresses(logger, localAddresses);
List<Proxy> proxyBuilder = Lists.newArrayList();
for (Entry<String, Integer> proxy : proxies.entrySet()) {
proxyBuilder.add(new Proxy(Type.HTTP, new InetSocketAddress(proxy.getKey(), proxy.getValue())));
for (HostAndPort proxy : proxies) {
proxyBuilder.add(new Proxy(Type.HTTP, new InetSocketAddress(proxy.getHostText(), proxy.getPort())));
}
this.proxies = Iterables.cycle(proxyBuilder).iterator();
@@ -8,6 +8,7 @@ import com.github.games647.fastlogin.core.hooks.PasswordGenerator;
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.net.HostAndPort;
import java.io.File;
import java.io.IOException;
@@ -65,7 +66,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
.filter(key -> messages.get(key) != null)
.collect(Collectors.toMap(Function.identity(), messages::get))
.forEach((key, message) -> {
String colored = plugin.translateColorCodes('&', (String) message);
String colored = CommonUtil.translateColorCodes((String) message);
if (!colored.isEmpty()) {
localeMessages.put(key, colored);
}
@@ -77,11 +78,9 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
List<String> ipAddresses = config.getStringList("ip-addresses");
int requestLimit = config.getInt("mojang-request-limit");
List<String> proxyList = config.get("proxies", Lists.newArrayList());
Map<String, Integer> proxies = proxyList.stream()
.collect(Collectors
.toMap(line -> line.split(":")[0], line -> Integer.parseInt(line.split(":")[1])));
List<HostAndPort> proxies = proxyList.stream().map(HostAndPort::fromString).collect(Collectors.toList());
this.apiConnector = plugin.makeApiConnector(plugin.getLogger(), ipAddresses, requestLimit, proxies);
this.apiConnector = plugin.makeApiConnector(ipAddresses, requestLimit, proxies);
}
private Configuration loadFile(String fileName) throws IOException {
@@ -1,10 +1,10 @@
package com.github.games647.fastlogin.core.shared;
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
import com.google.common.net.HostAndPort;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadFactory;
import java.util.logging.Logger;
@@ -20,8 +20,5 @@ public interface PlatformPlugin<C> {
ThreadFactory getThreadFactory();
String translateColorCodes(char colorChar, String rawMessage);
MojangApiConnector makeApiConnector(Logger logger, List<String> addresses, int requests
, Map<String, Integer> proxies);
MojangApiConnector makeApiConnector(List<String> addresses, int requests, List<HostAndPort> proxies);
}