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
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);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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");

View File

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

View File

@ -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) {

View File

@ -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

View File

@ -29,26 +29,25 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
@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<ProxiedPlayer> {
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<ProxiedPlayer> {
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);
}
}

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.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;

View File

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

View File

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

View File

@ -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;

View File

@ -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);
}