forked from TuxCoding/FastLogin
Fix timestamp parsing in newer versions of SQLite
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
* Remove deprecated API methods from the last version
|
* Remove deprecated API methods from the last version
|
||||||
* Finally set a value to the API column
|
* Finally set a value to the API column
|
||||||
* No duplicate session login
|
* No duplicate session login
|
||||||
|
* Fix timestamp parsing in newer versions of SQLite
|
||||||
|
|
||||||
######1.9
|
######1.9
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ import me.vik1395.BungeeAuth.Tables;
|
|||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Github: https://github.com/MatteCarra/BungeeAuth
|
* Github: https://github.com/vik1395/BungeeAuth-Minecraft
|
||||||
*
|
*
|
||||||
* Project page:
|
* Project page:
|
||||||
*
|
*
|
||||||
@@ -24,13 +24,13 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|||||||
*/
|
*/
|
||||||
public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
|
public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
|
||||||
|
|
||||||
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L32
|
//https://github.com/vik1395/BungeeAuth-Minecraft/blob/master/src/me/vik1395/BungeeAuth/Login.java#L32
|
||||||
private final Tables databaseConnection = new Tables();
|
private final Tables databaseConnection = new Tables();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean forceLogin(ProxiedPlayer player) {
|
public boolean forceLogin(ProxiedPlayer player) {
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L92-95
|
//https://github.com/vik1395/BungeeAuth-Minecraft/blob/master/src/me/vik1395/BungeeAuth/Login.java#L92-95
|
||||||
if (Main.plonline.contains(playerName)) {
|
if (Main.plonline.contains(playerName)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -58,14 +58,14 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRegistered(String playerName) throws Exception {
|
public boolean isRegistered(String playerName) throws Exception {
|
||||||
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Register.java#L46
|
//https://github.com/vik1395/BungeeAuth-Minecraft/blob/master/src/me/vik1395/BungeeAuth/Register.java#L46
|
||||||
//renamed t to databaseConnection
|
//renamed t to databaseConnection
|
||||||
return databaseConnection.checkPlayerEntry(playerName);
|
return databaseConnection.checkPlayerEntry(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean forceRegister(ProxiedPlayer player, String password) {
|
public boolean forceRegister(ProxiedPlayer player, String password) {
|
||||||
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Register.java#L102
|
//https://github.com/vik1395/BungeeAuth-Minecraft/blob/master/src/me/vik1395/BungeeAuth/Register.java#L102
|
||||||
PasswordHandler ph = new PasswordHandler();
|
PasswordHandler ph = new PasswordHandler();
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
int maxp = 7; //Total Password Hashing methods.
|
int maxp = 7; //Total Password Hashing methods.
|
||||||
@@ -75,7 +75,7 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
|
|||||||
String Pw = password;
|
String Pw = password;
|
||||||
String pType = "" + rand.nextInt(maxp + 1);
|
String pType = "" + rand.nextInt(maxp + 1);
|
||||||
String regdate = ft.format(dNow);
|
String regdate = ft.format(dNow);
|
||||||
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Register.java#L60
|
//https://github.com/vik1395/BungeeAuth-Minecraft/blob/master/src/me/vik1395/BungeeAuth/Register.java#L60
|
||||||
String lastip = player.getAddress().getAddress().getHostAddress();
|
String lastip = player.getAddress().getAddress().getHostAddress();
|
||||||
String lastseen = regdate;
|
String lastseen = regdate;
|
||||||
String hash = ph.newHash(Pw, pType);
|
String hash = ph.newHash(Pw, pType);
|
||||||
@@ -86,7 +86,6 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
|
|||||||
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);
|
||||||
|
@@ -10,8 +10,7 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.Calendar;
|
import java.util.Properties;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -23,9 +22,6 @@ public class AuthStorage {
|
|||||||
private final FastLoginCore<?, ?, ?> core;
|
private final FastLoginCore<?, ?, ?> core;
|
||||||
private final HikariDataSource dataSource;
|
private final HikariDataSource dataSource;
|
||||||
|
|
||||||
//a try to fix https://www.spigotmc.org/threads/fastlogin.101192/page-26#post-1874647
|
|
||||||
private final Calendar calendar = Calendar.getInstance(Locale.US);
|
|
||||||
|
|
||||||
public AuthStorage(FastLoginCore<?, ?, ?> core, String driver, String host, int port, String databasePath
|
public AuthStorage(FastLoginCore<?, ?, ?> core, String driver, String host, int port, String databasePath
|
||||||
, String user, String pass) {
|
, String user, String pass) {
|
||||||
this.core = core;
|
this.core = core;
|
||||||
@@ -35,6 +31,11 @@ public class AuthStorage {
|
|||||||
databaseConfig.setPassword(pass);
|
databaseConfig.setPassword(pass);
|
||||||
databaseConfig.setDriverClassName(driver);
|
databaseConfig.setDriverClassName(driver);
|
||||||
|
|
||||||
|
//a try to fix https://www.spigotmc.org/threads/fastlogin.101192/page-26#post-1874647
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.setProperty("date_string_format", "yyyy-MM-dd HH:mm:ss");
|
||||||
|
databaseConfig.setDataSourceProperties(properties);
|
||||||
|
|
||||||
ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder()
|
ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder()
|
||||||
.setNameFormat(core.getPlugin().getName() + " Database Pool Thread #%1$d")
|
.setNameFormat(core.getPlugin().getName() + " Database Pool Thread #%1$d")
|
||||||
//Hikari create daemons by default
|
//Hikari create daemons by default
|
||||||
@@ -139,7 +140,7 @@ public class AuthStorage {
|
|||||||
|
|
||||||
boolean premium = resultSet.getBoolean(4);
|
boolean premium = resultSet.getBoolean(4);
|
||||||
String lastIp = resultSet.getString(5);
|
String lastIp = resultSet.getString(5);
|
||||||
long lastLogin = resultSet.getTimestamp(6, calendar).getTime();
|
long lastLogin = resultSet.getTimestamp(6).getTime();
|
||||||
PlayerProfile playerProfile = new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin);
|
PlayerProfile playerProfile = new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin);
|
||||||
return playerProfile;
|
return playerProfile;
|
||||||
} else {
|
} else {
|
||||||
@@ -173,7 +174,7 @@ public class AuthStorage {
|
|||||||
String name = resultSet.getString(3);
|
String name = resultSet.getString(3);
|
||||||
boolean premium = resultSet.getBoolean(4);
|
boolean premium = resultSet.getBoolean(4);
|
||||||
String lastIp = resultSet.getString(5);
|
String lastIp = resultSet.getString(5);
|
||||||
long lastLogin = resultSet.getTimestamp(6, calendar).getTime();
|
long lastLogin = resultSet.getTimestamp(6).getTime();
|
||||||
PlayerProfile playerProfile = new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin);
|
PlayerProfile playerProfile = new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin);
|
||||||
return playerProfile;
|
return playerProfile;
|
||||||
}
|
}
|
||||||
|
@@ -88,7 +88,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
|
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("config.yml")));
|
reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("config.yml")));
|
||||||
sharedConfig = new SharedConfig(plugin.loadYamlFile(reader));
|
sharedConfig = new SharedConfig(plugin.loadYamlFile(reader));
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
sharedConfig.getConfigValues().putAll(plugin.loadYamlFile(reader));
|
sharedConfig.getConfigValues().putAll(plugin.loadYamlFile(reader));
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|
||||||
reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("messages.yml")));
|
reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("messages.yml")));
|
||||||
reader = Files.newBufferedReader(new File(plugin.getDataFolder(), "messages.yml").toPath());
|
reader = Files.newBufferedReader(new File(plugin.getDataFolder(), "messages.yml").toPath());
|
||||||
Map<String, Object> messageConfig = plugin.loadYamlFile(reader);
|
Map<String, Object> messageConfig = plugin.loadYamlFile(reader);
|
||||||
reader.close();
|
reader.close();
|
||||||
|
Reference in New Issue
Block a user