#477 Change lastlogin column from bigint to timestamp (work in progress)
- Alter column type - Create migration for MySQL - Unrelated: move DataSource enum to its own file
This commit is contained in:
parent
9cf7405f63
commit
db4d4a7cce
@ -13,6 +13,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.io.Resources;
|
import com.google.common.io.Resources;
|
||||||
|
import fr.xephi.authme.datasource.DataSourceType;
|
||||||
import fr.xephi.authme.settings.SettingsMigrationService;
|
import fr.xephi.authme.settings.SettingsMigrationService;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
@ -534,7 +535,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.getDataSource == DataSource.DataSourceType.FILE) {
|
if (Settings.getDataSource == DataSourceType.FILE) {
|
||||||
ConsoleLogger.showError("FlatFile backend has been detected and is now deprecated, it will be changed " +
|
ConsoleLogger.showError("FlatFile backend has been detected and is now deprecated, it will be changed " +
|
||||||
"to SQLite... Connection will be impossible until conversion is done!");
|
"to SQLite... Connection will be impossible until conversion is done!");
|
||||||
ForceFlatToSqlite converter = new ForceFlatToSqlite(database, newSettings);
|
ForceFlatToSqlite converter = new ForceFlatToSqlite(database, newSettings);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSourceType;
|
||||||
import fr.xephi.authme.settings.NewSetting;
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
import fr.xephi.authme.settings.properties.BackupSettings;
|
import fr.xephi.authme.settings.properties.BackupSettings;
|
||||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||||
@ -80,7 +80,7 @@ public class PerformBackup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean doBackup() {
|
public boolean doBackup() {
|
||||||
DataSource.DataSourceType dataSourceType = settings.getProperty(DatabaseSettings.BACKEND);
|
DataSourceType dataSourceType = settings.getProperty(DatabaseSettings.BACKEND);
|
||||||
switch (dataSourceType) {
|
switch (dataSourceType) {
|
||||||
case FILE:
|
case FILE:
|
||||||
return fileBackup("auths.db");
|
return fileBackup("auths.db");
|
||||||
@ -112,14 +112,10 @@ public class PerformBackup {
|
|||||||
ConsoleLogger.info("Backup created successfully.");
|
ConsoleLogger.info("Backup created successfully.");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
ConsoleLogger.showError("Could not create the backup!");
|
ConsoleLogger.showError("Could not create the backup! (Windows)");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
ConsoleLogger.showError("Error during backup: " + StringUtils.formatException(e));
|
ConsoleLogger.logException("Error during Windows backup:", e);
|
||||||
ConsoleLogger.writeStackTrace(e);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
ConsoleLogger.showError("Backup was interrupted: " + StringUtils.formatException(e));
|
|
||||||
ConsoleLogger.writeStackTrace(e);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String executeCmd = "mysqldump -u " + dbUserName + " -p" + dbPassword + " " + dbName + " --tables " + tblname + " -r " + path + ".sql";
|
String executeCmd = "mysqldump -u " + dbUserName + " -p" + dbPassword + " " + dbName + " --tables " + tblname + " -r " + path + ".sql";
|
||||||
@ -133,12 +129,8 @@ public class PerformBackup {
|
|||||||
} else {
|
} else {
|
||||||
ConsoleLogger.showError("Could not create the backup!");
|
ConsoleLogger.showError("Could not create the backup!");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
ConsoleLogger.showError("Error during backup: " + StringUtils.formatException(e));
|
ConsoleLogger.logException("Error during backup:", e);
|
||||||
ConsoleLogger.writeStackTrace(e);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
ConsoleLogger.showError("Backup was interrupted: " + StringUtils.formatException(e));
|
|
||||||
ConsoleLogger.writeStackTrace(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package fr.xephi.authme.converter;
|
|||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import fr.xephi.authme.datasource.DataSourceType;
|
||||||
import fr.xephi.authme.datasource.SQLite;
|
import fr.xephi.authme.datasource.SQLite;
|
||||||
import fr.xephi.authme.settings.NewSetting;
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||||
@ -30,7 +31,7 @@ public class ForceFlatToSqlite {
|
|||||||
auth.setRealName("Player");
|
auth.setRealName("Player");
|
||||||
sqlite.saveAuth(auth);
|
sqlite.saveAuth(auth);
|
||||||
}
|
}
|
||||||
settings.setProperty(DatabaseSettings.BACKEND, DataSource.DataSourceType.SQLITE);
|
settings.setProperty(DatabaseSettings.BACKEND, DataSourceType.SQLITE);
|
||||||
settings.save();
|
settings.save();
|
||||||
ConsoleLogger.info("Database successfully converted to sqlite!");
|
ConsoleLogger.info("Database successfully converted to sqlite!");
|
||||||
return sqlite;
|
return sqlite;
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource.DataSourceType;
|
import fr.xephi.authme.datasource.DataSourceType;
|
||||||
import fr.xephi.authme.datasource.SQLite;
|
import fr.xephi.authme.datasource.SQLite;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,7 @@ public class CacheDataSource implements DataSource {
|
|||||||
})
|
})
|
||||||
.build(
|
.build(
|
||||||
new CacheLoader<String, Optional<PlayerAuth>>() {
|
new CacheLoader<String, Optional<PlayerAuth>>() {
|
||||||
|
@Override
|
||||||
public Optional<PlayerAuth> load(String key) {
|
public Optional<PlayerAuth> load(String key) {
|
||||||
return Optional.fromNullable(source.getAuth(key));
|
return Optional.fromNullable(source.getAuth(key));
|
||||||
}
|
}
|
||||||
@ -62,15 +63,6 @@ public class CacheDataSource implements DataSource {
|
|||||||
return source.getPassword(user);
|
return source.getPassword(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getAuth.
|
|
||||||
*
|
|
||||||
* @param user String
|
|
||||||
*
|
|
||||||
* @return PlayerAuth
|
|
||||||
*
|
|
||||||
* @see fr.xephi.authme.datasource.DataSource#getAuth(String)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized PlayerAuth getAuth(String user) {
|
public synchronized PlayerAuth getAuth(String user) {
|
||||||
user = user.toLowerCase();
|
user = user.toLowerCase();
|
||||||
|
|||||||
@ -220,9 +220,4 @@ public interface DataSource {
|
|||||||
|
|
||||||
boolean isEmailStored(String email);
|
boolean isEmailStored(String email);
|
||||||
|
|
||||||
enum DataSourceType {
|
|
||||||
MYSQL,
|
|
||||||
FILE,
|
|
||||||
SQLITE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/main/java/fr/xephi/authme/datasource/DataSourceType.java
Normal file
14
src/main/java/fr/xephi/authme/datasource/DataSourceType.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DataSource type.
|
||||||
|
*/
|
||||||
|
public enum DataSourceType {
|
||||||
|
|
||||||
|
MYSQL,
|
||||||
|
|
||||||
|
FILE,
|
||||||
|
|
||||||
|
SQLITE
|
||||||
|
|
||||||
|
}
|
||||||
@ -18,6 +18,8 @@ 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.sql.Timestamp;
|
||||||
|
import java.sql.Types;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -149,7 +151,7 @@ public class MySQL implements DataSource {
|
|||||||
+ columnRealName + " VARCHAR(255) NOT NULL,"
|
+ columnRealName + " VARCHAR(255) NOT NULL,"
|
||||||
+ columnPassword + " VARCHAR(255) NOT NULL,"
|
+ columnPassword + " VARCHAR(255) NOT NULL,"
|
||||||
+ columnIp + " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1',"
|
+ columnIp + " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1',"
|
||||||
+ columnLastLogin + " BIGINT NOT NULL DEFAULT '" + System.currentTimeMillis() + "',"
|
+ columnLastLogin + " TIMESTAMP NOT NULL DEFAULT current_timestamp,"
|
||||||
+ lastlocX + " DOUBLE NOT NULL DEFAULT '0.0',"
|
+ lastlocX + " DOUBLE NOT NULL DEFAULT '0.0',"
|
||||||
+ lastlocY + " DOUBLE NOT NULL DEFAULT '0.0',"
|
+ lastlocY + " DOUBLE NOT NULL DEFAULT '0.0',"
|
||||||
+ lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0',"
|
+ lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0',"
|
||||||
@ -200,7 +202,9 @@ public class MySQL implements DataSource {
|
|||||||
rs = md.getColumns(null, null, tableName, columnLastLogin);
|
rs = md.getColumns(null, null, tableName, columnLastLogin);
|
||||||
if (!rs.next()) {
|
if (!rs.next()) {
|
||||||
st.executeUpdate("ALTER TABLE " + tableName
|
st.executeUpdate("ALTER TABLE " + tableName
|
||||||
+ " ADD COLUMN " + columnLastLogin + " BIGINT;");
|
+ " ADD COLUMN " + columnLastLogin + " TIMESTAMP NOT NULL DEFAULT current_timestamp;");
|
||||||
|
} else {
|
||||||
|
migrateLastLoginColumnToTimestamp(con, rs);
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
|
|
||||||
@ -245,7 +249,7 @@ public class MySQL implements DataSource {
|
|||||||
|
|
||||||
st.close();
|
st.close();
|
||||||
}
|
}
|
||||||
ConsoleLogger.info("MySQL Setup finished");
|
ConsoleLogger.info("MySQL setup finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -291,22 +295,8 @@ public class MySQL implements DataSource {
|
|||||||
if (!rs.next()) {
|
if (!rs.next()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String salt = !columnSalt.isEmpty() ? rs.getString(columnSalt) : null;
|
|
||||||
int group = !columnGroup.isEmpty() ? rs.getInt(columnGroup) : -1;
|
|
||||||
int id = rs.getInt(columnID);
|
int id = rs.getInt(columnID);
|
||||||
pAuth = PlayerAuth.builder()
|
pAuth = buildAuthFromResultSet(rs);
|
||||||
.name(rs.getString(columnName))
|
|
||||||
.realName(rs.getString(columnRealName))
|
|
||||||
.password(rs.getString(columnPassword), salt)
|
|
||||||
.lastLogin(rs.getLong(columnLastLogin))
|
|
||||||
.ip(rs.getString(columnIp))
|
|
||||||
.locWorld(rs.getString(lastlocWorld))
|
|
||||||
.locX(rs.getDouble(lastlocX))
|
|
||||||
.locY(rs.getDouble(lastlocY))
|
|
||||||
.locZ(rs.getDouble(lastlocZ))
|
|
||||||
.email(rs.getString(columnEmail))
|
|
||||||
.groupId(group)
|
|
||||||
.build();
|
|
||||||
rs.close();
|
rs.close();
|
||||||
pst.close();
|
pst.close();
|
||||||
if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) {
|
if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) {
|
||||||
@ -344,7 +334,7 @@ public class MySQL implements DataSource {
|
|||||||
pst.setString(1, auth.getNickname());
|
pst.setString(1, auth.getNickname());
|
||||||
pst.setString(2, auth.getPassword().getHash());
|
pst.setString(2, auth.getPassword().getHash());
|
||||||
pst.setString(3, auth.getIp());
|
pst.setString(3, auth.getIp());
|
||||||
pst.setLong(4, auth.getLastLogin());
|
pst.setTimestamp(4, new Timestamp(auth.getLastLogin()));
|
||||||
pst.setString(5, auth.getRealName());
|
pst.setString(5, auth.getRealName());
|
||||||
pst.setString(6, auth.getEmail());
|
pst.setString(6, auth.getEmail());
|
||||||
if (useSalt) {
|
if (useSalt) {
|
||||||
@ -923,22 +913,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = st.executeQuery("SELECT * FROM " + tableName);
|
ResultSet rs = st.executeQuery("SELECT * FROM " + tableName);
|
||||||
PreparedStatement pst = con.prepareStatement("SELECT data FROM xf_user_authenticate WHERE " + columnID + "=?;");
|
PreparedStatement pst = con.prepareStatement("SELECT data FROM xf_user_authenticate WHERE " + columnID + "=?;");
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
String salt = !columnSalt.isEmpty() ? rs.getString(columnSalt) : null;
|
PlayerAuth pAuth = buildAuthFromResultSet(rs);
|
||||||
int group = !columnGroup.isEmpty() ? rs.getInt(columnGroup) : -1;
|
|
||||||
PlayerAuth pAuth = PlayerAuth.builder()
|
|
||||||
.name(rs.getString(columnName))
|
|
||||||
.realName(rs.getString(columnRealName))
|
|
||||||
.password(rs.getString(columnPassword), salt)
|
|
||||||
.lastLogin(rs.getLong(columnLastLogin))
|
|
||||||
.ip(rs.getString(columnIp))
|
|
||||||
.locWorld(rs.getString(lastlocWorld))
|
|
||||||
.locX(rs.getDouble(lastlocX))
|
|
||||||
.locY(rs.getDouble(lastlocY))
|
|
||||||
.locZ(rs.getDouble(lastlocZ))
|
|
||||||
.email(rs.getString(columnEmail))
|
|
||||||
.groupId(group)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) {
|
if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) {
|
||||||
int id = rs.getInt(columnID);
|
int id = rs.getInt(columnID);
|
||||||
pst.setInt(1, id);
|
pst.setInt(1, id);
|
||||||
@ -969,22 +944,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = st.executeQuery("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
|
ResultSet rs = st.executeQuery("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
|
||||||
PreparedStatement pst = con.prepareStatement("SELECT data FROM xf_user_authenticate WHERE " + columnID + "=?;");
|
PreparedStatement pst = con.prepareStatement("SELECT data FROM xf_user_authenticate WHERE " + columnID + "=?;");
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
String salt = !columnSalt.isEmpty() ? rs.getString(columnSalt) : null;
|
PlayerAuth pAuth = buildAuthFromResultSet(rs);
|
||||||
int group = !columnGroup.isEmpty() ? rs.getInt(columnGroup) : -1;
|
|
||||||
PlayerAuth pAuth = PlayerAuth.builder()
|
|
||||||
.name(rs.getString(columnName))
|
|
||||||
.realName(rs.getString(columnRealName))
|
|
||||||
.password(rs.getString(columnPassword), salt)
|
|
||||||
.lastLogin(rs.getLong(columnLastLogin))
|
|
||||||
.ip(rs.getString(columnIp))
|
|
||||||
.locWorld(rs.getString(lastlocWorld))
|
|
||||||
.locX(rs.getDouble(lastlocX))
|
|
||||||
.locY(rs.getDouble(lastlocY))
|
|
||||||
.locZ(rs.getDouble(lastlocZ))
|
|
||||||
.email(rs.getString(columnEmail))
|
|
||||||
.groupId(group)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) {
|
if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) {
|
||||||
int id = rs.getInt(columnID);
|
int id = rs.getInt(columnID);
|
||||||
pst.setInt(1, id);
|
pst.setInt(1, id);
|
||||||
@ -1018,6 +978,55 @@ public class MySQL implements DataSource {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {
|
||||||
|
String salt = columnSalt.isEmpty() ? null : row.getString(columnSalt);
|
||||||
|
int group = columnGroup.isEmpty() ? -1 : row.getInt(columnGroup);
|
||||||
|
return PlayerAuth.builder()
|
||||||
|
.name(row.getString(columnName))
|
||||||
|
.realName(row.getString(columnRealName))
|
||||||
|
.password(row.getString(columnPassword), salt)
|
||||||
|
.lastLogin(row.getTimestamp(columnLastLogin).getTime())
|
||||||
|
.ip(row.getString(columnIp))
|
||||||
|
.locWorld(row.getString(lastlocWorld))
|
||||||
|
.locX(row.getDouble(lastlocX))
|
||||||
|
.locY(row.getDouble(lastlocY))
|
||||||
|
.locZ(row.getDouble(lastlocZ))
|
||||||
|
.email(row.getString(columnEmail))
|
||||||
|
.groupId(group)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void migrateLastLoginColumnToTimestamp(Connection con, ResultSet rs) throws SQLException {
|
||||||
|
final int columnType = rs.getInt("DATA_TYPE");
|
||||||
|
if (columnType == Types.BIGINT) {
|
||||||
|
ConsoleLogger.info("Migrating lastlogin column from bigint to timestamp");
|
||||||
|
final String lastLoginOld = columnLastLogin + "_old";
|
||||||
|
|
||||||
|
// Rename lastlogin to lastlogin_old
|
||||||
|
String sql = String.format("ALTER TABLE %s CHANGE COLUMN %s %s BIGINT",
|
||||||
|
tableName, columnLastLogin, lastLoginOld);
|
||||||
|
PreparedStatement pst = con.prepareStatement(sql);
|
||||||
|
pst.execute();
|
||||||
|
|
||||||
|
// Create lastlogin column
|
||||||
|
sql = String.format("ALTER TABLE %s ADD COLUMN %s " +
|
||||||
|
"TIMESTAMP NOT NULL DEFAULT current_timestamp AFTER %s",
|
||||||
|
tableName, columnLastLogin, columnIp);
|
||||||
|
con.prepareStatement(sql).execute();
|
||||||
|
|
||||||
|
// Set values of lastlogin based on lastlogin_old
|
||||||
|
sql = String.format("UPDATE %s SET %s = FROM_UNIXTIME(%s)",
|
||||||
|
tableName, columnLastLogin, lastLoginOld);
|
||||||
|
con.prepareStatement(sql).execute();
|
||||||
|
|
||||||
|
// Drop lastlogin_old
|
||||||
|
sql = String.format("ALTER TABLE %s DROP COLUMN %s",
|
||||||
|
tableName, lastLoginOld);
|
||||||
|
con.prepareStatement(sql).execute();
|
||||||
|
ConsoleLogger.info("Finished migration of lastlogin (bigint to timestamp)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void logSqlException(SQLException e) {
|
private static void logSqlException(SQLException e) {
|
||||||
ConsoleLogger.logException("Error during SQL operation:", e);
|
ConsoleLogger.logException("Error during SQL operation:", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,9 +64,9 @@ public class SQLite implements DataSource {
|
|||||||
try {
|
try {
|
||||||
this.connect();
|
this.connect();
|
||||||
this.setup();
|
this.setup();
|
||||||
} catch (ClassNotFoundException | SQLException cnf) {
|
} catch (ClassNotFoundException | SQLException ex) {
|
||||||
ConsoleLogger.showError("Can't use SQLITE... !");
|
ConsoleLogger.logException("Error during SQLite initialization:", ex);
|
||||||
throw cnf;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ public class SQLite implements DataSource {
|
|||||||
rs.close();
|
rs.close();
|
||||||
rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin);
|
rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin);
|
||||||
if (!rs.next()) {
|
if (!rs.next()) {
|
||||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " BIGINT DEFAULT '0';");
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " TIMESTAMP DEFAULT current_timestamp;");
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
rs = con.getMetaData().getColumns(null, null, tableName, lastlocX);
|
rs = con.getMetaData().getColumns(null, null, tableName, lastlocX);
|
||||||
@ -124,7 +124,7 @@ public class SQLite implements DataSource {
|
|||||||
rs.close();
|
rs.close();
|
||||||
rs = con.getMetaData().getColumns(null, null, tableName, columnLogged);
|
rs = con.getMetaData().getColumns(null, null, tableName, columnLogged);
|
||||||
if (!rs.next()) {
|
if (!rs.next()) {
|
||||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLogged + " BIGINT DEFAULT '0';");
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLogged + " INT DEFAULT '0';");
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
rs = con.getMetaData().getColumns(null, null, tableName, columnRealName);
|
rs = con.getMetaData().getColumns(null, null, tableName, columnRealName);
|
||||||
@ -178,13 +178,6 @@ public class SQLite implements DataSource {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getAuth.
|
|
||||||
*
|
|
||||||
* @param user String
|
|
||||||
*
|
|
||||||
* @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized PlayerAuth getAuth(String user) {
|
public synchronized PlayerAuth getAuth(String user) {
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class AsynchronousLogin {
|
|||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean needsCaptcha() {
|
private boolean needsCaptcha() {
|
||||||
if (Settings.useCaptcha) {
|
if (Settings.useCaptcha) {
|
||||||
if (!plugin.captcha.containsKey(name)) {
|
if (!plugin.captcha.containsKey(name)) {
|
||||||
plugin.captcha.putIfAbsent(name, 1);
|
plugin.captcha.putIfAbsent(name, 1);
|
||||||
@ -87,7 +87,7 @@ public class AsynchronousLogin {
|
|||||||
*
|
*
|
||||||
* @return PlayerAuth
|
* @return PlayerAuth
|
||||||
*/
|
*/
|
||||||
protected PlayerAuth preAuth() {
|
private PlayerAuth preAuth() {
|
||||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||||
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||||
return null;
|
return null;
|
||||||
@ -153,7 +153,6 @@ public class AsynchronousLogin {
|
|||||||
.name(name)
|
.name(name)
|
||||||
.realName(realName)
|
.realName(realName)
|
||||||
.ip(ip)
|
.ip(ip)
|
||||||
.lastLogin(new Date().getTime())
|
|
||||||
.email(email)
|
.email(email)
|
||||||
.password(pAuth.getPassword())
|
.password(pAuth.getPassword())
|
||||||
.build();
|
.build();
|
||||||
@ -221,14 +220,12 @@ public class AsynchronousLogin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void displayOtherAccounts(PlayerAuth auth) {
|
public void displayOtherAccounts(PlayerAuth auth) {
|
||||||
if (!Settings.displayOtherAccounts) {
|
if (!Settings.displayOtherAccounts || auth == null) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (auth == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> auths = this.database.getAllAuthsByName(auth);
|
List<String> auths = this.database.getAllAuthsByName(auth);
|
||||||
if (auths.isEmpty() || auths.size() == 1) {
|
if (auths.size() < 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String message = "[AuthMe] " + StringUtils.join(", ", auths) + ".";
|
String message = "[AuthMe] " + StringUtils.join(", ", auths) + ".";
|
||||||
|
|||||||
@ -43,7 +43,7 @@ public class AsyncRegister {
|
|||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean preRegisterCheck() throws Exception {
|
private boolean preRegisterCheck() {
|
||||||
String passLow = password.toLowerCase();
|
String passLow = password.toLowerCase();
|
||||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||||
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||||
@ -86,18 +86,12 @@ public class AsyncRegister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
try {
|
if (preRegisterCheck()) {
|
||||||
if (!preRegisterCheck()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (email != null && !email.isEmpty()) {
|
if (email != null && !email.isEmpty()) {
|
||||||
emailRegister();
|
emailRegister();
|
||||||
} else {
|
} else {
|
||||||
passwordRegister();
|
passwordRegister();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
ConsoleLogger.logException("Error during async register process", e);
|
|
||||||
m.send(player, MessageKey.ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +124,7 @@ public class AsyncRegister {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void passwordRegister() throws Exception {
|
private void passwordRegister() {
|
||||||
final HashedPassword hashedPassword = plugin.getPasswordSecurity().computeHash(password, name);
|
final HashedPassword hashedPassword = plugin.getPasswordSecurity().computeHash(password, name);
|
||||||
PlayerAuth auth = PlayerAuth.builder()
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
.name(name)
|
.name(name)
|
||||||
|
|||||||
@ -2,8 +2,7 @@ package fr.xephi.authme.settings;
|
|||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSourceType;
|
||||||
import fr.xephi.authme.datasource.DataSource.DataSourceType;
|
|
||||||
import fr.xephi.authme.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
import fr.xephi.authme.util.Wrapper;
|
import fr.xephi.authme.util.Wrapper;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
@ -281,10 +280,10 @@ public final class Settings {
|
|||||||
private static DataSourceType getDataSource() {
|
private static DataSourceType getDataSource() {
|
||||||
String key = "DataSource.backend";
|
String key = "DataSource.backend";
|
||||||
try {
|
try {
|
||||||
return DataSource.DataSourceType.valueOf(configFile.getString(key, "sqlite").toUpperCase());
|
return DataSourceType.valueOf(configFile.getString(key, "sqlite").toUpperCase());
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
ConsoleLogger.showError("Unknown database backend; defaulting to SQLite database");
|
ConsoleLogger.showError("Unknown database backend; defaulting to SQLite database");
|
||||||
return DataSource.DataSourceType.SQLITE;
|
return DataSourceType.SQLITE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package fr.xephi.authme.settings.properties;
|
package fr.xephi.authme.settings.properties;
|
||||||
|
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSourceType;
|
||||||
import fr.xephi.authme.settings.domain.Comment;
|
import fr.xephi.authme.settings.domain.Comment;
|
||||||
import fr.xephi.authme.settings.domain.Property;
|
import fr.xephi.authme.settings.domain.Property;
|
||||||
import fr.xephi.authme.settings.domain.SettingsClass;
|
import fr.xephi.authme.settings.domain.SettingsClass;
|
||||||
@ -11,8 +11,8 @@ public class DatabaseSettings implements SettingsClass {
|
|||||||
|
|
||||||
@Comment({"What type of database do you want to use?",
|
@Comment({"What type of database do you want to use?",
|
||||||
"Valid values: sqlite, mysql"})
|
"Valid values: sqlite, mysql"})
|
||||||
public static final Property<DataSource.DataSourceType> BACKEND =
|
public static final Property<DataSourceType> BACKEND =
|
||||||
newProperty(DataSource.DataSourceType.class, "DataSource.backend", DataSource.DataSourceType.SQLITE);
|
newProperty(DataSourceType.class, "DataSource.backend", DataSourceType.SQLITE);
|
||||||
|
|
||||||
@Comment("Enable database caching, should improve database performance")
|
@Comment("Enable database caching, should improve database performance")
|
||||||
public static final Property<Boolean> USE_CACHING =
|
public static final Property<Boolean> USE_CACHING =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user