Refactor a lot of code + Add Guava v10 as shared library

This commit is contained in:
games647
2016-09-11 21:26:03 +02:00
parent 2cd50d23ad
commit 76f5ba7ed1
29 changed files with 128 additions and 150 deletions

View File

@ -1,9 +1,10 @@
######1.9
* Refactored/Cleaned up a lot of code
* [API] Deprecated platform specific authplugin. Please use AuthPlugin< platform specific player type >
* [API] Deprecated bukkit's password generator. Please use PasswordGenerator< platform specific player type >
* Added second attempt login -> cracked login
* Add cracked whitelist (switch-mode -> switching to online-mode from offlinemode)
* Added cracked whitelist (switch-mode -> switching to online-mode from offlinemode)
* Added configuration to disable auto logins for 2Factor authentication
* Add missing add-premium-other message
* Fix ProtocolSupport autoRegister

View File

@ -104,6 +104,7 @@
<artifactId>LoginSecurity-2</artifactId>
<!--Old version 2.0 -->
<version>-9c09e73b7f-1</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>*</groupId>
@ -116,6 +117,7 @@
<groupId>com.lenis0012.bukkit</groupId>
<artifactId>loginsecurity</artifactId>
<version>2.1.3-SNAPSHOT</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>*</groupId>
@ -128,6 +130,7 @@
<groupId>com.github.games647</groupId>
<artifactId>LogIt</artifactId>
<version>9e3581db27</version>
<optional>true</optional>
<scope>provided</scope>
<exclusions>
<exclusion>
@ -141,6 +144,7 @@
<groupId>com.github.RoyalDev</groupId>
<artifactId>RoyalAuth</artifactId>
<version>-e21354a9b7-1</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>*</groupId>

View File

@ -1,45 +1,24 @@
package com.github.games647.fastlogin.bukkit;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.google.common.base.Charsets;
import com.google.common.cache.CacheLoader;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.io.File;
import java.io.InputStreamReader;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
public class BukkitCore extends FastLoginCore {
public static <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.");
}
});
}
public class BukkitCore extends FastLoginCore<Player> {
private final FastLoginBukkit plugin;
public BukkitCore(FastLoginBukkit plugin) {
super(BukkitCore.<String, Object>buildCache(5, 0), plugin.getConfig().getValues(false));
super(plugin.getConfig().getValues(false));
this.plugin = plugin;
}

View File

@ -14,13 +14,10 @@ import com.github.games647.fastlogin.bukkit.listener.protocollib.LoginSkinApplyL
import com.github.games647.fastlogin.bukkit.listener.protocollib.StartPacketListener;
import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener;
import com.github.games647.fastlogin.bukkit.tasks.DelayedAuthHook;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.google.common.collect.Sets;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import java.security.KeyPair;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentMap;
import java.util.logging.Level;
@ -38,18 +35,13 @@ public class FastLoginBukkit extends JavaPlugin {
private final KeyPair keyPair = EncryptionUtil.generateKeyPair();
private boolean bungeeCord;
private final FastLoginCore core = new BukkitCore(this);
private final BukkitCore core = new BukkitCore(this);
private boolean serverStarted;
private final Set<UUID> pendingConfirms = Sets.newHashSet();
//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 = BukkitCore.buildCache(1, -1);
//1 minutes should be enough as a timeout for bad internet connection (Server, Client and Mojang)
private final ConcurrentMap<String, BukkitLoginSession> session = FastLoginCore.buildCache(1, -1);
private BukkitAuthPlugin authPlugin;
private PasswordGenerator passwordGenerator = new DefaultPasswordGenerator();
@Override
public void onEnable() {
@ -58,8 +50,7 @@ public class FastLoginBukkit extends JavaPlugin {
List<String> ipAddresses = getConfig().getStringList("ip-addresses");
int requestLimit = getConfig().getInt("mojang-request-limit");
ConcurrentMap<Object, Object> requestCache = BukkitCore.buildCache(10, -1);
MojangApiBukkit mojangApi = new MojangApiBukkit(requestCache, getLogger(), ipAddresses, requestLimit);
MojangApiBukkit mojangApi = new MojangApiBukkit(getLogger(), ipAddresses, requestLimit);
core.setMojangApiConnector(mojangApi);
try {
@ -67,8 +58,7 @@ public class FastLoginBukkit extends JavaPlugin {
bungeeCord = Class.forName("org.spigotmc.SpigotConfig").getDeclaredField("bungee").getBoolean(null);
}
} catch (Exception | NoSuchMethodError ex) {
getLogger().warning("Cannot check bungeecord support. You use a non-spigot build");
ex.printStackTrace();
getLogger().log(Level.WARNING, "Cannot check bungeecord support. You use a non-spigot build", ex);
}
if (getServer().getOnlineMode()) {
@ -86,15 +76,7 @@ public class FastLoginBukkit extends JavaPlugin {
getServer().getMessenger().registerOutgoingPluginChannel(this, getName());
//register listeners on success
} else {
String driver = getConfig().getString("driver");
String host = getConfig().getString("host", "");
int port = getConfig().getInt("port", 3306);
String database = getConfig().getString("database");
String username = getConfig().getString("username", "");
String password = getConfig().getString("password", "");
if (!core.setupDatabase(driver, host, port, database, username, password)) {
if (!core.setupDatabase()) {
setEnabled(false);
return;
}
@ -143,16 +125,13 @@ public class FastLoginBukkit extends JavaPlugin {
}
}
public FastLoginCore getCore() {
public BukkitCore getCore() {
return core;
}
public String generateStringPassword(Player player) {
return passwordGenerator.getRandomPassword(player);
}
@Deprecated
public void setPasswordGenerator(PasswordGenerator passwordGenerator) {
this.passwordGenerator = passwordGenerator;
core.setPasswordGenerator(passwordGenerator);
}
/**
@ -210,10 +189,6 @@ public class FastLoginBukkit extends JavaPlugin {
return serverStarted;
}
public Set<UUID> getPendingConfirms() {
return pendingConfirms;
}
public void setServerStarted() {
if (!this.serverStarted) {
this.serverStarted = true;

View File

@ -1,14 +1,13 @@
package com.github.games647.fastlogin.bukkit;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.github.games647.fastlogin.core.MojangApiConnector;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.github.games647.fastlogin.core.shared.MojangApiConnector;
import java.io.BufferedReader;
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;
@ -21,9 +20,8 @@ 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(ConcurrentMap<Object, Object> requests, Logger logger, List<String> localAddresses
, int rateLimit) {
super(requests, logger, localAddresses, rateLimit);
public MojangApiBukkit(Logger logger, List<String> localAddresses, int rateLimit) {
super(logger, localAddresses, rateLimit);
}
@Override

View File

@ -4,10 +4,10 @@ import org.bukkit.entity.Player;
/**
*
* @deprecated please use com.github.games647.fastlogin.core.shared.PasswordGenerator<org.bukkit.entity.Player>
* @deprecated please use com.github.games647.fastlogin.core.hooks.PasswordGenerator<org.bukkit.entity.Player>
*/
@Deprecated
public interface PasswordGenerator {
public interface PasswordGenerator extends com.github.games647.fastlogin.core.hooks.PasswordGenerator<Player> {
String getRandomPassword(Player player);
}

View File

@ -2,7 +2,7 @@ package com.github.games647.fastlogin.bukkit.commands;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.AuthStorage;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.github.games647.fastlogin.core.importer.ImportPlugin;
import org.bukkit.ChatColor;

View File

@ -44,13 +44,14 @@ public class PremiumCommand implements CommandExecutor {
}
} else {
UUID id = ((Player) sender).getUniqueId();
if (plugin.getConfig().getBoolean("premium-warning") && !plugin.getPendingConfirms().contains(id)) {
if (plugin.getConfig().getBoolean("premium-warning")
&& !plugin.getCore().getPendingConfirms().contains(id)) {
sender.sendMessage(plugin.getCore().getMessage("premium-warning"));
plugin.getPendingConfirms().add(id);
plugin.getCore().getPendingConfirms().add(id);
return true;
}
plugin.getPendingConfirms().remove(id);
plugin.getCore().getPendingConfirms().remove(id);
//todo: load async
final PlayerProfile profile = plugin.getCore().getStorage().loadProfile(sender.getName());
if (profile.isPremium()) {

View File

@ -1,11 +1,11 @@
package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.core.AuthPlugin;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import org.bukkit.entity.Player;
/**
* @deprecated please use com.github.games647.fastlogin.core.AuthPlugin<org.bukkit.entity.Player>
* @deprecated please use com.github.games647.fastlogin.core.hooks.AuthPlugin<org.bukkit.entity.Player>
*/
@Deprecated
public interface BukkitAuthPlugin extends AuthPlugin<Player> {

View File

@ -48,6 +48,6 @@ public class BukkitJoinListener implements Listener {
public void onPlayerQuit(PlayerQuitEvent quitEvent) {
Player player = quitEvent.getPlayer();
player.removeMetadata(plugin.getName(), plugin);
plugin.getPendingConfirms().remove(player.getUniqueId());
plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
}
}

View File

@ -88,7 +88,7 @@ public class ForceLoginTask implements Runnable {
private boolean forceRegister(BukkitAuthPlugin authPlugin, Player player) {
plugin.getLogger().log(Level.FINE, "Register player {0}", player.getName());
String generatedPassword = plugin.generateStringPassword(player);
String generatedPassword = plugin.getCore().getPasswordGenerator().getRandomPassword(player);
boolean success = authPlugin.forceRegister(player, generatedPassword);
String message = plugin.getCore().getMessage("auto-register");
if (success && message != null) {

View File

@ -44,13 +44,6 @@
<version>1.8-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- <dependency>
<groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId>
<version>1.9-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>-->
<dependency>
<groupId>com.github.MatteCarra</groupId>

View File

@ -1,7 +1,6 @@
package com.github.games647.fastlogin.bungee;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.google.common.cache.CacheBuilder;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
@ -12,23 +11,22 @@ import java.nio.file.Files;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.scheduler.GroupedThreadFactory;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
public class BungeeCore extends FastLoginCore {
public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
private final FastLoginBungee plugin;
public BungeeCore(FastLoginBungee plugin) {
super(CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).<String, Object>build().asMap()
, generateConfigMap(plugin.getConfig()));
super(generateConfigMap(plugin.getConfig()));
this.plugin = plugin;
}

View File

@ -4,10 +4,6 @@ import com.github.games647.fastlogin.bungee.hooks.BungeeAuthHook;
import com.github.games647.fastlogin.bungee.hooks.BungeeAuthPlugin;
import com.github.games647.fastlogin.bungee.listener.PlayerConnectionListener;
import com.github.games647.fastlogin.bungee.listener.PluginMessageListener;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.github.games647.fastlogin.core.shared.DefaultPasswordGenerator;
import com.github.games647.fastlogin.core.shared.PasswordGenerator;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
@ -17,11 +13,9 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
@ -32,11 +26,10 @@ import net.md_5.bungee.config.YamlConfiguration;
*/
public class FastLoginBungee extends Plugin {
private final FastLoginCore loginCore = new BungeeCore(this);
private final BungeeCore loginCore = new BungeeCore(this);
private BungeeAuthPlugin bungeeAuthPlugin;
private Configuration config;
private final PasswordGenerator<ProxiedPlayer> passwordGenerator = new DefaultPasswordGenerator<>();
private final Set<UUID> pendingConfirms = Sets.newHashSet();
private final ConcurrentMap<PendingConnection, BungeeLoginSession> session = Maps.newConcurrentMap();
@ -52,19 +45,10 @@ public class FastLoginBungee extends Plugin {
List<String> ipAddresses = getConfig().getStringList("ip-addresses");
int requestLimit = getConfig().getInt("mojang-request-limit");
ConcurrentMap<Object, Object> requestCache = CacheBuilder.newBuilder()
.expireAfterWrite(10, TimeUnit.MINUTES).build().asMap();
MojangApiBungee mojangApi = new MojangApiBungee(requestCache, getLogger(), ipAddresses, requestLimit);
MojangApiBungee mojangApi = new MojangApiBungee(getLogger(), ipAddresses, requestLimit);
loginCore.setMojangApiConnector(mojangApi);
String driver = config.getString("driver");
String host = config.getString("host", "");
int port = config.getInt("port", 3306);
String database = config.getString("database");
String username = config.getString("username", "");
String password = config.getString("password", "");
if (!loginCore.setupDatabase(driver, host, port, database, username, password)) {
if (!loginCore.setupDatabase()) {
return;
}
} catch (IOException ioExc) {
@ -85,16 +69,12 @@ public class FastLoginBungee extends Plugin {
registerHook();
}
public String generatePassword(ProxiedPlayer player) {
return passwordGenerator.getRandomPassword(player);
}
@Override
public void onDisable() {
loginCore.close();
}
public FastLoginCore getCore() {
public BungeeCore getCore() {
return loginCore;
}
@ -110,10 +90,6 @@ public class FastLoginBungee extends Plugin {
return session;
}
public Set<UUID> getPendingConfirms() {
return pendingConfirms;
}
/**
* Get the auth plugin hook for BungeeCord
*

View File

@ -2,7 +2,7 @@ package com.github.games647.fastlogin.bungee;
import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.core.AuthStorage;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.github.games647.fastlogin.core.importer.ImportPlugin;
import net.md_5.bungee.api.ChatColor;

View File

@ -1,20 +1,18 @@
package com.github.games647.fastlogin.bungee;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.github.games647.fastlogin.core.MojangApiConnector;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.github.games647.fastlogin.core.shared.MojangApiConnector;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentMap;
import java.util.logging.Logger;
import net.md_5.bungee.BungeeCord;
public class MojangApiBungee extends MojangApiConnector {
public MojangApiBungee(ConcurrentMap<Object, Object> requests, Logger logger, List<String> localAddresses
, int rateLimit) {
super(requests, logger, localAddresses, rateLimit);
public MojangApiBungee(Logger logger, List<String> localAddresses, int rateLimit) {
super(logger, localAddresses, rateLimit);
}
@Override

View File

@ -1,10 +1,10 @@
package com.github.games647.fastlogin.bungee.hooks;
import com.github.games647.fastlogin.core.AuthPlugin;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import net.md_5.bungee.api.connection.ProxiedPlayer;
/**
* @deprecated please use com.github.games647.fastlogin.core.AuthPlugin<net.md_5.bungee.api.connection.ProxiedPlayer>
* @deprecated please use com.github.games647.fastlogin.core.hooks.AuthPlugin<net.md_5.bungee.api.connection.ProxiedPlayer>
*/
@Deprecated
public interface BungeeAuthPlugin extends AuthPlugin<ProxiedPlayer> {

View File

@ -103,6 +103,6 @@ public class PlayerConnectionListener implements Listener {
public void onDisconnect(PlayerDisconnectEvent disconnectEvent) {
ProxiedPlayer player = disconnectEvent.getPlayer();
plugin.getSession().remove(player.getPendingConnection());
plugin.getPendingConfirms().remove(player.getUniqueId());
plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
}
}

View File

@ -55,14 +55,14 @@ public class PluginMessageListener implements Listener {
String playerName = dataInput.readUTF();
if (playerName.equals(forPlayer.getName()) && plugin.getConfig().getBoolean("premium-warning")
&& !plugin.getPendingConfirms().contains(forPlayer.getUniqueId())) {
&& !plugin.getCore().getPendingConfirms().contains(forPlayer.getUniqueId())) {
String message = plugin.getCore().getMessage("premium-warning");
forPlayer.sendMessage(TextComponent.fromLegacyText(message));
plugin.getPendingConfirms().add(forPlayer.getUniqueId());
plugin.getCore().getPendingConfirms().add(forPlayer.getUniqueId());
return;
}
plugin.getPendingConfirms().remove(forPlayer.getUniqueId());
plugin.getCore().getPendingConfirms().remove(forPlayer.getUniqueId());
AsyncToggleMessage task = new AsyncToggleMessage(plugin, forPlayer, playerName, true);
ProxyServer.getInstance().getScheduler().runAsync(plugin, task);
} else if ("OFF".equals(subchannel)) {

View File

@ -81,7 +81,7 @@ public class ForceLoginTask implements Runnable {
session.setAlreadyLogged(true);
String password = plugin.generatePassword(player);
String password = plugin.getCore().getPasswordGenerator().getRandomPassword(player);
if (authPlugin.forceRegister(player, password)) {
//save will happen on success message from bukkit
sendBukkitLoginNotification(true);

View File

@ -28,5 +28,12 @@
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>10.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.core;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

View File

@ -1,4 +1,4 @@
package com.github.games647.fastlogin.bukkit;
package com.github.games647.fastlogin.core;
import java.lang.reflect.Method;
import java.util.concurrent.ConcurrentMap;
@ -10,14 +10,13 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.RemovalListener;
/**
* Represents a Guava CacheBuilder that is compatible with both Guava 10 and 13
* Represents a Guava CacheBuilder that is compatible with both Guava 10 (Minecraft 1.7.X) and 13
*/
public class CompatibleCacheBuilder<K, V> {
private static Method BUILD_METHOD;
private static Method AS_MAP_METHOD;
/**
* Construct a new safe cache builder.
*

View File

@ -1,4 +1,4 @@
package com.github.games647.fastlogin.core;
package com.github.games647.fastlogin.core.hooks;
/**
* Represents a supporting authentication plugin in BungeeCord and Bukkit/Spigot/... servers

View File

@ -1,4 +1,4 @@
package com.github.games647.fastlogin.core.shared;
package com.github.games647.fastlogin.core.hooks;
import java.util.Random;

View File

@ -1,4 +1,4 @@
package com.github.games647.fastlogin.core.shared;
package com.github.games647.fastlogin.core.hooks;
public interface PasswordGenerator<T> {

View File

@ -1,23 +1,51 @@
package com.github.games647.fastlogin.core;
package com.github.games647.fastlogin.core.shared;
import com.github.games647.fastlogin.core.AuthStorage;
import com.github.games647.fastlogin.core.CompatibleCacheBuilder;
import com.github.games647.fastlogin.core.SharedConfig;
import com.github.games647.fastlogin.core.hooks.DefaultPasswordGenerator;
import com.github.games647.fastlogin.core.hooks.PasswordGenerator;
import com.github.games647.fastlogin.core.importer.AutoInImporter;
import com.github.games647.fastlogin.core.importer.ImportPlugin;
import com.github.games647.fastlogin.core.importer.Importer;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.Sets;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class FastLoginCore {
public abstract class FastLoginCore<T> {
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(new CacheLoader<K, V>() {
@Override
public V load(K key) throws Exception {
throw new UnsupportedOperationException("Not supported yet.");
}
});
}
public static UUID parseId(String withoutDashes) {
if (withoutDashes == null) {
return null;
@ -33,13 +61,15 @@ public abstract class FastLoginCore {
protected final Map<String, String> localeMessages = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Object> pendingLogins;
private final Set<UUID> pendingConfirms = Sets.newHashSet();
private final SharedConfig sharedConfig;
private MojangApiConnector mojangApiConnector;
private PasswordGenerator<T> passwordGenerator = new DefaultPasswordGenerator<>();
private AuthStorage storage;
public FastLoginCore(ConcurrentMap<String, Object> pendingLogins, Map<String, Object> config) {
this.pendingLogins = pendingLogins;
public FastLoginCore(Map<String, Object> config) {
this.pendingLogins = FastLoginCore.buildCache(5, 0);
this.sharedConfig = new SharedConfig(config);
}
@ -69,7 +99,15 @@ public abstract class FastLoginCore {
public abstract void loadConfig();
public boolean setupDatabase(String driver, String host, int port, String database, String user, String password) {
public boolean setupDatabase() {
String driver = sharedConfig.get("driver");
String host = sharedConfig.get("host", "");
int port = sharedConfig.get("port", 3306);
String database = sharedConfig.get("database");
String user = sharedConfig.get("username", "");
String password = sharedConfig.get("password", "");
storage = new AuthStorage(this, driver, host, port, database, user, password);
try {
storage.createTables();
@ -124,10 +162,22 @@ public abstract class FastLoginCore {
return sharedConfig;
}
public PasswordGenerator<T> getPasswordGenerator() {
return passwordGenerator;
}
public void setPasswordGenerator(PasswordGenerator<T> passwordGenerator) {
this.passwordGenerator = passwordGenerator;
}
public ConcurrentMap<String, Object> getPendingLogins() {
return pendingLogins;
}
public Set<UUID> getPendingConfirms() {
return pendingConfirms;
}
public void close() {
if (storage != null) {
storage.close();

View File

@ -1,7 +1,6 @@
package com.github.games647.fastlogin.core.shared;
import com.github.games647.fastlogin.core.AuthPlugin;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import com.github.games647.fastlogin.core.PlayerProfile;
import com.github.games647.fastlogin.core.SharedConfig;
import java.util.UUID;

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.core;
package com.github.games647.fastlogin.core.shared;
import com.github.games647.fastlogin.core.BalancedSSLFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@ -36,17 +37,15 @@ public abstract class MojangApiConnector {
//compile the pattern only on plugin enable -> and this have to be threadsafe
private final Pattern playernameMatcher = Pattern.compile(VALID_PLAYERNAME);
private final ConcurrentMap<Object, Object> requests;
private final ConcurrentMap<Object, Object> requests = FastLoginCore.buildCache(10, -1);
private final BalancedSSLFactory sslFactory;
private final int rateLimit;
private long lastRateLimit;
protected final Logger logger;
public MojangApiConnector(ConcurrentMap<Object, Object> requests, Logger logger, List<String> localAddresses
, int rateLimit) {
public MojangApiConnector(Logger logger, List<String> localAddresses, int rateLimit) {
this.logger = logger;
this.requests = requests;
if (rateLimit > 600) {
this.rateLimit = 600;