Fix loading of settings

This commit is contained in:
games647
2016-09-19 17:59:45 +02:00
parent acab4766b1
commit da266c7e91
15 changed files with 57 additions and 48 deletions

View File

@ -46,10 +46,11 @@ public class FastLoginBukkit extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
saveDefaultConfig();
core = new BukkitCore(this); core = new BukkitCore(this);
core.loadConfig();
core.loadMessages(); core.loadMessages();
core.setApiConnector();
try { try {
if (ClassUtil.isPresent("org.spigotmc.SpigotConfig")) { if (ClassUtil.isPresent("org.spigotmc.SpigotConfig")) {
bungeeCord = Class.forName("org.spigotmc.SpigotConfig").getDeclaredField("bungee").getBoolean(null); bungeeCord = Class.forName("org.spigotmc.SpigotConfig").getDeclaredField("bungee").getBoolean(null);

View File

@ -77,7 +77,7 @@ public class MojangApiBukkit extends MojangApiConnector {
} }
String uuid = (String) mojangPlayer.get("id"); String uuid = (String) mojangPlayer.get("id");
if (uuid == null || uuid.equals("null")) { if ("null".equals(uuid)) {
return null; return null;
} }

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bukkit.listener.protocollib; 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.Accessors;
import com.comphenix.protocol.reflect.accessors.MethodAccessor; import com.comphenix.protocol.reflect.accessors.MethodAccessor;
import com.comphenix.protocol.utility.MinecraftReflection; 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 com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -17,6 +17,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
public class LoginSkinApplyListener implements Listener { public class LoginSkinApplyListener implements Listener {
@ -33,6 +34,10 @@ public class LoginSkinApplyListener implements Listener {
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
//run this on the loginEvent to let skins plugins see the skin like in normal minecraft behaviour //run this on the loginEvent to let skins plugins see the skin like in normal minecraft behaviour
public void onPlayerLogin(PlayerLoginEvent loginEvent) { public void onPlayerLogin(PlayerLoginEvent loginEvent) {
if (loginEvent.getResult() != Result.ALLOWED) {
return;
}
Player player = loginEvent.getPlayer(); Player player = loginEvent.getPlayer();
if (plugin.getConfig().getBoolean("forwardSkin")) { if (plugin.getConfig().getBoolean("forwardSkin")) {
@ -59,8 +64,7 @@ public class LoginSkinApplyListener implements Listener {
} catch (ClassCastException castException) { } catch (ClassCastException castException) {
Object map = GET_PROPERTIES.invoke(gameProfile.getHandle()); Object map = GET_PROPERTIES.invoke(gameProfile.getHandle());
try { try {
Method putMethod = map.getClass().getMethod("put", Object.class, Object.class); MethodUtils.invokeMethod(map, "put", new Object[]{"textures", skin.getHandle()});
putMethod.invoke(map, "textures", skin.getHandle());
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
plugin.getLogger().log(Level.SEVERE, "Error setting premium skin", ex); plugin.getLogger().log(Level.SEVERE, "Error setting premium skin", ex);
} }

View File

@ -8,8 +8,8 @@ import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.shared.LoginSource; import com.github.games647.fastlogin.core.shared.LoginSource;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.security.PublicKey; import java.security.PublicKey;
import java.util.Random; import java.util.Random;

View File

@ -5,7 +5,9 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.netty.Injector;
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory; import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
import com.comphenix.protocol.reflect.FieldUtils;
import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile; 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.EncryptionUtil;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.math.BigInteger; import java.math.BigInteger;
@ -102,10 +103,9 @@ public class VerifyResponseTask implements Runnable {
try { try {
Object networkManager = getNetworkManager(); Object networkManager = getNetworkManager();
//https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/NetworkManager.java#L69 //https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/NetworkManager.java#L69
Field spoofField = FuzzyReflection.fromObject(networkManager).getFieldByType("spoofedUUID", UUID.class); FieldUtils.writeField(networkManager, "spoofedUUID", premiumUUID, true);
spoofField.set(networkManager, premiumUUID); } catch (Exception exc) {
} catch (ReflectiveOperationException reflectiveOperationException) { plugin.getLogger().log(Level.SEVERE, "Error setting premium uuid", exc);
plugin.getLogger().log(Level.SEVERE, "Error setting premium uuid", reflectiveOperationException);
} }
} }
} }
@ -129,15 +129,11 @@ public class VerifyResponseTask implements Runnable {
//try to get the networkManager from ProtocolLib //try to get the networkManager from ProtocolLib
private Object getNetworkManager() throws IllegalAccessException, NoSuchFieldException { private Object getNetworkManager() throws IllegalAccessException, NoSuchFieldException {
Object socketInjector = TemporaryPlayerFactory.getInjectorFromPlayer(fromPlayer); Object injectorContainer = TemporaryPlayerFactory.getInjectorFromPlayer(fromPlayer);
Field injectorField = socketInjector.getClass().getDeclaredField("injector");
injectorField.setAccessible(true);
Object rawInjector = injectorField.get(socketInjector); //ChannelInjector
Injector rawInjector = FuzzyReflection.getFieldValue(injectorContainer, Injector.class, true);
injectorField = rawInjector.getClass().getDeclaredField("networkManager"); return FieldUtils.readField(rawInjector, "networkManager", true);
injectorField.setAccessible(true);
return injectorField.get(rawInjector);
} }
private boolean encryptConnection(SecretKey loginKey) throws IllegalArgumentException { private boolean encryptConnection(SecretKey loginKey) throws IllegalArgumentException {
@ -146,12 +142,12 @@ public class VerifyResponseTask implements Runnable {
Object networkManager = getNetworkManager(); Object networkManager = getNetworkManager();
//try to detect the method by parameters //try to detect the method by parameters
Method encryptConnectionMethod = FuzzyReflection Method encryptMethod = FuzzyReflection
.fromObject(networkManager).getMethodByParameters("a", SecretKey.class); .fromObject(networkManager).getMethodByParameters("a", SecretKey.class);
//encrypt/decrypt following packets //encrypt/decrypt following packets
//the client expects this behaviour //the client expects this behaviour
encryptConnectionMethod.invoke(networkManager, loginKey); encryptMethod.invoke(networkManager, loginKey);
} catch (Exception ex) { } catch (Exception ex) {
plugin.getLogger().log(Level.SEVERE, "Couldn't enable encryption", ex); plugin.getLogger().log(Level.SEVERE, "Couldn't enable encryption", ex);
disconnect(plugin.getCore().getMessage("error-kick"), false, "Couldn't enable encryption"); disconnect(plugin.getCore().getMessage("error-kick"), false, "Couldn't enable encryption");

View File

@ -24,7 +24,7 @@ public class ProtocolSupportListener extends JoinManagement<Player, ProtocolLogi
this.plugin = plugin; this.plugin = plugin;
} }
@EventHandler(ignoreCancelled = true) @EventHandler
public void onLoginStart(PlayerLoginStartEvent loginStartEvent) { public void onLoginStart(PlayerLoginStartEvent loginStartEvent) {
plugin.setServerStarted(); plugin.setServerStarted();
if (loginStartEvent.isLoginDenied() || plugin.getCore().getAuthPluginHook() == null) { if (loginStartEvent.isLoginDenied() || plugin.getCore().getAuthPluginHook() == null) {
@ -40,7 +40,7 @@ public class ProtocolSupportListener extends JoinManagement<Player, ProtocolLogi
super.onLogin(username, new ProtocolLoginSource(loginStartEvent)); super.onLogin(username, new ProtocolLoginSource(loginStartEvent));
} }
@EventHandler(ignoreCancelled = true) @EventHandler
public void onPropertiesResolve(PlayerPropertiesResolveEvent propertiesResolveEvent) { public void onPropertiesResolve(PlayerPropertiesResolveEvent propertiesResolveEvent) {
InetSocketAddress address = propertiesResolveEvent.getAddress(); InetSocketAddress address = propertiesResolveEvent.getAddress();
BukkitLoginSession session = plugin.getSessions().get(address.toString()); BukkitLoginSession session = plugin.getSessions().get(address.toString());

View File

@ -23,7 +23,8 @@ import net.md_5.bungee.config.YamlConfiguration;
public class BungeeCore extends FastLoginCore<ProxiedPlayer> { public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
private static Map<String, Object> generateConfigMap(Configuration config) { private static Map<String, Object> 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; private final FastLoginBungee plugin;

View File

@ -35,7 +35,9 @@ public class FastLoginBungee extends Plugin {
try { try {
File configFile = new File(getDataFolder(), "config.yml"); 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); core = new BungeeCore(this, config);
if (!core.setupDatabase()) { if (!core.setupDatabase()) {
@ -47,6 +49,7 @@ public class FastLoginBungee extends Plugin {
} }
core.loadConfig(); core.loadConfig();
core.setApiConnector();
core.loadMessages(); core.loadMessages();
//events //events
@ -64,7 +67,9 @@ public class FastLoginBungee extends Plugin {
@Override @Override
public void onDisable() { public void onDisable() {
core.close(); if (core != null) {
core.close();
}
} }
public void saveDefaultFile(String fileName) { public void saveDefaultFile(String fileName) {

View File

@ -24,11 +24,12 @@ public class MojangApiBungee extends MojangApiConnector {
mojangPlayer = BungeeCord.getInstance().gson.fromJson(json, MojangPlayer.class); 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 null;
} }
return mojangPlayer.getId(); return id;
} }
@Override @Override

View File

@ -29,26 +29,25 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
@Override @Override
public boolean forceLogin(ProxiedPlayer player) { public boolean forceLogin(ProxiedPlayer player) {
String playerName = player.getName();
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L92-95 //https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L92-95
if (Main.plonline.contains(player.getName())) { if (Main.plonline.contains(playerName)) {
Main.plugin.getLogger().log(Level.INFO, "Cannot force login player {0}, because he/she is already online"
, player.getName());
return true; return true;
} }
Main.plonline.add(player.getName()); Main.plonline.add(playerName);
//renamed from ct to databaseConnection //renamed from ct to databaseConnection
// databaseConnection.setStatus(player.getName(), "online"); // databaseConnection.setStatus(player.getName(), "online");
Class<?>[] parameterTypes = new Class<?>[]{String.class, String.class}; Class<?>[] parameterTypes = new Class<?>[]{String.class, String.class};
Object[] arguments = new Object[]{player.getName(), "online"}; Object[] arguments = new Object[]{playerName, "online"};
try { try {
callProtected("setStatus", parameterTypes, arguments); callProtected("setStatus", parameterTypes, arguments);
ListenerClass.movePlayer(player, false); ListenerClass.movePlayer(player, false);
//proparly not thread-safe //proparly not thread-safe
ListenerClass.prelogin.get(player.getName()).cancel(); ListenerClass.prelogin.get(playerName).cancel();
} catch (Exception ex) { } catch (Exception ex) {
Main.plugin.getLogger().log(Level.SEVERE, "Error force loging in player", ex); Main.plugin.getLogger().log(Level.SEVERE, "Error force loging in player", ex);
return false; return false;
@ -82,15 +81,12 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
String hash = ph.newHash(Pw, pType); String hash = ph.newHash(Pw, pType);
//creates a new SQL entry with the player's details. //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 Class<?>[] parameterTypes = new Class<?>[] {String.class, String.class, String.class, String.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}; Object[] arguments = new Object[] {player.getName(), hash, pType, "", lastip, regdate, lastip, lastseen};
try { try {
callProtected("newPlayerEntry", parameterTypes, arguments); callProtected("newPlayerEntry", parameterTypes, arguments);
//proparly not thread-safe //proparly not thread-safe
forceLogin(player); forceLogin(player);
@ -108,6 +104,8 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
Method method = tableClass.getDeclaredMethod(methodName, parameterTypes); Method method = tableClass.getDeclaredMethod(methodName, parameterTypes);
method.setAccessible(true); method.setAccessible(true);
//renamed t to databaseConnection
//databaseConnection.newPlayerEntry(player.getName(), hash, pType, "", lastip, regdate, lastip, lastseen);
method.invoke(databaseConnection, arguments); method.invoke(databaseConnection, arguments);
} }
} }

View File

@ -3,8 +3,8 @@ package com.github.games647.fastlogin.bungee.listener;
import com.github.games647.fastlogin.bungee.FastLoginBungee; import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.bungee.tasks.AsyncPremiumCheck; import com.github.games647.fastlogin.bungee.tasks.AsyncPremiumCheck;
import com.github.games647.fastlogin.bungee.tasks.ForceLoginTask; 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.PlayerProfile;
import com.github.games647.fastlogin.core.shared.LoginSession;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import java.lang.reflect.Field; import java.lang.reflect.Field;

View File

@ -19,7 +19,7 @@
<dependency> <dependency>
<groupId>com.zaxxer</groupId> <groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId> <artifactId>HikariCP</artifactId>
<version>2.4.7</version> <version>2.5.0</version>
</dependency> </dependency>
<!--Logging framework implements slf4j which is required by hikari--> <!--Logging framework implements slf4j which is required by hikari-->
@ -32,7 +32,7 @@
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>10.0</version> <version>10.0.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -66,8 +66,7 @@ public abstract class FastLoginCore<P> {
private final Set<UUID> pendingConfirms = Sets.newHashSet(); private final Set<UUID> pendingConfirms = Sets.newHashSet();
private final SharedConfig sharedConfig; private final SharedConfig sharedConfig;
private final MojangApiConnector apiConnector; private MojangApiConnector apiConnector;
private AuthStorage storage; private AuthStorage storage;
private PasswordGenerator<P> passwordGenerator = new DefaultPasswordGenerator<>(); private PasswordGenerator<P> passwordGenerator = new DefaultPasswordGenerator<>();
private AuthPlugin<P> authPlugin; private AuthPlugin<P> authPlugin;
@ -75,7 +74,9 @@ public abstract class FastLoginCore<P> {
public FastLoginCore(Map<String, Object> config) { public FastLoginCore(Map<String, Object> config) {
this.pendingLogins = FastLoginCore.buildCache(5, 0); this.pendingLogins = FastLoginCore.buildCache(5, 0);
this.sharedConfig = new SharedConfig(config); this.sharedConfig = new SharedConfig(config);
}
public void setApiConnector() {
List<String> ipAddresses = sharedConfig.get("ip-addresses"); List<String> ipAddresses = sharedConfig.get("ip-addresses");
int requestLimit = sharedConfig.get("mojang-request-limit"); int requestLimit = sharedConfig.get("mojang-request-limit");
this.apiConnector = makeApiConnector(getLogger(), ipAddresses, requestLimit); this.apiConnector = makeApiConnector(getLogger(), ipAddresses, requestLimit);

View File

@ -1,8 +1,9 @@
package com.github.games647.fastlogin.core.shared; 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.PlayerProfile;
import com.github.games647.fastlogin.core.SharedConfig; import com.github.games647.fastlogin.core.SharedConfig;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;

View File

@ -7,6 +7,7 @@ import com.google.common.io.CharStreams;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URL; import java.net.URL;
@ -126,9 +127,9 @@ public abstract class MojangApiConnector {
return null; return null;
} }
BufferedReader reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream())); Reader reader = new InputStreamReader(httpConnection.getInputStream());
String input = CharStreams.toString(reader); String json = CharStreams.toString(reader);
return FastLoginCore.parseId(getUUIDFromJson(input)); return FastLoginCore.parseId(getUUIDFromJson(json));
} catch (IOException iOException) { } catch (IOException iOException) {
logger.log(Level.SEVERE, "Tried converting name->uuid from third-party api", iOException); logger.log(Level.SEVERE, "Tried converting name->uuid from third-party api", iOException);
} }