diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index e9bf0e5a..6ab102b4 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -46,10 +46,11 @@ public class FastLoginBukkit extends JavaPlugin { @Override public void onEnable() { + saveDefaultConfig(); core = new BukkitCore(this); - core.loadConfig(); core.loadMessages(); + core.setApiConnector(); try { if (ClassUtil.isPresent("org.spigotmc.SpigotConfig")) { bungeeCord = Class.forName("org.spigotmc.SpigotConfig").getDeclaredField("bungee").getBoolean(null); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiBukkit.java index a0e35eb0..3207b677 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiBukkit.java @@ -77,7 +77,7 @@ public class MojangApiBukkit extends MojangApiConnector { } String uuid = (String) mojangPlayer.get("id"); - if (uuid == null || uuid.equals("null")) { + if ("null".equals(uuid)) { return null; } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/LoginSkinApplyListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/LoginSkinApplyListener.java index 311fcdd5..9c7f4c50 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/LoginSkinApplyListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/LoginSkinApplyListener.java @@ -1,5 +1,6 @@ package com.github.games647.fastlogin.bukkit.listener.protocollib; +import com.comphenix.protocol.reflect.MethodUtils; import com.comphenix.protocol.reflect.accessors.Accessors; import com.comphenix.protocol.reflect.accessors.MethodAccessor; import com.comphenix.protocol.utility.MinecraftReflection; @@ -9,7 +10,6 @@ import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.logging.Level; import org.bukkit.entity.Player; @@ -17,6 +17,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerLoginEvent.Result; public class LoginSkinApplyListener implements Listener { @@ -33,6 +34,10 @@ public class LoginSkinApplyListener implements Listener { @EventHandler(priority = EventPriority.LOW) //run this on the loginEvent to let skins plugins see the skin like in normal minecraft behaviour public void onPlayerLogin(PlayerLoginEvent loginEvent) { + if (loginEvent.getResult() != Result.ALLOWED) { + return; + } + Player player = loginEvent.getPlayer(); if (plugin.getConfig().getBoolean("forwardSkin")) { @@ -59,8 +64,7 @@ public class LoginSkinApplyListener implements Listener { } catch (ClassCastException castException) { Object map = GET_PROPERTIES.invoke(gameProfile.getHandle()); try { - Method putMethod = map.getClass().getMethod("put", Object.class, Object.class); - putMethod.invoke(map, "textures", skin.getHandle()); + MethodUtils.invokeMethod(map, "put", new Object[]{"textures", skin.getHandle()}); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { plugin.getLogger().log(Level.SEVERE, "Error setting premium skin", ex); } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibLoginSource.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibLoginSource.java index 1becc0c2..911cfbb2 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibLoginSource.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibLoginSource.java @@ -8,8 +8,8 @@ import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.core.shared.LoginSource; -import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.InvocationTargetException; import java.net.InetSocketAddress; import java.security.PublicKey; import java.util.Random; diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java index 297f1576..f108be2a 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java @@ -5,7 +5,9 @@ import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.injector.netty.Injector; import com.comphenix.protocol.injector.server.TemporaryPlayerFactory; +import com.comphenix.protocol.reflect.FieldUtils; import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedGameProfile; @@ -13,7 +15,6 @@ import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.EncryptionUtil; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; -import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigInteger; @@ -102,10 +103,9 @@ public class VerifyResponseTask implements Runnable { try { Object networkManager = getNetworkManager(); //https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/NetworkManager.java#L69 - Field spoofField = FuzzyReflection.fromObject(networkManager).getFieldByType("spoofedUUID", UUID.class); - spoofField.set(networkManager, premiumUUID); - } catch (ReflectiveOperationException reflectiveOperationException) { - plugin.getLogger().log(Level.SEVERE, "Error setting premium uuid", reflectiveOperationException); + FieldUtils.writeField(networkManager, "spoofedUUID", premiumUUID, true); + } catch (Exception exc) { + plugin.getLogger().log(Level.SEVERE, "Error setting premium uuid", exc); } } } @@ -129,15 +129,11 @@ public class VerifyResponseTask implements Runnable { //try to get the networkManager from ProtocolLib private Object getNetworkManager() throws IllegalAccessException, NoSuchFieldException { - Object socketInjector = TemporaryPlayerFactory.getInjectorFromPlayer(fromPlayer); - Field injectorField = socketInjector.getClass().getDeclaredField("injector"); - injectorField.setAccessible(true); + Object injectorContainer = TemporaryPlayerFactory.getInjectorFromPlayer(fromPlayer); - Object rawInjector = injectorField.get(socketInjector); - - injectorField = rawInjector.getClass().getDeclaredField("networkManager"); - injectorField.setAccessible(true); - return injectorField.get(rawInjector); + //ChannelInjector + Injector rawInjector = FuzzyReflection.getFieldValue(injectorContainer, Injector.class, true); + return FieldUtils.readField(rawInjector, "networkManager", true); } private boolean encryptConnection(SecretKey loginKey) throws IllegalArgumentException { @@ -146,12 +142,12 @@ public class VerifyResponseTask implements Runnable { Object networkManager = getNetworkManager(); //try to detect the method by parameters - Method encryptConnectionMethod = FuzzyReflection + Method encryptMethod = FuzzyReflection .fromObject(networkManager).getMethodByParameters("a", SecretKey.class); //encrypt/decrypt following packets //the client expects this behaviour - encryptConnectionMethod.invoke(networkManager, loginKey); + encryptMethod.invoke(networkManager, loginKey); } catch (Exception ex) { plugin.getLogger().log(Level.SEVERE, "Couldn't enable encryption", ex); disconnect(plugin.getCore().getMessage("error-kick"), false, "Couldn't enable encryption"); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java index 77bb2b71..6f55c6b2 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java @@ -24,7 +24,7 @@ public class ProtocolSupportListener extends JoinManagement { private static Map generateConfigMap(Configuration config) { - return config.getKeys().stream().collect(Collectors.toMap(key -> key, config::get)); + return config.getKeys().stream().filter(key -> config.get(key) != null) + .collect(Collectors.toMap(key -> key, config::get)); } private final FastLoginBungee plugin; diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java index 28b94678..ad40e2d1 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java @@ -35,7 +35,9 @@ public class FastLoginBungee extends Plugin { try { File configFile = new File(getDataFolder(), "config.yml"); - config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); + ConfigurationProvider provider = ConfigurationProvider.getProvider(YamlConfiguration.class); + Configuration defaults = provider.load(getResourceAsStream("config.yml")); + config = provider.load(configFile, defaults); core = new BungeeCore(this, config); if (!core.setupDatabase()) { @@ -47,6 +49,7 @@ public class FastLoginBungee extends Plugin { } core.loadConfig(); + core.setApiConnector(); core.loadMessages(); //events @@ -64,7 +67,9 @@ public class FastLoginBungee extends Plugin { @Override public void onDisable() { - core.close(); + if (core != null) { + core.close(); + } } public void saveDefaultFile(String fileName) { diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/MojangApiBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/MojangApiBungee.java index 40fd78a0..d8bce85f 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/MojangApiBungee.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/MojangApiBungee.java @@ -24,11 +24,12 @@ public class MojangApiBungee extends MojangApiConnector { mojangPlayer = BungeeCord.getInstance().gson.fromJson(json, MojangPlayer.class); } - if (mojangPlayer.getId() == null || mojangPlayer.getId().equals("null")) { + String id = mojangPlayer.getId(); + if ("null".equals(id)) { return null; } - return mojangPlayer.getId(); + return id; } @Override diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/hooks/BungeeAuthHook.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/hooks/BungeeAuthHook.java index 10e43b37..3b65223c 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/hooks/BungeeAuthHook.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/hooks/BungeeAuthHook.java @@ -29,26 +29,25 @@ public class BungeeAuthHook implements AuthPlugin { @Override public boolean forceLogin(ProxiedPlayer player) { + String playerName = player.getName(); //https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L92-95 - if (Main.plonline.contains(player.getName())) { - Main.plugin.getLogger().log(Level.INFO, "Cannot force login player {0}, because he/she is already online" - , player.getName()); + if (Main.plonline.contains(playerName)) { return true; } - Main.plonline.add(player.getName()); + Main.plonline.add(playerName); //renamed from ct to databaseConnection // databaseConnection.setStatus(player.getName(), "online"); Class[] parameterTypes = new Class[]{String.class, String.class}; - Object[] arguments = new Object[]{player.getName(), "online"}; + Object[] arguments = new Object[]{playerName, "online"}; try { callProtected("setStatus", parameterTypes, arguments); ListenerClass.movePlayer(player, false); //proparly not thread-safe - ListenerClass.prelogin.get(player.getName()).cancel(); + ListenerClass.prelogin.get(playerName).cancel(); } catch (Exception ex) { Main.plugin.getLogger().log(Level.SEVERE, "Error force loging in player", ex); return false; @@ -82,15 +81,12 @@ public class BungeeAuthHook implements AuthPlugin { String hash = ph.newHash(Pw, pType); //creates a new SQL entry with the player's details. - - //renamed t to databaseConnection -// databaseConnection.newPlayerEntry(player.getName(), hash, pType, "", lastip, regdate, lastip, lastseen); - Class[] parameterTypes = new Class[] {String.class, String.class, String.class, String.class , String.class, String.class, String.class, String.class}; Object[] arguments = new Object[] {player.getName(), hash, pType, "", lastip, regdate, lastip, lastseen}; try { + callProtected("newPlayerEntry", parameterTypes, arguments); //proparly not thread-safe forceLogin(player); @@ -108,6 +104,8 @@ public class BungeeAuthHook implements AuthPlugin { Method method = tableClass.getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); + //renamed t to databaseConnection + //databaseConnection.newPlayerEntry(player.getName(), hash, pType, "", lastip, regdate, lastip, lastseen); method.invoke(databaseConnection, arguments); } } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PlayerConnectionListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PlayerConnectionListener.java index c8ad3813..0976bc39 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PlayerConnectionListener.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PlayerConnectionListener.java @@ -3,8 +3,8 @@ package com.github.games647.fastlogin.bungee.listener; import com.github.games647.fastlogin.bungee.FastLoginBungee; import com.github.games647.fastlogin.bungee.tasks.AsyncPremiumCheck; import com.github.games647.fastlogin.bungee.tasks.ForceLoginTask; -import com.github.games647.fastlogin.core.shared.LoginSession; import com.github.games647.fastlogin.core.PlayerProfile; +import com.github.games647.fastlogin.core.shared.LoginSession; import com.google.common.base.Charsets; import java.lang.reflect.Field; diff --git a/core/pom.xml b/core/pom.xml index 0cb95aa3..9f26bd6e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -19,7 +19,7 @@ com.zaxxer HikariCP - 2.4.7 + 2.5.0 @@ -32,7 +32,7 @@ com.google.guava guava - 10.0 + 10.0.1 provided diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java index 0f0c0c40..7283493c 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java @@ -66,8 +66,7 @@ public abstract class FastLoginCore

{ private final Set pendingConfirms = Sets.newHashSet(); private final SharedConfig sharedConfig; - private final MojangApiConnector apiConnector; - + private MojangApiConnector apiConnector; private AuthStorage storage; private PasswordGenerator

passwordGenerator = new DefaultPasswordGenerator<>(); private AuthPlugin

authPlugin; @@ -75,7 +74,9 @@ public abstract class FastLoginCore

{ public FastLoginCore(Map config) { this.pendingLogins = FastLoginCore.buildCache(5, 0); this.sharedConfig = new SharedConfig(config); - + } + + public void setApiConnector() { List ipAddresses = sharedConfig.get("ip-addresses"); int requestLimit = sharedConfig.get("mojang-request-limit"); this.apiConnector = makeApiConnector(getLogger(), ipAddresses, requestLimit); diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java index 2f1c233f..2011ee47 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java @@ -1,8 +1,9 @@ package com.github.games647.fastlogin.core.shared; -import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.PlayerProfile; import com.github.games647.fastlogin.core.SharedConfig; +import com.github.games647.fastlogin.core.hooks.AuthPlugin; + import java.util.UUID; import java.util.logging.Level; diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/MojangApiConnector.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/MojangApiConnector.java index d31d7c24..c4d3c0b8 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/MojangApiConnector.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/MojangApiConnector.java @@ -7,6 +7,7 @@ import com.google.common.io.CharStreams; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.Reader; import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.URL; @@ -126,9 +127,9 @@ public abstract class MojangApiConnector { return null; } - BufferedReader reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream())); - String input = CharStreams.toString(reader); - return FastLoginCore.parseId(getUUIDFromJson(input)); + Reader reader = new InputStreamReader(httpConnection.getInputStream()); + String json = CharStreams.toString(reader); + return FastLoginCore.parseId(getUUIDFromJson(json)); } catch (IOException iOException) { logger.log(Level.SEVERE, "Tried converting name->uuid from third-party api", iOException); }