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 9179ef96..7e8e0665 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 @@ -1,5 +1,6 @@ package com.github.games647.fastlogin.bungee.hooks; +import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Random; @@ -27,10 +28,19 @@ public class BungeeAuthHook implements BungeeAuthPlugin { public void forceLogin(ProxiedPlayer player) { //https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L92-95 Main.plonline.add(player.getName()); - //renamed from ct to databaseConnection -// databaseConnection.setStatus(player.getName(), "online"); - ListenerClass.movePlayer(player, false); - ListenerClass.prelogin.get(player.getName()).cancel(); + try { + //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"}; + callProtected("setStatus", parameterTypes, arguments); + + ListenerClass.movePlayer(player, false); + ListenerClass.prelogin.get(player.getName()).cancel(); + } catch (Exception ex) { + Main.plugin.getLogger().severe("[BungeeAuth] Error force loging in player"); + } } @Override @@ -58,13 +68,26 @@ public class BungeeAuthHook implements BungeeAuthPlugin { String hash = ph.newHash(Pw, pType); //creates a new SQL entry with the player's details. -// try { + try { //renamed t to databaseConnection // databaseConnection.newPlayerEntry(player.getName(), hash, pType, "", lastip, regdate, lastip, lastseen); - ListenerClass.prelogin.get(player.getName()).cancel(); -// } catch (SQLException e) { -// Main.plugin.getLogger().severe("[BungeeAuth] Error when creating a new player in the MySQL Database"); -// e.printStackTrace(); -// } + + 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}; + callProtected("newPlayerEntry", parameterTypes, arguments); + forceLogin(player); + } catch (Exception ex) { + Main.plugin.getLogger().severe("[BungeeAuth] Error when creating a new player in the MySQL Database"); + } + } + + //pail ;( + private void callProtected(String methodName, Class[] parameterTypes, Object[] arguments) throws Exception { + Class tableClass = databaseConnection.getClass(); + + Method method = tableClass.getDeclaredMethod(methodName, parameterTypes); + method.setAccessible(true); + method.invoke(databaseConnection, arguments); } } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/hooks/BungeeAuthPlugin.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/hooks/BungeeAuthPlugin.java index 988ac150..b1c41e00 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/hooks/BungeeAuthPlugin.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/hooks/BungeeAuthPlugin.java @@ -1,18 +1,26 @@ package com.github.games647.fastlogin.bungee.hooks; - import net.md_5.bungee.api.connection.ProxiedPlayer; -//do not use yet - public interface BungeeAuthPlugin { /** + * Login the premium (paid account) player after + * the player joined successfully a server. * * @param player the player that needs to be logged in */ void forceLogin(ProxiedPlayer player); /** + * Checks whether an account exists for this player name. + * + * This check should check if a cracked player account exists + * so we can be sure the premium player doesn't steal the account + * of that player. + * + * This operation will be performed async while the player is + * connecting * * @param playerName player name * @return if the player has an account @@ -20,6 +28,19 @@ public interface BungeeAuthPlugin { boolean isRegistered(String playerName); /** + * Forces a register in order to protect the paid account. + * The method will be invoked after the player joined a server. + * + * After a successful registration the player should be logged + * in too. + * + * The method will be called only for premium accounts. + * So it's recommended to set additionally premium property + * if possible. + * + * If we don't register an account, cracked players + * could steal the unregistered account from the paid + * player account * * @param player the premium account * @param password a strong random generated password