Update BungeeAuth dependency and use the new API

This commit is contained in:
games647
2016-10-05 10:06:02 +02:00
parent e924b7a2fa
commit e69eb70377
4 changed files with 15 additions and 77 deletions

View File

@ -1,5 +1,7 @@
######1.10
* Automatically register accounts if they are not in the auth plugin database but in the FastLogin database
* Update BungeeAuth dependency and use the new API. Please update your plugin if you still use the old one.
* Remove deprecated API methods from the last version
* Finally set a value to the API column
* No duplicate session login

View File

@ -47,7 +47,13 @@
<dependency>
<groupId>me.vik1395</groupId>
<artifactId>BungeeAuth</artifactId>
<version>1.3.1</version>
<version>1.4</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

@ -2,16 +2,8 @@ package com.github.games647.fastlogin.bungee.hooks;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.logging.Level;
import me.vik1395.BungeeAuth.ListenerClass;
import me.vik1395.BungeeAuth.Main;
import me.vik1395.BungeeAuth.Password.PasswordHandler;
import me.vik1395.BungeeAuth.Tables;
import me.vik1395.BungeeAuthAPI.RequestHandler;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -24,87 +16,25 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
*/
public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
//https://github.com/vik1395/BungeeAuth-Minecraft/blob/master/src/me/vik1395/BungeeAuth/Login.java#L32
private final Tables databaseConnection = new Tables();
private final RequestHandler requestHandler = new RequestHandler();
@Override
public boolean forceLogin(ProxiedPlayer player) {
String playerName = player.getName();
//https://github.com/vik1395/BungeeAuth-Minecraft/blob/master/src/me/vik1395/BungeeAuth/Login.java#L92-95
if (Main.plonline.contains(playerName)) {
return true;
}
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[]{playerName, "online"};
try {
callProtected("setStatus", parameterTypes, arguments);
ListenerClass.movePlayer(player, false);
//proparly not thread-safe
ListenerClass.prelogin.get(playerName).cancel();
} catch (Exception ex) {
Main.plugin.getLogger().log(Level.SEVERE, "Error force loging in player", ex);
return false;
}
return true;
return requestHandler.forceLogin(playerName);
}
@Override
public boolean isRegistered(String playerName) throws Exception {
//https://github.com/vik1395/BungeeAuth-Minecraft/blob/master/src/me/vik1395/BungeeAuth/Register.java#L46
//renamed t to databaseConnection
return databaseConnection.checkPlayerEntry(playerName);
return requestHandler.isRegistered(playerName);
}
@Override
public boolean forceRegister(ProxiedPlayer player, String password) {
//https://github.com/vik1395/BungeeAuth-Minecraft/blob/master/src/me/vik1395/BungeeAuth/Register.java#L102
PasswordHandler ph = new PasswordHandler();
Random rand = new Random();
int maxp = 7; //Total Password Hashing methods.
Date dNow = new Date();
SimpleDateFormat ft = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
String Pw = password;
String pType = "" + rand.nextInt(maxp + 1);
String regdate = ft.format(dNow);
//https://github.com/vik1395/BungeeAuth-Minecraft/blob/master/src/me/vik1395/BungeeAuth/Register.java#L60
String lastip = player.getAddress().getAddress().getHostAddress();
String lastseen = regdate;
String hash = ph.newHash(Pw, pType);
//creates a new SQL entry with the player's details.
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);
} catch (Exception ex) {
Main.plugin.getLogger().log(Level.SEVERE, "[BungeeAuth] Error when creating a new player in the Database", ex);
return false;
}
return true;
}
//pail ;(
private void callProtected(String methodName, Class<?>[] parameterTypes, Object[] arguments) throws Exception {
Class<Tables> tableClass = Tables.class;
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);
return requestHandler.forceRegister(player, password);
}
}

View File

@ -19,7 +19,7 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.5.0</version>
<version>2.5.1</version>
</dependency>
<!--Logging framework implements slf4j which is required by hikari-->