Fix loading with unloaded configuration values

This commit is contained in:
games647
2016-09-15 10:33:17 +02:00
parent 218bc50c96
commit 07d0aededa
13 changed files with 58 additions and 35 deletions

View File

@ -1,5 +1,6 @@
######1.9 ######1.9
* Drop support for LoginSecurity 1.X since 2.X seems to be stable
* Refactored/Cleaned up a lot of code * Refactored/Cleaned up a lot of code
* [API] Deprecated platform specific authplugin. Please use AuthPlugin< platform specific player type > * [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 > * [API] Deprecated bukkit's password generator. Please use PasswordGenerator< platform specific player type >

View File

@ -14,6 +14,7 @@ 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.protocollib.StartPacketListener;
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.hooks.AuthPlugin;
import com.github.games647.fastlogin.core.shared.FastLoginCore; import com.github.games647.fastlogin.core.shared.FastLoginCore;
import java.security.KeyPair; import java.security.KeyPair;
@ -35,16 +36,16 @@ public class FastLoginBukkit extends JavaPlugin {
private final KeyPair keyPair = EncryptionUtil.generateKeyPair(); private final KeyPair keyPair = EncryptionUtil.generateKeyPair();
private boolean bungeeCord; private boolean bungeeCord;
private final BukkitCore core = new BukkitCore(this); private BukkitCore core;
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> session = FastLoginCore.buildCache(1, -1); private final ConcurrentMap<String, BukkitLoginSession> session = FastLoginCore.buildCache(1, -1);
private BukkitAuthPlugin authPlugin;
@Override @Override
public void onEnable() { public void onEnable() {
core = new BukkitCore(this);
core.loadConfig(); core.loadConfig();
core.loadMessages(); core.loadMessages();
@ -112,7 +113,6 @@ public class FastLoginBukkit extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
//clean up
session.clear(); session.clear();
if (core != null) { if (core != null) {
@ -160,6 +160,7 @@ public class FastLoginBukkit extends JavaPlugin {
* @return interface to any supported auth plugin * @return interface to any supported auth plugin
*/ */
public BukkitAuthPlugin getAuthPlugin() { public BukkitAuthPlugin getAuthPlugin() {
AuthPlugin<Player> authPlugin = core.getAuthPlugin();
if (authPlugin == null) { if (authPlugin == null) {
try { try {
Thread.sleep(1000); Thread.sleep(1000);
@ -168,11 +169,11 @@ public class FastLoginBukkit extends JavaPlugin {
} }
} }
return authPlugin; return (BukkitAuthPlugin) authPlugin;
} }
public void setAuthPluginHook(BukkitAuthPlugin authPlugin) { public void setAuthPluginHook(BukkitAuthPlugin authPlugin) {
this.authPlugin = authPlugin; core.setAuthPlugin(authPlugin);
} }
public boolean isBungeeCord() { public boolean isBungeeCord() {

View File

@ -1,6 +1,7 @@
package com.github.games647.fastlogin.bukkit.hooks; package com.github.games647.fastlogin.bukkit.hooks;
import com.avaje.ebeaninternal.api.ClassUtil; import com.avaje.ebeaninternal.api.ClassUtil;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import fr.xephi.authme.api.API; import fr.xephi.authme.api.API;
import fr.xephi.authme.api.NewAPI; import fr.xephi.authme.api.NewAPI;
@ -14,7 +15,7 @@ import org.bukkit.entity.Player;
* Bukkit: http://dev.bukkit.org/bukkit-plugins/authme-reloaded/ * Bukkit: http://dev.bukkit.org/bukkit-plugins/authme-reloaded/
* Spigot: https://www.spigotmc.org/resources/authme-reloaded.6269/ * Spigot: https://www.spigotmc.org/resources/authme-reloaded.6269/
*/ */
public class AuthMeHook implements BukkitAuthPlugin { public class AuthMeHook implements AuthPlugin<Player> {
private final boolean isNewAPIAvailable; private final boolean isNewAPIAvailable;

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bukkit.hooks; package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import de.st_ddt.crazylogin.CrazyLogin; import de.st_ddt.crazylogin.CrazyLogin;
import de.st_ddt.crazylogin.data.LoginPlayerData; import de.st_ddt.crazylogin.data.LoginPlayerData;
@ -23,7 +24,7 @@ import org.bukkit.entity.Player;
* *
* Bukkit: http://dev.bukkit.org/server-mods/crazylogin/ * Bukkit: http://dev.bukkit.org/server-mods/crazylogin/
*/ */
public class CrazyLoginHook implements BukkitAuthPlugin { public class CrazyLoginHook implements AuthPlugin<Player> {
protected final CrazyLogin crazyLoginPlugin = CrazyLogin.getPlugin(); protected final CrazyLogin crazyLoginPlugin = CrazyLogin.getPlugin();
private final PlayerListener playerListener = getListener(); private final PlayerListener playerListener = getListener();

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bukkit.hooks; package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import io.github.lucaseasedup.logit.CancelledState; import io.github.lucaseasedup.logit.CancelledState;
import io.github.lucaseasedup.logit.LogItCore; import io.github.lucaseasedup.logit.LogItCore;
@ -14,7 +15,7 @@ import org.bukkit.entity.Player;
* Bukkit: Unknown * Bukkit: Unknown
* Spigot: Unknown * Spigot: Unknown
*/ */
public class LogItHook implements BukkitAuthPlugin { public class LogItHook implements AuthPlugin<Player> {
@Override @Override
public boolean forceLogin(Player player) { public boolean forceLogin(Player player) {

View File

@ -1,6 +1,7 @@
package com.github.games647.fastlogin.bukkit.hooks; package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import com.lenis0012.bukkit.loginsecurity.LoginSecurity; import com.lenis0012.bukkit.loginsecurity.LoginSecurity;
import com.lenis0012.bukkit.loginsecurity.session.AuthService; import com.lenis0012.bukkit.loginsecurity.session.AuthService;
import com.lenis0012.bukkit.loginsecurity.session.PlayerSession; import com.lenis0012.bukkit.loginsecurity.session.PlayerSession;
@ -16,7 +17,7 @@ import org.bukkit.entity.Player;
* Bukkit: http://dev.bukkit.org/bukkit-plugins/loginsecurity/ * Bukkit: http://dev.bukkit.org/bukkit-plugins/loginsecurity/
* Spigot: https://www.spigotmc.org/resources/loginsecurity.19362/ * Spigot: https://www.spigotmc.org/resources/loginsecurity.19362/
*/ */
public class LoginSecurityHook implements BukkitAuthPlugin { public class LoginSecurityHook implements AuthPlugin<Player> {
private final FastLoginBukkit plugin = (FastLoginBukkit) Bukkit.getPluginManager().getPlugin("FastLogin"); private final FastLoginBukkit plugin = (FastLoginBukkit) Bukkit.getPluginManager().getPlugin("FastLogin");

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bukkit.hooks; package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -19,7 +20,7 @@ import org.royaldev.royalauth.RoyalAuth;
* *
* Bukkit: http://dev.bukkit.org/bukkit-plugins/royalauth/ * Bukkit: http://dev.bukkit.org/bukkit-plugins/royalauth/
*/ */
public class RoyalAuthHook implements BukkitAuthPlugin { public class RoyalAuthHook implements AuthPlugin<Player> {
private final RoyalAuth royalAuthPlugin = (RoyalAuth) Bukkit.getPluginManager().getPlugin("RoyalAuth"); private final RoyalAuth royalAuthPlugin = (RoyalAuth) Bukkit.getPluginManager().getPlugin("RoyalAuth");

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bukkit.hooks; package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -20,7 +21,7 @@ import ultraauth.managers.PlayerManager;
* Bukkit: http://dev.bukkit.org/bukkit-plugins/ultraauth-aa/ * Bukkit: http://dev.bukkit.org/bukkit-plugins/ultraauth-aa/
* Spigot: https://www.spigotmc.org/resources/ultraauth.17044/ * Spigot: https://www.spigotmc.org/resources/ultraauth.17044/
*/ */
public class UltraAuthHook implements BukkitAuthPlugin { public class UltraAuthHook implements AuthPlugin<Player> {
protected final Plugin ultraAuthPlugin = Main.main; protected final Plugin ultraAuthPlugin = Main.main;

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bukkit.hooks; package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import de.luricos.bukkit.xAuth.xAuth; import de.luricos.bukkit.xAuth.xAuth;
import de.luricos.bukkit.xAuth.xAuthPlayer; import de.luricos.bukkit.xAuth.xAuthPlayer;
@ -20,7 +21,7 @@ import org.bukkit.entity.Player;
* *
* Bukkit: http://dev.bukkit.org/bukkit-plugins/xauth/ * Bukkit: http://dev.bukkit.org/bukkit-plugins/xauth/
*/ */
public class xAuthHook implements BukkitAuthPlugin { public class xAuthHook implements AuthPlugin<Player> {
protected final xAuth xAuthPlugin = xAuth.getPlugin(); protected final xAuth xAuthPlugin = xAuth.getPlugin();

View File

@ -2,18 +2,19 @@ package com.github.games647.fastlogin.bukkit.tasks;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.hooks.AuthMeHook; import com.github.games647.fastlogin.bukkit.hooks.AuthMeHook;
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
import com.github.games647.fastlogin.bukkit.hooks.CrazyLoginHook; import com.github.games647.fastlogin.bukkit.hooks.CrazyLoginHook;
import com.github.games647.fastlogin.bukkit.hooks.LogItHook; import com.github.games647.fastlogin.bukkit.hooks.LogItHook;
import com.github.games647.fastlogin.bukkit.hooks.LoginSecurityHook; import com.github.games647.fastlogin.bukkit.hooks.LoginSecurityHook;
import com.github.games647.fastlogin.bukkit.hooks.UltraAuthHook; import com.github.games647.fastlogin.bukkit.hooks.UltraAuthHook;
import com.github.games647.fastlogin.bukkit.hooks.xAuthHook; import com.github.games647.fastlogin.bukkit.hooks.xAuthHook;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.List; import java.util.ArrayList;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class DelayedAuthHook implements Runnable { public class DelayedAuthHook implements Runnable {
@ -37,12 +38,12 @@ public class DelayedAuthHook implements Runnable {
} }
private boolean registerHooks() { private boolean registerHooks() {
BukkitAuthPlugin authPluginHook = null; AuthPlugin<Player> authPluginHook = null;
try { try {
List<Class<? extends BukkitAuthPlugin>> supportedHooks = Lists.newArrayList(AuthMeHook.class ArrayList<Class<? extends AuthPlugin<Player>>> supportedHooks = Lists.newArrayList(AuthMeHook.class
, CrazyLoginHook.class, LogItHook.class, LoginSecurityHook.class, UltraAuthHook.class , CrazyLoginHook.class, LogItHook.class, LoginSecurityHook.class, UltraAuthHook.class
, xAuthHook.class); , xAuthHook.class);
for (Class<? extends BukkitAuthPlugin> clazz : supportedHooks) { for (Class<? extends AuthPlugin<Player>> clazz : supportedHooks) {
String pluginName = clazz.getSimpleName().replace("Hook", ""); String pluginName = clazz.getSimpleName().replace("Hook", "");
//uses only member classes which uses AuthPlugin interface (skip interfaces) //uses only member classes which uses AuthPlugin interface (skip interfaces)
if (Bukkit.getServer().getPluginManager().getPlugin(pluginName) != null) { if (Bukkit.getServer().getPluginManager().getPlugin(pluginName) != null) {
@ -63,7 +64,7 @@ public class DelayedAuthHook implements Runnable {
} }
if (plugin.getAuthPlugin() == null) { if (plugin.getAuthPlugin() == null) {
plugin.setAuthPluginHook(authPluginHook); plugin.getCore().setAuthPlugin(authPluginHook);
} }
return true; return true;

View File

@ -23,27 +23,25 @@ import net.md_5.bungee.config.YamlConfiguration;
*/ */
public class FastLoginBungee extends Plugin { public class FastLoginBungee extends Plugin {
private final BungeeCore loginCore = new BungeeCore(this);
private BungeeAuthPlugin bungeeAuthPlugin;
private Configuration config;
private final ConcurrentMap<PendingConnection, BungeeLoginSession> session = Maps.newConcurrentMap(); private final ConcurrentMap<PendingConnection, BungeeLoginSession> session = Maps.newConcurrentMap();
private BungeeCore core;
private Configuration config;
@Override @Override
public void onEnable() { public void onEnable() {
loginCore.loadConfig();
loginCore.loadMessages();
try { try {
File configFile = new File(getDataFolder(), "config.yml"); File configFile = new File(getDataFolder(), "config.yml");
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
core = new BungeeCore(this);
List<String> ipAddresses = getConfig().getStringList("ip-addresses"); List<String> ipAddresses = getConfig().getStringList("ip-addresses");
int requestLimit = getConfig().getInt("mojang-request-limit"); int requestLimit = getConfig().getInt("mojang-request-limit");
MojangApiBungee mojangApi = new MojangApiBungee(getLogger(), ipAddresses, requestLimit); MojangApiBungee mojangApi = new MojangApiBungee(getLogger(), ipAddresses, requestLimit);
loginCore.setMojangApiConnector(mojangApi); core.setMojangApiConnector(mojangApi);
if (!loginCore.setupDatabase()) { if (!core.setupDatabase()) {
return; return;
} }
} catch (IOException ioExc) { } catch (IOException ioExc) {
@ -51,6 +49,9 @@ public class FastLoginBungee extends Plugin {
return; return;
} }
core.loadConfig();
core.loadMessages();
//events //events
getProxy().getPluginManager().registerListener(this, new PlayerConnectionListener(this)); getProxy().getPluginManager().registerListener(this, new PlayerConnectionListener(this));
getProxy().getPluginManager().registerListener(this, new PluginMessageListener(this)); getProxy().getPluginManager().registerListener(this, new PluginMessageListener(this));
@ -66,15 +67,15 @@ public class FastLoginBungee extends Plugin {
@Override @Override
public void onDisable() { public void onDisable() {
loginCore.close(); core.close();
} }
public BungeeCore getCore() { public BungeeCore getCore() {
return loginCore; return core;
} }
public void setAuthPluginHook(BungeeAuthPlugin authPlugin) { public void setAuthPluginHook(BungeeAuthPlugin authPlugin) {
this.bungeeAuthPlugin = authPlugin; core.setAuthPlugin(authPlugin);
} }
public Configuration getConfig() { public Configuration getConfig() {
@ -91,13 +92,13 @@ public class FastLoginBungee extends Plugin {
* @return the auth hook for BungeeCord. null if none found * @return the auth hook for BungeeCord. null if none found
*/ */
public BungeeAuthPlugin getBungeeAuthPlugin() { public BungeeAuthPlugin getBungeeAuthPlugin() {
return bungeeAuthPlugin; return (BungeeAuthPlugin) core.getAuthPlugin();
} }
private void registerHook() { private void registerHook() {
Plugin plugin = getProxy().getPluginManager().getPlugin("BungeeAuth"); Plugin plugin = getProxy().getPluginManager().getPlugin("BungeeAuth");
if (plugin != null) { if (plugin != null) {
bungeeAuthPlugin = new BungeeAuthHook(); core.setAuthPlugin(new BungeeAuthHook());
getLogger().info("Hooked into BungeeAuth"); getLogger().info("Hooked into BungeeAuth");
} }
} }

View File

@ -1,5 +1,7 @@
package com.github.games647.fastlogin.bungee.hooks; package com.github.games647.fastlogin.bungee.hooks;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
@ -20,7 +22,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
* *
* Spigot: https://www.spigotmc.org/resources/bungeeauth.493/ * Spigot: https://www.spigotmc.org/resources/bungeeauth.493/
*/ */
public class BungeeAuthHook implements BungeeAuthPlugin { public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L32 //https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L32
private final Tables databaseConnection = new Tables(); private final Tables databaseConnection = new Tables();

View File

@ -3,6 +3,7 @@ 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.CompatibleCacheBuilder;
import com.github.games647.fastlogin.core.SharedConfig; import com.github.games647.fastlogin.core.SharedConfig;
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.importer.AutoInImporter; import com.github.games647.fastlogin.core.importer.AutoInImporter;
@ -65,8 +66,9 @@ public abstract class FastLoginCore<T> {
private final SharedConfig sharedConfig; private final SharedConfig sharedConfig;
private MojangApiConnector mojangApiConnector; private MojangApiConnector mojangApiConnector;
private PasswordGenerator<T> passwordGenerator = new DefaultPasswordGenerator<>();
private AuthStorage storage; private AuthStorage storage;
private PasswordGenerator<T> passwordGenerator = new DefaultPasswordGenerator<>();
private AuthPlugin<T> authPlugin;
public FastLoginCore(Map<String, Object> config) { public FastLoginCore(Map<String, Object> config) {
this.pendingLogins = FastLoginCore.buildCache(5, 0); this.pendingLogins = FastLoginCore.buildCache(5, 0);
@ -178,6 +180,14 @@ public abstract class FastLoginCore<T> {
return pendingConfirms; return pendingConfirms;
} }
public AuthPlugin<T> getAuthPlugin() {
return authPlugin;
}
public void setAuthPlugin(AuthPlugin<T> authPlugin) {
this.authPlugin = authPlugin;
}
public void close() { public void close() {
if (storage != null) { if (storage != null) {
storage.close(); storage.close();