Switch to mcapi.ca and add configurable number of requests
This commit is contained in:
1 parent
757ddb905a
commit
c50249edea
9 files changed
+77
-79
No files matched your search
@@ -18,6 +18,7 @@ import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.security.KeyPair;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
@@ -45,19 +46,8 @@ public class FastLoginBukkit extends JavaPlugin {
|
||||
|
||||
//this map is thread-safe for async access (Packet Listener)
|
||||
//SafeCacheBuilder is used in order to be version independent
|
||||
private final ConcurrentMap<String, BukkitLoginSession> session = CompatibleCacheBuilder
|
||||
.<String, BukkitLoginSession>newBuilder()
|
||||
//2 minutes should be enough as a timeout for bad internet connection (Server, Client and Mojang)
|
||||
.expireAfterWrite(1, TimeUnit.MINUTES)
|
||||
//mapped by ip:port -> PlayerSession
|
||||
.build(new CacheLoader<String, BukkitLoginSession>() {
|
||||
|
||||
@Override
|
||||
public BukkitLoginSession load(String key) throws Exception {
|
||||
//A key should be inserted manually on start packet
|
||||
throw new UnsupportedOperationException("Not supported");
|
||||
}
|
||||
});
|
||||
private final ConcurrentMap<String, BukkitLoginSession> session = buildCache(1, -1);
|
||||
//1 minutes should be enough as a timeout for bad internet connection (Server, Client and Mojang)
|
||||
|
||||
private BukkitAuthPlugin authPlugin;
|
||||
private PasswordGenerator passwordGenerator = new DefaultPasswordGenerator();
|
||||
@@ -67,9 +57,10 @@ public class FastLoginBukkit extends JavaPlugin {
|
||||
core.loadConfig();
|
||||
core.loadMessages();
|
||||
|
||||
core.setMojangApiConnector(new MojangApiBukkit(core
|
||||
, getConfig().getStringList("ip-addresses")
|
||||
, getConfig().getBoolean("lookup-third-party")));
|
||||
List<String> ipAddresses = getConfig().getStringList("ip-addresses");
|
||||
int requestLimit = getConfig().getInt("mojang-request-limit");
|
||||
MojangApiBukkit mojangApi = new MojangApiBukkit(buildCache(10, -1), getLogger(), ipAddresses, requestLimit);
|
||||
core.setMojangApiConnector(mojangApi);
|
||||
|
||||
try {
|
||||
if (ClassUtil.isPresent("org.spigotmc.SpigotConfig")) {
|
||||
@@ -227,4 +218,23 @@ public class FastLoginBukkit extends JavaPlugin {
|
||||
this.serverStarted = true;
|
||||
}
|
||||
}
|
||||
|
||||
private <K, V> ConcurrentMap<K, V> buildCache(int minutes, int maxSize) {
|
||||
CompatibleCacheBuilder<Object, Object> builder = CompatibleCacheBuilder.newBuilder();
|
||||
|
||||
if (minutes > 0) {
|
||||
builder.expireAfterWrite(minutes, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
if (maxSize > 0) {
|
||||
builder.maximumSize(maxSize);
|
||||
}
|
||||
|
||||
return builder.build(new CacheLoader<K, V>() {
|
||||
@Override
|
||||
public V load(K key) throws Exception {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,9 @@ import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
@@ -19,8 +21,9 @@ public class MojangApiBukkit extends MojangApiConnector {
|
||||
//mojang api check to prove a player is logged in minecraft and made a join server request
|
||||
private static final String HAS_JOINED_URL = "https://sessionserver.mojang.com/session/minecraft/hasJoined?";
|
||||
|
||||
public MojangApiBukkit(FastLoginCore plugin, List<String> localAddresses, boolean apiLookup) {
|
||||
super(plugin, localAddresses, apiLookup);
|
||||
public MojangApiBukkit(ConcurrentMap<Object, Object> requests, Logger logger, List<String> localAddresses
|
||||
, int rateLimit) {
|
||||
super(requests, logger, localAddresses, rateLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,7 +60,7 @@ public class MojangApiBukkit extends MojangApiConnector {
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
//catch not only ioexceptions also parse and NPE on unexpected json format
|
||||
plugin.getLogger().log(Level.WARNING, "Failed to verify session", ex);
|
||||
logger.log(Level.WARNING, "Failed to verify session", ex);
|
||||
}
|
||||
|
||||
//this connection doesn't need to be closed. So can make use of keep alive in java
|
||||
@@ -70,11 +73,4 @@ public class MojangApiBukkit extends MojangApiConnector {
|
||||
String uuid = (String) userData.get("id");
|
||||
return FastLoginCore.parseId(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID getUUIDFromJsonAPI(String json) {
|
||||
JSONObject userData = (JSONObject) JSONValue.parse(json);
|
||||
String uuid = (String) userData.get("uuid");
|
||||
return FastLoginCore.parseId(uuid);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user