Workaround protected method + Add documentation

This commit is contained in:
games647
2016-03-20 13:26:37 +01:00
parent dd386408d1
commit f610001c9b
2 changed files with 56 additions and 12 deletions

View File

@ -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<? extends Tables> tableClass = databaseConnection.getClass();
Method method = tableClass.getDeclaredMethod(methodName, parameterTypes);
method.setAccessible(true);
method.invoke(databaseConnection, arguments);
}
}

View File

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