mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-08-02 04:04:42 +02:00
Fix message loading was interacting with the normal config
This commit is contained in:
@@ -8,6 +8,7 @@ import com.github.games647.fastlogin.bukkit.listener.protocollib.LoginSkinApplyL
|
|||||||
import com.github.games647.fastlogin.bukkit.listener.protocollib.ProtocolLibListener;
|
import com.github.games647.fastlogin.bukkit.listener.protocollib.ProtocolLibListener;
|
||||||
import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener;
|
import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener;
|
||||||
import com.github.games647.fastlogin.bukkit.tasks.DelayedAuthHook;
|
import com.github.games647.fastlogin.bukkit.tasks.DelayedAuthHook;
|
||||||
|
import com.github.games647.fastlogin.core.CommonUtil;
|
||||||
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
|
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
|
||||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||||
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
|
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
|
||||||
@@ -42,7 +43,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
|
|||||||
private boolean serverStarted;
|
private boolean serverStarted;
|
||||||
|
|
||||||
//1 minutes should be enough as a timeout for bad internet connection (Server, Client and Mojang)
|
//1 minutes should be enough as a timeout for bad internet connection (Server, Client and Mojang)
|
||||||
private final ConcurrentMap<String, BukkitLoginSession> loginSession = FastLoginCore.buildCache(1, -1);
|
private final ConcurrentMap<String, BukkitLoginSession> loginSession = CommonUtil.buildCache(1, -1);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
package com.github.games647.fastlogin.bukkit;
|
package com.github.games647.fastlogin.bukkit;
|
||||||
|
|
||||||
|
import com.github.games647.fastlogin.core.CommonUtil;
|
||||||
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
|
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
|
||||||
import com.github.games647.fastlogin.core.mojang.SkinProperties;
|
import com.github.games647.fastlogin.core.mojang.SkinProperties;
|
||||||
import com.github.games647.fastlogin.core.mojang.VerificationReply;
|
import com.github.games647.fastlogin.core.mojang.VerificationReply;
|
||||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
|
||||||
import com.github.games647.fastlogin.core.shared.LoginSession;
|
import com.github.games647.fastlogin.core.shared.LoginSession;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -45,7 +45,7 @@ public class MojangApiBukkit extends MojangApiConnector {
|
|||||||
VerificationReply verification = gson.fromJson(reader, VerificationReply.class);
|
VerificationReply verification = gson.fromJson(reader, VerificationReply.class);
|
||||||
|
|
||||||
String uuid = verification.getId();
|
String uuid = verification.getId();
|
||||||
playerSession.setUuid(FastLoginCore.parseId(uuid));
|
playerSession.setUuid(CommonUtil.parseId(uuid));
|
||||||
|
|
||||||
SkinProperties[] properties = verification.getProperties();
|
SkinProperties[] properties = verification.getProperties();
|
||||||
if (properties != null && properties.length > 0) {
|
if (properties != null && properties.length > 0) {
|
||||||
|
@@ -93,7 +93,7 @@ public class AuthStorage {
|
|||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
long userId = resultSet.getInt(1);
|
long userId = resultSet.getInt(1);
|
||||||
|
|
||||||
UUID uuid = FastLoginCore.parseId(resultSet.getString(2));
|
UUID uuid = CommonUtil.parseId(resultSet.getString(2));
|
||||||
|
|
||||||
boolean premium = resultSet.getBoolean(4);
|
boolean premium = resultSet.getBoolean(4);
|
||||||
String lastIp = resultSet.getString(5);
|
String lastIp = resultSet.getString(5);
|
||||||
|
@@ -0,0 +1,42 @@
|
|||||||
|
package com.github.games647.fastlogin.core;
|
||||||
|
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class CommonUtil {
|
||||||
|
|
||||||
|
public static <K, V> ConcurrentMap<K, V> buildCache(int expireAfterWrite, int maxSize) {
|
||||||
|
CompatibleCacheBuilder<Object, Object> builder = CompatibleCacheBuilder.newBuilder();
|
||||||
|
|
||||||
|
if (expireAfterWrite > 0) {
|
||||||
|
builder.expireAfterWrite(expireAfterWrite, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxSize > 0) {
|
||||||
|
builder.maximumSize(maxSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build(CacheLoader.from(() -> {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UUID parseId(String withoutDashes) {
|
||||||
|
if (withoutDashes == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return UUID.fromString(withoutDashes.substring(0, 8)
|
||||||
|
+ '-' + withoutDashes.substring(8, 12)
|
||||||
|
+ '-' + withoutDashes.substring(12, 16)
|
||||||
|
+ '-' + withoutDashes.substring(16, 20)
|
||||||
|
+ '-' + withoutDashes.substring(20, 32));
|
||||||
|
}
|
||||||
|
|
||||||
|
private CommonUtil() {
|
||||||
|
//Utility class
|
||||||
|
}
|
||||||
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
package com.github.games647.fastlogin.core.mojang;
|
package com.github.games647.fastlogin.core.mojang;
|
||||||
|
|
||||||
import com.github.games647.fastlogin.core.BalancedSSLFactory;
|
import com.github.games647.fastlogin.core.BalancedSSLFactory;
|
||||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
import com.github.games647.fastlogin.core.CommonUtil;
|
||||||
import com.github.games647.fastlogin.core.shared.LoginSession;
|
import com.github.games647.fastlogin.core.shared.LoginSession;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -47,7 +47,7 @@ public class MojangApiConnector {
|
|||||||
private final Pattern validNameMatcher = Pattern.compile("^\\w{2,16}$");
|
private final Pattern validNameMatcher = Pattern.compile("^\\w{2,16}$");
|
||||||
|
|
||||||
private final Iterator<Proxy> proxies;
|
private final Iterator<Proxy> proxies;
|
||||||
private final Map<Object, Object> requests = FastLoginCore.buildCache(10, -1);
|
private final Map<Object, Object> requests = CommonUtil.buildCache(10, -1);
|
||||||
private final BalancedSSLFactory sslFactory;
|
private final BalancedSSLFactory sslFactory;
|
||||||
private final int rateLimit;
|
private final int rateLimit;
|
||||||
private long lastRateLimit;
|
private long lastRateLimit;
|
||||||
@@ -97,7 +97,7 @@ public class MojangApiConnector {
|
|||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||||
String line = reader.readLine();
|
String line = reader.readLine();
|
||||||
if (!"null".equals(line)) {
|
if (!"null".equals(line)) {
|
||||||
return FastLoginCore.parseId(getUUIDFromJson(line));
|
return CommonUtil.parseId(getUUIDFromJson(line));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (connection.getResponseCode() == RATE_LIMIT_CODE) {
|
} else if (connection.getResponseCode() == RATE_LIMIT_CODE) {
|
||||||
|
@@ -1,12 +1,11 @@
|
|||||||
package com.github.games647.fastlogin.core.shared;
|
package com.github.games647.fastlogin.core.shared;
|
||||||
|
|
||||||
import com.github.games647.fastlogin.core.AuthStorage;
|
import com.github.games647.fastlogin.core.AuthStorage;
|
||||||
import com.github.games647.fastlogin.core.CompatibleCacheBuilder;
|
import com.github.games647.fastlogin.core.CommonUtil;
|
||||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||||
import com.github.games647.fastlogin.core.hooks.DefaultPasswordGenerator;
|
import com.github.games647.fastlogin.core.hooks.DefaultPasswordGenerator;
|
||||||
import com.github.games647.fastlogin.core.hooks.PasswordGenerator;
|
import com.github.games647.fastlogin.core.hooks.PasswordGenerator;
|
||||||
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
|
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
|
||||||
import com.google.common.cache.CacheLoader;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
@@ -22,7 +21,6 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -38,37 +36,9 @@ import net.md_5.bungee.config.YamlConfiguration;
|
|||||||
*/
|
*/
|
||||||
public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
||||||
|
|
||||||
public static <K, V> ConcurrentMap<K, V> buildCache(int expireAfterWrite, int maxSize) {
|
|
||||||
CompatibleCacheBuilder<Object, Object> builder = CompatibleCacheBuilder.newBuilder();
|
|
||||||
|
|
||||||
if (expireAfterWrite > 0) {
|
|
||||||
builder.expireAfterWrite(expireAfterWrite, TimeUnit.MINUTES);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maxSize > 0) {
|
|
||||||
builder.maximumSize(maxSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.build(CacheLoader.from(() -> {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UUID parseId(String withoutDashes) {
|
|
||||||
if (withoutDashes == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return UUID.fromString(withoutDashes.substring(0, 8)
|
|
||||||
+ '-' + withoutDashes.substring(8, 12)
|
|
||||||
+ '-' + withoutDashes.substring(12, 16)
|
|
||||||
+ '-' + withoutDashes.substring(16, 20)
|
|
||||||
+ '-' + withoutDashes.substring(20, 32));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final Map<String, String> localeMessages = new ConcurrentHashMap<>();
|
protected final Map<String, String> localeMessages = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final ConcurrentMap<String, Object> pendingLogin = FastLoginCore.buildCache(5, -1);
|
private final ConcurrentMap<String, Object> pendingLogin = CommonUtil.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;
|
||||||
|
|
||||||
@@ -92,8 +62,8 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
|
|
||||||
messages.getKeys()
|
messages.getKeys()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(key -> config.get(key) != null)
|
.filter(key -> messages.get(key) != null)
|
||||||
.collect(Collectors.toMap(Function.identity(), config::get))
|
.collect(Collectors.toMap(Function.identity(), messages::get))
|
||||||
.forEach((key, message) -> {
|
.forEach((key, message) -> {
|
||||||
String colored = plugin.translateColorCodes('&', (String) message);
|
String colored = plugin.translateColorCodes('&', (String) message);
|
||||||
if (!colored.isEmpty()) {
|
if (!colored.isEmpty()) {
|
||||||
|
Reference in New Issue
Block a user