Wrap column names into class

- Load column names for data sources centrally
- Remove no longer used settings in legacy Settings
This commit is contained in:
ljacqu 2016-02-14 13:25:16 +01:00
parent 6e2528278a
commit 5dc1598f6e
10 changed files with 313 additions and 342 deletions

View File

@ -244,8 +244,8 @@ public class AuthMe extends JavaPlugin {
return; return;
} }
passwordSecurity = new PasswordSecurity(getDataSource(), Settings.getPasswordHash, passwordSecurity = new PasswordSecurity(getDataSource(), newSettings.getProperty(SecuritySettings.PASSWORD_HASH),
Bukkit.getPluginManager(), Settings.supportOldPassword); Bukkit.getPluginManager(), newSettings.getProperty(SecuritySettings.SUPPORT_OLD_PASSWORD_HASH));
// Set up the permissions manager and command handler // Set up the permissions manager and command handler
permsMan = initializePermissionsManager(); permsMan = initializePermissionsManager();
@ -516,10 +516,10 @@ public class AuthMe extends JavaPlugin {
database = new FlatFile(); database = new FlatFile();
break; break;
case MYSQL: case MYSQL:
database = new MySQL(); database = new MySQL(newSettings);
break; break;
case SQLITE: case SQLITE:
database = new SQLite(); database = new SQLite(newSettings);
isSQLite = true; isSQLite = true;
break; break;
} }

View File

@ -51,8 +51,8 @@ public class ConverterCommand implements ExecutableCommand {
converter = new vAuthConverter(plugin, sender); converter = new vAuthConverter(plugin, sender);
break; break;
case SQLITETOSQL: case SQLITETOSQL:
converter = new SqliteToSql(plugin, sender); converter = new SqliteToSql(plugin, sender, commandService.getSettings());
break; break;
default: default:
break; break;
} }

View File

@ -1,6 +1,7 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
/** /**
* Common supertype for AuthMe converters.
*/ */
public interface Converter extends Runnable { public interface Converter extends Runnable {
} }

View File

@ -26,7 +26,7 @@ public class ForceFlatToSqlite {
public DataSource run() { public DataSource run() {
try { try {
DataSource sqlite = new SQLite(); DataSource sqlite = new SQLite(settings);
for (PlayerAuth auth : database.getAllAuths()) { for (PlayerAuth auth : database.getAllAuths()) {
auth.setRealName("Player"); auth.setRealName("Player");
sqlite.saveAuth(auth); sqlite.saveAuth(auth);
@ -36,9 +36,7 @@ public class ForceFlatToSqlite {
ConsoleLogger.info("Database successfully converted to sqlite!"); ConsoleLogger.info("Database successfully converted to sqlite!");
return sqlite; return sqlite;
} catch (SQLException | ClassNotFoundException e) { } catch (SQLException | ClassNotFoundException e) {
ConsoleLogger.showError("An error occurred while trying to convert flatfile to sqlite: " ConsoleLogger.logException("Could not convert from Flatfile to SQLite:", e);
+ StringUtils.formatException(e));
ConsoleLogger.writeStackTrace(e);
} }
return null; return null;
} }

View File

@ -1,5 +1,6 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
import fr.xephi.authme.settings.NewSetting;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
@ -11,29 +12,31 @@ import fr.xephi.authme.output.MessageKey;
public class SqliteToSql implements Converter { public class SqliteToSql implements Converter {
private AuthMe plugin; private final AuthMe plugin;
private CommandSender sender; private final CommandSender sender;
private final NewSetting settings;
public SqliteToSql(AuthMe plugin, CommandSender sender) { public SqliteToSql(AuthMe plugin, CommandSender sender, NewSetting settings) {
this.plugin = plugin; this.plugin = plugin;
this.sender = sender; this.sender = sender;
} this.settings = settings;
}
@Override @Override
public void run() { public void run() {
if (plugin.getDataSource().getType() != DataSourceType.MYSQL) { if (plugin.getDataSource().getType() != DataSourceType.MYSQL) {
sender.sendMessage("Please config your mySQL connection and re-run this command"); sender.sendMessage("Please configure your mySQL connection and re-run this command");
return; return;
} }
try { try {
SQLite data = new SQLite(); SQLite data = new SQLite(settings);
for (PlayerAuth auth : data.getAllAuths()) { for (PlayerAuth auth : data.getAllAuths()) {
plugin.getDataSource().saveAuth(auth); plugin.getDataSource().saveAuth(auth);
} }
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage(plugin.getMessages().retrieve(MessageKey.ERROR)); plugin.getMessages().send(sender, MessageKey.ERROR);
ConsoleLogger.showError(e.getMessage()); ConsoleLogger.logException("Problem during SQLite to SQL conversion:", e);
} }
} }
} }

View File

@ -4,8 +4,10 @@ import de.luricos.bukkit.xAuth.database.DatabaseTables;
import de.luricos.bukkit.xAuth.utils.xAuthLog; import de.luricos.bukkit.xAuth.utils.xAuthLog;
import de.luricos.bukkit.xAuth.xAuth; import de.luricos.bukkit.xAuth.xAuth;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
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.util.CollectionUtils;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.io.File; import java.io.File;
@ -22,12 +24,6 @@ class xAuthToFlat {
private final DataSource database; private final DataSource database;
private final CommandSender sender; private final CommandSender sender;
/**
* Constructor for xAuthToFlat.
*
* @param instance AuthMe
* @param sender CommandSender
*/
public xAuthToFlat(AuthMe instance, CommandSender sender) { public xAuthToFlat(AuthMe instance, CommandSender sender) {
this.instance = instance; this.instance = instance;
this.database = instance.getDataSource(); this.database = instance.getDataSource();
@ -39,12 +35,13 @@ class xAuthToFlat {
sender.sendMessage("[AuthMe] xAuth plugin not found"); sender.sendMessage("[AuthMe] xAuth plugin not found");
return false; return false;
} }
if (!(new File(instance.getDataFolder().getParent() + File.separator + "xAuth" + File.separator + "xAuth.h2.db").exists())) { File xAuthDb = new File(instance.getDataFolder().getParent(), "xAuth" + File.separator + "xAuth.h2.db");
if (!xAuthDb.exists()) {
sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data..."); sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data...");
} }
List<Integer> players = getXAuthPlayers(); List<Integer> players = getXAuthPlayers();
if (players == null || players.isEmpty()) { if (CollectionUtils.isEmpty(players)) {
sender.sendMessage("[AuthMe] Error while import xAuthPlayers"); sender.sendMessage("[AuthMe] Error while importing xAuthPlayers: did not find any players");
return false; return false;
} }
sender.sendMessage("[AuthMe] Starting import..."); sender.sendMessage("[AuthMe] Starting import...");
@ -59,7 +56,9 @@ class xAuthToFlat {
} }
sender.sendMessage("[AuthMe] Successfully converted from xAuth database"); sender.sendMessage("[AuthMe] Successfully converted from xAuth database");
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage("[AuthMe] An error has been thrown while import xAuth database, the import hadn't fail but can be not complete "); sender.sendMessage("[AuthMe] An error has occurred while importing the xAuth database."
+ " The import may have succeeded partially.");
ConsoleLogger.logException("Error during xAuth database import", e);
} }
return true; return true;
} }

View File

@ -0,0 +1,43 @@
package fr.xephi.authme.datasource;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.DatabaseSettings;
/**
* Database column names.
*/
public final class Columns {
public final String NAME;
public final String REAL_NAME;
public final String PASSWORD;
public final String SALT;
public final String IP;
public final String LAST_LOGIN;
public final String GROUP;
public final String LASTLOC_X;
public final String LASTLOC_Y;
public final String LASTLOC_Z;
public final String LASTLOC_WORLD;
public final String EMAIL;
public final String ID;
public final String IS_LOGGED;
public Columns(NewSetting settings) {
NAME = settings.getProperty(DatabaseSettings.MYSQL_COL_NAME);
REAL_NAME = settings.getProperty(DatabaseSettings.MYSQL_COL_REALNAME);
PASSWORD = settings.getProperty(DatabaseSettings.MYSQL_COL_PASSWORD);
SALT = settings.getProperty(DatabaseSettings.MYSQL_COL_SALT);
IP = settings.getProperty(DatabaseSettings.MYSQL_COL_IP);
LAST_LOGIN = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOGIN);
GROUP = settings.getProperty(DatabaseSettings.MYSQL_COL_GROUP);
LASTLOC_X = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_X);
LASTLOC_Y = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Y);
LASTLOC_Z = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Z);
LASTLOC_WORLD = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_WORLD);
EMAIL = settings.getProperty(DatabaseSettings.MYSQL_COL_EMAIL);
ID = settings.getProperty(DatabaseSettings.MYSQL_COL_ID);
IS_LOGGED = settings.getProperty(DatabaseSettings.MYSQL_COL_ISLOGGED);
}
}

View File

@ -8,7 +8,11 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.security.crypts.XFBCRYPT; import fr.xephi.authme.security.crypts.XFBCRYPT;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.DatabaseSettings;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.StringUtils;
import java.sql.Blob; import java.sql.Blob;
@ -33,45 +37,21 @@ public class MySQL implements DataSource {
private final String password; private final String password;
private final String database; private final String database;
private final String tableName; private final String tableName;
private final String columnName;
private final String columnPassword;
private final String columnIp;
private final String columnLastLogin;
private final String columnSalt;
private final String columnGroup;
private final String lastlocX;
private final String lastlocY;
private final String lastlocZ;
private final String lastlocWorld;
private final String columnEmail;
private final String columnID;
private final String columnLogged;
private final String columnRealName;
private final List<String> columnOthers; private final List<String> columnOthers;
private final Columns col;
private final HashAlgorithm hashAlgorithm;
private HikariDataSource ds; private HikariDataSource ds;
public MySQL() throws ClassNotFoundException, SQLException, PoolInitializationException { public MySQL(NewSetting settings) throws ClassNotFoundException, SQLException, PoolInitializationException {
this.host = Settings.getMySQLHost; this.host = settings.getProperty(DatabaseSettings.MYSQL_HOST);
this.port = Settings.getMySQLPort; this.port = settings.getProperty(DatabaseSettings.MYSQL_PORT);
this.username = Settings.getMySQLUsername; this.username = settings.getProperty(DatabaseSettings.MYSQL_USERNAME);
this.password = Settings.getMySQLPassword; this.password = settings.getProperty(DatabaseSettings.MYSQL_PASSWORD);
this.database = Settings.getMySQLDatabase; this.database = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
this.tableName = Settings.getMySQLTablename; this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
this.columnName = Settings.getMySQLColumnName; this.columnOthers = settings.getProperty(HooksSettings.MYSQL_OTHER_USERNAME_COLS);
this.columnPassword = Settings.getMySQLColumnPassword; this.col = new Columns(settings);
this.columnIp = Settings.getMySQLColumnIp; this.hashAlgorithm = settings.getProperty(SecuritySettings.PASSWORD_HASH);
this.columnLastLogin = Settings.getMySQLColumnLastLogin;
this.lastlocX = Settings.getMySQLlastlocX;
this.lastlocY = Settings.getMySQLlastlocY;
this.lastlocZ = Settings.getMySQLlastlocZ;
this.lastlocWorld = Settings.getMySQLlastlocWorld;
this.columnSalt = Settings.getMySQLColumnSalt;
this.columnGroup = Settings.getMySQLColumnGroup;
this.columnEmail = Settings.getMySQLColumnEmail;
this.columnOthers = Settings.getMySQLOtherUsernameColumn;
this.columnID = Settings.getMySQLColumnId;
this.columnLogged = Settings.getMySQLColumnLogged;
this.columnRealName = Settings.getMySQLColumnRealName;
// Set the connection arguments (and check if connection is ok) // Set the connection arguments (and check if connection is ok)
try { try {
@ -146,104 +126,104 @@ public class MySQL implements DataSource {
DatabaseMetaData md = con.getMetaData(); DatabaseMetaData md = con.getMetaData();
// Create table if not exists. // Create table if not exists.
String sql = "CREATE TABLE IF NOT EXISTS " + tableName + " (" String sql = "CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ columnID + " INTEGER AUTO_INCREMENT," + col.ID + " INTEGER AUTO_INCREMENT,"
+ columnName + " VARCHAR(255) NOT NULL UNIQUE," + col.NAME + " VARCHAR(255) NOT NULL UNIQUE,"
+ columnRealName + " VARCHAR(255) NOT NULL," + col.REAL_NAME + " VARCHAR(255) NOT NULL,"
+ columnPassword + " VARCHAR(255) NOT NULL," + col.PASSWORD + " VARCHAR(255) NOT NULL,"
+ columnIp + " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1'," + col.IP + " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1',"
+ columnLastLogin + " TIMESTAMP NOT NULL DEFAULT current_timestamp," + col.LAST_LOGIN + " TIMESTAMP NOT NULL DEFAULT current_timestamp,"
+ lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0',"
+ lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0',"
+ lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0',"
+ lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "',"
+ columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com',"
+ columnLogged + " SMALLINT NOT NULL DEFAULT '0'," + col.IS_LOGGED + " SMALLINT NOT NULL DEFAULT '0',"
+ "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + ")" + "CONSTRAINT table_const_prim PRIMARY KEY (" + col.ID + ")"
+ ");"; + ");";
st.executeUpdate(sql); st.executeUpdate(sql);
ResultSet rs = md.getColumns(null, null, tableName, columnName); ResultSet rs = md.getColumns(null, null, tableName, col.NAME);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName st.executeUpdate("ALTER TABLE " + tableName
+ " ADD COLUMN " + columnName + " VARCHAR(255) NOT NULL UNIQUE AFTER " + columnID + ";"); + " ADD COLUMN " + col.NAME + " VARCHAR(255) NOT NULL UNIQUE AFTER " + col.ID + ";");
} }
rs.close(); rs.close();
rs = md.getColumns(null, null, tableName, columnRealName); rs = md.getColumns(null, null, tableName, col.REAL_NAME);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName st.executeUpdate("ALTER TABLE " + tableName
+ " ADD COLUMN " + columnRealName + " VARCHAR(255) NOT NULL AFTER " + columnName + ";"); + " ADD COLUMN " + col.REAL_NAME + " VARCHAR(255) NOT NULL AFTER " + col.NAME + ";");
} }
rs.close(); rs.close();
rs = md.getColumns(null, null, tableName, columnPassword); rs = md.getColumns(null, null, tableName, col.PASSWORD);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName st.executeUpdate("ALTER TABLE " + tableName
+ " ADD COLUMN " + columnPassword + " VARCHAR(255) NOT NULL;"); + " ADD COLUMN " + col.PASSWORD + " VARCHAR(255) NOT NULL;");
} }
rs.close(); rs.close();
if (!columnSalt.isEmpty()) { if (!col.SALT.isEmpty()) {
rs = md.getColumns(null, null, tableName, columnSalt); rs = md.getColumns(null, null, tableName, col.SALT);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName st.executeUpdate("ALTER TABLE " + tableName
+ " ADD COLUMN " + columnSalt + " VARCHAR(255);"); + " ADD COLUMN " + col.SALT + " VARCHAR(255);");
} }
rs.close(); rs.close();
} }
rs = md.getColumns(null, null, tableName, columnIp); rs = md.getColumns(null, null, tableName, col.IP);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName st.executeUpdate("ALTER TABLE " + tableName
+ " ADD COLUMN " + columnIp + " VARCHAR(40) NOT NULL;"); + " ADD COLUMN " + col.IP + " VARCHAR(40) NOT NULL;");
} }
rs.close(); rs.close();
rs = md.getColumns(null, null, tableName, columnLastLogin); rs = md.getColumns(null, null, tableName, col.LAST_LOGIN);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName st.executeUpdate("ALTER TABLE " + tableName
+ " ADD COLUMN " + columnLastLogin + " TIMESTAMP NOT NULL DEFAULT current_timestamp;"); + " ADD COLUMN " + col.LAST_LOGIN + " TIMESTAMP NOT NULL DEFAULT current_timestamp;");
} else { } else {
migrateLastLoginColumnToTimestamp(con, rs); migrateLastLoginColumnToTimestamp(con, rs);
} }
rs.close(); rs.close();
rs = md.getColumns(null, null, tableName, lastlocX); rs = md.getColumns(null, null, tableName, col.LASTLOC_X);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ lastlocX + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + columnLastLogin + " , ADD " + col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LAST_LOGIN + " , ADD "
+ lastlocY + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + lastlocX + " , ADD " + col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LASTLOC_X + " , ADD "
+ lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + lastlocY); + col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LASTLOC_Y);
} }
rs.close(); rs.close();
rs = md.getColumns(null, null, tableName, lastlocX); rs = md.getColumns(null, null, tableName, col.LASTLOC_X);
if (rs.next()) { if (rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " MODIFY " st.executeUpdate("ALTER TABLE " + tableName + " MODIFY "
+ lastlocX + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY " + col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY "
+ lastlocY + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY " + col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY "
+ lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';"); + col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0';");
} }
rs.close(); rs.close();
rs = md.getColumns(null, null, tableName, lastlocWorld); rs = md.getColumns(null, null, tableName, col.LASTLOC_WORLD);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + lastlocZ); + col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + col.LASTLOC_Z);
} }
rs.close(); rs.close();
rs = md.getColumns(null, null, tableName, columnEmail); rs = md.getColumns(null, null, tableName, col.EMAIL);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ columnEmail + " VARCHAR(255) DEFAULT 'your@email.com' AFTER " + lastlocWorld); + col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com' AFTER " + col.LASTLOC_WORLD);
} }
rs.close(); rs.close();
rs = md.getColumns(null, null, tableName, columnLogged); rs = md.getColumns(null, null, tableName, col.IS_LOGGED);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ columnLogged + " SMALLINT NOT NULL DEFAULT '0' AFTER " + columnEmail); + col.IS_LOGGED + " SMALLINT NOT NULL DEFAULT '0' AFTER " + col.EMAIL);
} }
rs.close(); rs.close();
@ -255,7 +235,7 @@ public class MySQL implements DataSource {
@Override @Override
public synchronized boolean isAuthAvailable(String user) { public synchronized boolean isAuthAvailable(String user) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "SELECT " + columnName + " FROM " + tableName + " WHERE " + columnName + "=?;"; String sql = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.NAME + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, user.toLowerCase()); pst.setString(1, user.toLowerCase());
ResultSet rs = pst.executeQuery(); ResultSet rs = pst.executeQuery();
@ -269,14 +249,14 @@ public class MySQL implements DataSource {
@Override @Override
public HashedPassword getPassword(String user) { public HashedPassword getPassword(String user) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "SELECT " + columnPassword + "," + columnSalt + " FROM " + tableName String sql = "SELECT " + col.PASSWORD + "," + col.SALT + " FROM " + tableName
+ " WHERE " + columnName + "=?;"; + " WHERE " + col.NAME + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, user.toLowerCase()); pst.setString(1, user.toLowerCase());
ResultSet rs = pst.executeQuery(); ResultSet rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
return new HashedPassword(rs.getString(columnPassword), return new HashedPassword(rs.getString(col.PASSWORD),
!columnSalt.isEmpty() ? rs.getString(columnSalt) : null); !col.SALT.isEmpty() ? rs.getString(col.SALT) : null);
} }
} catch (SQLException ex) { } catch (SQLException ex) {
logSqlException(ex); logSqlException(ex);
@ -288,19 +268,19 @@ public class MySQL implements DataSource {
public synchronized PlayerAuth getAuth(String user) { public synchronized PlayerAuth getAuth(String user) {
PlayerAuth pAuth; PlayerAuth pAuth;
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "SELECT * FROM " + tableName + " WHERE " + columnName + "=?;"; String sql = "SELECT * FROM " + tableName + " WHERE " + col.NAME + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, user.toLowerCase()); pst.setString(1, user.toLowerCase());
ResultSet rs = pst.executeQuery(); ResultSet rs = pst.executeQuery();
if (!rs.next()) { if (!rs.next()) {
return null; return null;
} }
int id = rs.getInt(columnID); int id = rs.getInt(col.ID);
pAuth = buildAuthFromResultSet(rs); pAuth = buildAuthFromResultSet(rs);
rs.close(); rs.close();
pst.close(); pst.close();
if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) { if (hashAlgorithm == HashAlgorithm.XFBCRYPT) {
pst = con.prepareStatement("SELECT data FROM xf_user_authenticate WHERE " + columnID + "=?;"); pst = con.prepareStatement("SELECT data FROM xf_user_authenticate WHERE " + col.ID + "=?;");
pst.setInt(1, id); pst.setInt(1, id);
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
@ -324,11 +304,11 @@ public class MySQL implements DataSource {
ResultSet rs; ResultSet rs;
String sql; String sql;
boolean useSalt = !columnSalt.isEmpty() || !StringUtils.isEmpty(auth.getPassword().getSalt()); boolean useSalt = !col.SALT.isEmpty() || !StringUtils.isEmpty(auth.getPassword().getSalt());
sql = "INSERT INTO " + tableName + "(" sql = "INSERT INTO " + tableName + "("
+ columnName + "," + columnPassword + "," + columnIp + "," + col.NAME + "," + col.PASSWORD + "," + col.IP + ","
+ columnLastLogin + "," + columnRealName + "," + columnEmail + col.LAST_LOGIN + "," + col.REAL_NAME + "," + col.EMAIL
+ (useSalt ? "," + columnSalt : "") + (useSalt ? "," + col.SALT : "")
+ ") VALUES (?,?,?,?,?,?" + (useSalt ? ",?" : "") + ");"; + ") VALUES (?,?,?,?,?,?" + (useSalt ? ",?" : "") + ");";
pst = con.prepareStatement(sql); pst = con.prepareStatement(sql);
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
@ -345,7 +325,7 @@ public class MySQL implements DataSource {
if (!columnOthers.isEmpty()) { if (!columnOthers.isEmpty()) {
for (String column : columnOthers) { for (String column : columnOthers) {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + column + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + column + "=? WHERE " + col.NAME + "=?;");
pst.setString(1, auth.getRealName()); pst.setString(1, auth.getRealName());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
@ -353,13 +333,13 @@ public class MySQL implements DataSource {
} }
} }
if (Settings.getPasswordHash == HashAlgorithm.PHPBB) { if (hashAlgorithm == HashAlgorithm.PHPBB) {
sql = "SELECT " + columnID + " FROM " + tableName + " WHERE " + columnName + "=?;"; sql = "SELECT " + col.ID + " FROM " + tableName + " WHERE " + col.NAME + "=?;";
pst = con.prepareStatement(sql); pst = con.prepareStatement(sql);
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
int id = rs.getInt(columnID); int id = rs.getInt(col.ID);
// Insert player in phpbb_user_group // Insert player in phpbb_user_group
sql = "INSERT INTO " + Settings.getPhpbbPrefix sql = "INSERT INTO " + Settings.getPhpbbPrefix
+ "user_group (group_id, user_id, group_leader, user_pending) VALUES (?,?,?,?);"; + "user_group (group_id, user_id, group_leader, user_pending) VALUES (?,?,?,?);";
@ -372,7 +352,7 @@ public class MySQL implements DataSource {
pst2.close(); pst2.close();
// Update username_clean in phpbb_users // Update username_clean in phpbb_users
sql = "UPDATE " + tableName + " SET " + tableName sql = "UPDATE " + tableName + " SET " + tableName
+ ".username_clean=? WHERE " + columnName + "=?;"; + ".username_clean=? WHERE " + col.NAME + "=?;";
pst2 = con.prepareStatement(sql); pst2 = con.prepareStatement(sql);
pst2.setString(1, auth.getNickname()); pst2.setString(1, auth.getNickname());
pst2.setString(2, auth.getNickname()); pst2.setString(2, auth.getNickname());
@ -380,7 +360,7 @@ public class MySQL implements DataSource {
pst2.close(); pst2.close();
// Update player group in phpbb_users // Update player group in phpbb_users
sql = "UPDATE " + tableName + " SET " + tableName sql = "UPDATE " + tableName + " SET " + tableName
+ ".group_id=? WHERE " + columnName + "=?;"; + ".group_id=? WHERE " + col.NAME + "=?;";
pst2 = con.prepareStatement(sql); pst2 = con.prepareStatement(sql);
pst2.setInt(1, Settings.getPhpbbGroup); pst2.setInt(1, Settings.getPhpbbGroup);
pst2.setString(2, auth.getNickname()); pst2.setString(2, auth.getNickname());
@ -390,7 +370,7 @@ public class MySQL implements DataSource {
long time = System.currentTimeMillis() / 1000; long time = System.currentTimeMillis() / 1000;
// Update user_regdate // Update user_regdate
sql = "UPDATE " + tableName + " SET " + tableName sql = "UPDATE " + tableName + " SET " + tableName
+ ".user_regdate=? WHERE " + columnName + "=?;"; + ".user_regdate=? WHERE " + col.NAME + "=?;";
pst2 = con.prepareStatement(sql); pst2 = con.prepareStatement(sql);
pst2.setLong(1, time); pst2.setLong(1, time);
pst2.setString(2, auth.getNickname()); pst2.setString(2, auth.getNickname());
@ -398,7 +378,7 @@ public class MySQL implements DataSource {
pst2.close(); pst2.close();
// Update user_lastvisit // Update user_lastvisit
sql = "UPDATE " + tableName + " SET " + tableName sql = "UPDATE " + tableName + " SET " + tableName
+ ".user_lastvisit=? WHERE " + columnName + "=?;"; + ".user_lastvisit=? WHERE " + col.NAME + "=?;";
pst2 = con.prepareStatement(sql); pst2 = con.prepareStatement(sql);
pst2.setLong(1, time); pst2.setLong(1, time);
pst2.setString(2, auth.getNickname()); pst2.setString(2, auth.getNickname());
@ -413,12 +393,12 @@ public class MySQL implements DataSource {
} }
rs.close(); rs.close();
pst.close(); pst.close();
} else if (Settings.getPasswordHash == HashAlgorithm.WORDPRESS) { } else if (hashAlgorithm == HashAlgorithm.WORDPRESS) {
pst = con.prepareStatement("SELECT " + columnID + " FROM " + tableName + " WHERE " + columnName + "=?;"); pst = con.prepareStatement("SELECT " + col.ID + " FROM " + tableName + " WHERE " + col.NAME + "=?;");
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
int id = rs.getInt(columnID); int id = rs.getInt(col.ID);
sql = "INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"; sql = "INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);";
pst2 = con.prepareStatement(sql); pst2 = con.prepareStatement(sql);
// First Name // First Name
@ -489,12 +469,12 @@ public class MySQL implements DataSource {
} }
rs.close(); rs.close();
pst.close(); pst.close();
} else if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) { } else if (hashAlgorithm == HashAlgorithm.XFBCRYPT) {
pst = con.prepareStatement("SELECT " + columnID + " FROM " + tableName + " WHERE " + columnName + "=?;"); pst = con.prepareStatement("SELECT " + col.ID + " FROM " + tableName + " WHERE " + col.NAME + "=?;");
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
int id = rs.getInt(columnID); int id = rs.getInt(col.ID);
sql = "INSERT INTO xf_user_authenticate (user_id, scheme_class, data) VALUES (?,?,?)"; sql = "INSERT INTO xf_user_authenticate (user_id, scheme_class, data) VALUES (?,?,?)";
pst2 = con.prepareStatement(sql); pst2 = con.prepareStatement(sql);
pst2.setInt(1, id); pst2.setInt(1, id);
@ -526,33 +506,33 @@ public class MySQL implements DataSource {
public boolean updatePassword(String user, HashedPassword password) { public boolean updatePassword(String user, HashedPassword password) {
user = user.toLowerCase(); user = user.toLowerCase();
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
boolean useSalt = !columnSalt.isEmpty(); boolean useSalt = !col.SALT.isEmpty();
PreparedStatement pst; PreparedStatement pst;
if (useSalt) { if (useSalt) {
String sql = String.format("UPDATE %s SET %s = ?, %s = ? WHERE %s = ?;", String sql = String.format("UPDATE %s SET %s = ?, %s = ? WHERE %s = ?;",
tableName, columnPassword, columnSalt, columnName); tableName, col.PASSWORD, col.SALT, col.NAME);
pst = con.prepareStatement(sql); pst = con.prepareStatement(sql);
pst.setString(1, password.getHash()); pst.setString(1, password.getHash());
pst.setString(2, password.getSalt()); pst.setString(2, password.getSalt());
pst.setString(3, user); pst.setString(3, user);
} else { } else {
String sql = String.format("UPDATE %s SET %s = ? WHERE %s = ?;", String sql = String.format("UPDATE %s SET %s = ? WHERE %s = ?;",
tableName, columnPassword, columnName); tableName, col.PASSWORD, col.NAME);
pst = con.prepareStatement(sql); pst = con.prepareStatement(sql);
pst.setString(1, password.getHash()); pst.setString(1, password.getHash());
pst.setString(2, user); pst.setString(2, user);
} }
pst.executeUpdate(); pst.executeUpdate();
pst.close(); pst.close();
if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) { if (hashAlgorithm == HashAlgorithm.XFBCRYPT) {
String sql = "SELECT " + columnID + " FROM " + tableName + " WHERE " + columnName + "=?;"; String sql = "SELECT " + col.ID + " FROM " + tableName + " WHERE " + col.NAME + "=?;";
pst = con.prepareStatement(sql); pst = con.prepareStatement(sql);
pst.setString(1, user); pst.setString(1, user);
ResultSet rs = pst.executeQuery(); ResultSet rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
int id = rs.getInt(columnID); int id = rs.getInt(col.ID);
// Insert password in the correct table // Insert password in the correct table
sql = "UPDATE xf_user_authenticate SET data=? WHERE " + columnID + "=?;"; sql = "UPDATE xf_user_authenticate SET data=? WHERE " + col.ID + "=?;";
PreparedStatement pst2 = con.prepareStatement(sql); PreparedStatement pst2 = con.prepareStatement(sql);
String serializedHash = XFBCRYPT.serializeHash(password.getHash()); String serializedHash = XFBCRYPT.serializeHash(password.getHash());
byte[] bytes = serializedHash.getBytes(); byte[] bytes = serializedHash.getBytes();
@ -563,7 +543,7 @@ public class MySQL implements DataSource {
pst2.executeUpdate(); pst2.executeUpdate();
pst2.close(); pst2.close();
// ... // ...
sql = "UPDATE xf_user_authenticate SET scheme_class=? WHERE " + columnID + "=?;"; sql = "UPDATE xf_user_authenticate SET scheme_class=? WHERE " + col.ID + "=?;";
pst2 = con.prepareStatement(sql); pst2 = con.prepareStatement(sql);
pst2.setString(1, XFBCRYPT.SCHEME_CLASS); pst2.setString(1, XFBCRYPT.SCHEME_CLASS);
pst2.setInt(2, id); pst2.setInt(2, id);
@ -584,7 +564,7 @@ public class MySQL implements DataSource {
public synchronized boolean updateSession(PlayerAuth auth) { public synchronized boolean updateSession(PlayerAuth auth) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "UPDATE " + tableName + " SET " String sql = "UPDATE " + tableName + " SET "
+ columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE " + columnName + "=?;"; + col.IP + "=?, " + col.LAST_LOGIN + "=?, " + col.REAL_NAME + "=? WHERE " + col.NAME + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, auth.getIp()); pst.setString(1, auth.getIp());
pst.setTimestamp(2, new Timestamp(auth.getLastLogin())); pst.setTimestamp(2, new Timestamp(auth.getLastLogin()));
@ -603,7 +583,7 @@ public class MySQL implements DataSource {
public synchronized int purgeDatabase(long until) { public synchronized int purgeDatabase(long until) {
int result = 0; int result = 0;
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;"; String sql = "DELETE FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setLong(1, until); pst.setLong(1, until);
result = pst.executeUpdate(); result = pst.executeUpdate();
@ -617,15 +597,15 @@ public class MySQL implements DataSource {
public synchronized List<String> autoPurgeDatabase(long until) { public synchronized List<String> autoPurgeDatabase(long until) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "SELECT " + columnName + " FROM " + tableName + " WHERE " + columnLastLogin + "<?;"; String sql = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
PreparedStatement st = con.prepareStatement(sql); PreparedStatement st = con.prepareStatement(sql);
st.setLong(1, until); st.setLong(1, until);
ResultSet rs = st.executeQuery(); ResultSet rs = st.executeQuery();
while (rs.next()) { while (rs.next()) {
list.add(rs.getString(columnName)); list.add(rs.getString(col.NAME));
} }
rs.close(); rs.close();
sql = "DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;"; sql = "DELETE FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
st = con.prepareStatement(sql); st = con.prepareStatement(sql);
st.setLong(1, until); st.setLong(1, until);
st.executeUpdate(); st.executeUpdate();
@ -642,14 +622,14 @@ public class MySQL implements DataSource {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql; String sql;
PreparedStatement pst; PreparedStatement pst;
if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) { if (hashAlgorithm == HashAlgorithm.XFBCRYPT) {
sql = "SELECT " + columnID + " FROM " + tableName + " WHERE " + columnName + "=?;"; sql = "SELECT " + col.ID + " FROM " + tableName + " WHERE " + col.NAME + "=?;";
pst = con.prepareStatement(sql); pst = con.prepareStatement(sql);
pst.setString(1, user); pst.setString(1, user);
ResultSet rs = pst.executeQuery(); ResultSet rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
int id = rs.getInt(columnID); int id = rs.getInt(col.ID);
sql = "DELETE FROM xf_user_authenticate WHERE " + columnID + "=?;"; sql = "DELETE FROM xf_user_authenticate WHERE " + col.ID + "=?;";
PreparedStatement st = con.prepareStatement(sql); PreparedStatement st = con.prepareStatement(sql);
st.setInt(1, id); st.setInt(1, id);
st.executeUpdate(); st.executeUpdate();
@ -658,7 +638,7 @@ public class MySQL implements DataSource {
rs.close(); rs.close();
pst.close(); pst.close();
} }
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;");
pst.setString(1, user); pst.setString(1, user);
pst.executeUpdate(); pst.executeUpdate();
return true; return true;
@ -672,8 +652,8 @@ public class MySQL implements DataSource {
public synchronized boolean updateQuitLoc(PlayerAuth auth) { public synchronized boolean updateQuitLoc(PlayerAuth auth) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "UPDATE " + tableName String sql = "UPDATE " + tableName
+ " SET " + lastlocX + " =?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=?" + " SET " + col.LASTLOC_X + " =?, " + col.LASTLOC_Y + "=?, " + col.LASTLOC_Z + "=?, " + col.LASTLOC_WORLD + "=?"
+ " WHERE " + columnName + "=?;"; + " WHERE " + col.NAME + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setDouble(1, auth.getQuitLocX()); pst.setDouble(1, auth.getQuitLocX());
pst.setDouble(2, auth.getQuitLocY()); pst.setDouble(2, auth.getQuitLocY());
@ -693,7 +673,7 @@ public class MySQL implements DataSource {
public synchronized int getIps(String ip) { public synchronized int getIps(String ip) {
int countIp = 0; int countIp = 0;
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "SELECT COUNT(*) FROM " + tableName + " WHERE " + columnIp + "=?;"; String sql = "SELECT COUNT(*) FROM " + tableName + " WHERE " + col.IP + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, ip); pst.setString(1, ip);
ResultSet rs = pst.executeQuery(); ResultSet rs = pst.executeQuery();
@ -711,7 +691,7 @@ public class MySQL implements DataSource {
@Override @Override
public synchronized boolean updateEmail(PlayerAuth auth) { public synchronized boolean updateEmail(PlayerAuth auth) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "UPDATE " + tableName + " SET " + columnEmail + " =? WHERE " + columnName + "=?;"; String sql = "UPDATE " + tableName + " SET " + col.EMAIL + " =? WHERE " + col.NAME + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, auth.getEmail()); pst.setString(1, auth.getEmail());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
@ -746,12 +726,12 @@ public class MySQL implements DataSource {
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) { public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "SELECT " + columnName + " FROM " + tableName + " WHERE " + columnIp + "=?;"; String sql = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.IP + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, auth.getIp()); pst.setString(1, auth.getIp());
ResultSet rs = pst.executeQuery(); ResultSet rs = pst.executeQuery();
while (rs.next()) { while (rs.next()) {
result.add(rs.getString(columnName)); result.add(rs.getString(col.NAME));
} }
rs.close(); rs.close();
pst.close(); pst.close();
@ -765,12 +745,12 @@ public class MySQL implements DataSource {
public synchronized List<String> getAllAuthsByIp(String ip) { public synchronized List<String> getAllAuthsByIp(String ip) {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "SELECT " + columnName + " FROM " + tableName + " WHERE " + columnIp + "=?;"; String sql = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.IP + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, ip); pst.setString(1, ip);
ResultSet rs = pst.executeQuery(); ResultSet rs = pst.executeQuery();
while (rs.next()) { while (rs.next()) {
result.add(rs.getString(columnName)); result.add(rs.getString(col.NAME));
} }
rs.close(); rs.close();
pst.close(); pst.close();
@ -784,12 +764,12 @@ public class MySQL implements DataSource {
public synchronized List<String> getAllAuthsByEmail(String email) { public synchronized List<String> getAllAuthsByEmail(String email) {
List<String> countEmail = new ArrayList<>(); List<String> countEmail = new ArrayList<>();
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "SELECT " + columnName + " FROM " + tableName + " WHERE " + columnEmail + "=?;"; String sql = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.EMAIL + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, email); pst.setString(1, email);
ResultSet rs = pst.executeQuery(); ResultSet rs = pst.executeQuery();
while (rs.next()) { while (rs.next()) {
countEmail.add(rs.getString(columnName)); countEmail.add(rs.getString(col.NAME));
} }
rs.close(); rs.close();
pst.close(); pst.close();
@ -802,7 +782,7 @@ public class MySQL implements DataSource {
@Override @Override
public synchronized void purgeBanned(List<String> banned) { public synchronized void purgeBanned(List<String> banned) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); PreparedStatement pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;");
for (String name : banned) { for (String name : banned) {
pst.setString(1, name); pst.setString(1, name);
pst.executeUpdate(); pst.executeUpdate();
@ -822,11 +802,11 @@ public class MySQL implements DataSource {
public boolean isLogged(String user) { public boolean isLogged(String user) {
boolean isLogged = false; boolean isLogged = false;
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "SELECT " + columnLogged + " FROM " + tableName + " WHERE " + columnName + "=?;"; String sql = "SELECT " + col.IS_LOGGED + " FROM " + tableName + " WHERE " + col.NAME + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, user); pst.setString(1, user);
ResultSet rs = pst.executeQuery(); ResultSet rs = pst.executeQuery();
isLogged = rs.next() && (rs.getInt(columnLogged) == 1); isLogged = rs.next() && (rs.getInt(col.IS_LOGGED) == 1);
} catch (SQLException ex) { } catch (SQLException ex) {
logSqlException(ex); logSqlException(ex);
} }
@ -836,7 +816,7 @@ public class MySQL implements DataSource {
@Override @Override
public void setLogged(String user) { public void setLogged(String user) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnName + "=?;"; String sql = "UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE " + col.NAME + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setInt(1, 1); pst.setInt(1, 1);
pst.setString(2, user.toLowerCase()); pst.setString(2, user.toLowerCase());
@ -850,7 +830,7 @@ public class MySQL implements DataSource {
@Override @Override
public void setUnlogged(String user) { public void setUnlogged(String user) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnName + "=?;"; String sql = "UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE " + col.NAME + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setInt(1, 0); pst.setInt(1, 0);
pst.setString(2, user.toLowerCase()); pst.setString(2, user.toLowerCase());
@ -864,7 +844,7 @@ public class MySQL implements DataSource {
@Override @Override
public void purgeLogged() { public void purgeLogged() {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;"; String sql = "UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE " + col.IS_LOGGED + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setInt(1, 0); pst.setInt(1, 0);
pst.setInt(2, 1); pst.setInt(2, 1);
@ -895,7 +875,7 @@ public class MySQL implements DataSource {
@Override @Override
public void updateName(String oldOne, String newOne) { public void updateName(String oldOne, String newOne) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql = "UPDATE " + tableName + " SET " + columnName + "=? WHERE " + columnName + "=?;"; String sql = "UPDATE " + tableName + " SET " + col.NAME + "=? WHERE " + col.NAME + "=?;";
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, newOne); pst.setString(1, newOne);
pst.setString(2, oldOne); pst.setString(2, oldOne);
@ -911,11 +891,11 @@ public class MySQL implements DataSource {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
Statement st = con.createStatement(); Statement st = con.createStatement();
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 " + col.ID + "=?;");
while (rs.next()) { while (rs.next()) {
PlayerAuth pAuth = buildAuthFromResultSet(rs); PlayerAuth pAuth = buildAuthFromResultSet(rs);
if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) { if (hashAlgorithm == HashAlgorithm.XFBCRYPT) {
int id = rs.getInt(columnID); int id = rs.getInt(col.ID);
pst.setInt(1, id); pst.setInt(1, id);
ResultSet rs2 = pst.executeQuery(); ResultSet rs2 = pst.executeQuery();
if (rs2.next()) { if (rs2.next()) {
@ -941,12 +921,12 @@ public class MySQL implements DataSource {
List<PlayerAuth> auths = new ArrayList<>(); List<PlayerAuth> auths = new ArrayList<>();
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
Statement st = con.createStatement(); Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;"); ResultSet rs = st.executeQuery("SELECT * FROM " + tableName + " WHERE " + col.IS_LOGGED + "=1;");
PreparedStatement pst = con.prepareStatement("SELECT data FROM xf_user_authenticate WHERE " + columnID + "=?;"); PreparedStatement pst = con.prepareStatement("SELECT data FROM xf_user_authenticate WHERE " + col.ID + "=?;");
while (rs.next()) { while (rs.next()) {
PlayerAuth pAuth = buildAuthFromResultSet(rs); PlayerAuth pAuth = buildAuthFromResultSet(rs);
if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) { if (hashAlgorithm == HashAlgorithm.XFBCRYPT) {
int id = rs.getInt(columnID); int id = rs.getInt(col.ID);
pst.setInt(1, id); pst.setInt(1, id);
ResultSet rs2 = pst.executeQuery(); ResultSet rs2 = pst.executeQuery();
if (rs2.next()) { if (rs2.next()) {
@ -966,7 +946,7 @@ public class MySQL implements DataSource {
@Override @Override
public synchronized boolean isEmailStored(String email) { public synchronized boolean isEmailStored(String email) {
String sql = "SELECT 1 FROM " + tableName + " WHERE " + columnEmail + " = ?"; String sql = "SELECT 1 FROM " + tableName + " WHERE " + col.EMAIL + " = ?";
try (Connection con = ds.getConnection()) { try (Connection con = ds.getConnection()) {
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, email); pst.setString(1, email);
@ -979,19 +959,19 @@ public class MySQL implements DataSource {
} }
private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException { private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {
String salt = columnSalt.isEmpty() ? null : row.getString(columnSalt); String salt = col.SALT.isEmpty() ? null : row.getString(col.SALT);
int group = columnGroup.isEmpty() ? -1 : row.getInt(columnGroup); int group = col.GROUP.isEmpty() ? -1 : row.getInt(col.GROUP);
return PlayerAuth.builder() return PlayerAuth.builder()
.name(row.getString(columnName)) .name(row.getString(col.NAME))
.realName(row.getString(columnRealName)) .realName(row.getString(col.REAL_NAME))
.password(row.getString(columnPassword), salt) .password(row.getString(col.PASSWORD), salt)
.lastLogin(safeGetTimestamp(row)) .lastLogin(safeGetTimestamp(row))
.ip(row.getString(columnIp)) .ip(row.getString(col.IP))
.locWorld(row.getString(lastlocWorld)) .locWorld(row.getString(col.LASTLOC_WORLD))
.locX(row.getDouble(lastlocX)) .locX(row.getDouble(col.LASTLOC_X))
.locY(row.getDouble(lastlocY)) .locY(row.getDouble(col.LASTLOC_Y))
.locZ(row.getDouble(lastlocZ)) .locZ(row.getDouble(col.LASTLOC_Z))
.email(row.getString(columnEmail)) .email(row.getString(col.EMAIL))
.groupId(group) .groupId(group)
.build(); .build();
} }
@ -1004,7 +984,7 @@ public class MySQL implements DataSource {
*/ */
private long safeGetTimestamp(ResultSet row) { private long safeGetTimestamp(ResultSet row) {
try { try {
return row.getTimestamp(columnLastLogin).getTime(); return row.getTimestamp(col.LAST_LOGIN).getTime();
} catch (SQLException e) { } catch (SQLException e) {
ConsoleLogger.logException("Could not get timestamp from resultSet. Defaulting to current time", e); ConsoleLogger.logException("Could not get timestamp from resultSet. Defaulting to current time", e);
} }
@ -1015,23 +995,23 @@ public class MySQL implements DataSource {
final int columnType = rs.getInt("DATA_TYPE"); final int columnType = rs.getInt("DATA_TYPE");
if (columnType == Types.BIGINT) { if (columnType == Types.BIGINT) {
ConsoleLogger.info("Migrating lastlogin column from bigint to timestamp"); ConsoleLogger.info("Migrating lastlogin column from bigint to timestamp");
final String lastLoginOld = columnLastLogin + "_old"; final String lastLoginOld = col.LAST_LOGIN + "_old";
// Rename lastlogin to lastlogin_old // Rename lastlogin to lastlogin_old
String sql = String.format("ALTER TABLE %s CHANGE COLUMN %s %s BIGINT", String sql = String.format("ALTER TABLE %s CHANGE COLUMN %s %s BIGINT",
tableName, columnLastLogin, lastLoginOld); tableName, col.LAST_LOGIN, lastLoginOld);
PreparedStatement pst = con.prepareStatement(sql); PreparedStatement pst = con.prepareStatement(sql);
pst.execute(); pst.execute();
// Create lastlogin column // Create lastlogin column
sql = String.format("ALTER TABLE %s ADD COLUMN %s " + sql = String.format("ALTER TABLE %s ADD COLUMN %s "
"TIMESTAMP NOT NULL DEFAULT current_timestamp AFTER %s", + "TIMESTAMP NOT NULL DEFAULT current_timestamp AFTER %s",
tableName, columnLastLogin, columnIp); tableName, col.LAST_LOGIN, col.IP);
con.prepareStatement(sql).execute(); con.prepareStatement(sql).execute();
// Set values of lastlogin based on lastlogin_old // Set values of lastlogin based on lastlogin_old
sql = String.format("UPDATE %s SET %s = FROM_UNIXTIME(%s)", sql = String.format("UPDATE %s SET %s = FROM_UNIXTIME(%s)",
tableName, columnLastLogin, lastLoginOld); tableName, col.LAST_LOGIN, lastLoginOld);
con.prepareStatement(sql).execute(); con.prepareStatement(sql).execute();
// Drop lastlogin_old // Drop lastlogin_old

View File

@ -3,7 +3,9 @@ package fr.xephi.authme.datasource;
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.security.crypts.HashedPassword; import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.DatabaseSettings;
import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.StringUtils;
import java.sql.Connection; import java.sql.Connection;
@ -21,21 +23,8 @@ public class SQLite implements DataSource {
private final String database; private final String database;
private final String tableName; private final String tableName;
private final String columnName; private final Columns col;
private final String columnPassword;
private final String columnIp;
private final String columnLastLogin;
private final String columnSalt;
private final String columnGroup;
private final String lastlocX;
private final String lastlocY;
private final String lastlocZ;
private final String lastlocWorld;
private final String columnEmail;
private final String columnID;
private Connection con; private Connection con;
private final String columnLogged;
private final String columnRealName;
/** /**
* Constructor for SQLite. * Constructor for SQLite.
@ -43,23 +32,10 @@ public class SQLite implements DataSource {
* @throws ClassNotFoundException Exception * @throws ClassNotFoundException Exception
* @throws SQLException Exception * @throws SQLException Exception
*/ */
public SQLite() throws ClassNotFoundException, SQLException { public SQLite(NewSetting settings) throws ClassNotFoundException, SQLException {
this.database = Settings.getMySQLDatabase; this.database = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
this.tableName = Settings.getMySQLTablename; this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
this.columnName = Settings.getMySQLColumnName; this.col = new Columns(settings);
this.columnPassword = Settings.getMySQLColumnPassword;
this.columnIp = Settings.getMySQLColumnIp;
this.columnLastLogin = Settings.getMySQLColumnLastLogin;
this.columnSalt = Settings.getMySQLColumnSalt;
this.columnGroup = Settings.getMySQLColumnGroup;
this.lastlocX = Settings.getMySQLlastlocX;
this.lastlocY = Settings.getMySQLlastlocY;
this.lastlocZ = Settings.getMySQLlastlocZ;
this.lastlocWorld = Settings.getMySQLlastlocWorld;
this.columnEmail = Settings.getMySQLColumnEmail;
this.columnID = Settings.getMySQLColumnId;
this.columnLogged = Settings.getMySQLColumnLogged;
this.columnRealName = Settings.getMySQLColumnRealName;
try { try {
this.connect(); this.connect();
@ -82,54 +58,54 @@ public class SQLite implements DataSource {
ResultSet rs = null; ResultSet rs = null;
try { try {
st = con.createStatement(); st = con.createStatement();
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL," + columnLastLogin + " BIGINT," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));"); st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + col.ID + " INTEGER AUTO_INCREMENT," + col.NAME + " VARCHAR(255) NOT NULL UNIQUE," + col.PASSWORD + " VARCHAR(255) NOT NULL," + col.IP + " VARCHAR(40) NOT NULL," + col.LAST_LOGIN + " BIGINT," + col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0'," + col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0'," + col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0'," + col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + col.ID + "));");
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword); rs = con.getMetaData().getColumns(null, null, tableName, col.PASSWORD);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnPassword + " VARCHAR(255) NOT NULL;"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.PASSWORD + " VARCHAR(255) NOT NULL;");
} }
rs.close(); rs.close();
if (!columnSalt.isEmpty()) { if (!col.SALT.isEmpty()) {
rs = con.getMetaData().getColumns(null, null, tableName, columnSalt); rs = con.getMetaData().getColumns(null, null, tableName, col.SALT);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnSalt + " VARCHAR(255);"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.SALT + " VARCHAR(255);");
} }
rs.close(); rs.close();
} }
rs = con.getMetaData().getColumns(null, null, tableName, columnIp); rs = con.getMetaData().getColumns(null, null, tableName, col.IP);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnIp + " VARCHAR(40) NOT NULL;"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.IP + " VARCHAR(40) NOT NULL;");
} }
rs.close(); rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin); rs = con.getMetaData().getColumns(null, null, tableName, col.LAST_LOGIN);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " TIMESTAMP DEFAULT current_timestamp;"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.LAST_LOGIN + " TIMESTAMP DEFAULT current_timestamp;");
} }
rs.close(); rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); rs = con.getMetaData().getColumns(null, null, tableName, col.LASTLOC_X);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0';"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0';");
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0';"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0';");
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0';");
} }
rs.close(); rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld); rs = con.getMetaData().getColumns(null, null, tableName, col.LASTLOC_WORLD);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world';"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT 'world';");
} }
rs.close(); rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, columnEmail); rs = con.getMetaData().getColumns(null, null, tableName, col.EMAIL);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com';");
} }
rs.close(); rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, columnLogged); rs = con.getMetaData().getColumns(null, null, tableName, col.IS_LOGGED);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLogged + " INT DEFAULT '0';"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.IS_LOGGED + " INT DEFAULT '0';");
} }
rs.close(); rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, columnRealName); rs = con.getMetaData().getColumns(null, null, tableName, col.REAL_NAME);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnRealName + " VARCHAR(255) NOT NULL DEFAULT 'Player';"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.REAL_NAME + " VARCHAR(255) NOT NULL DEFAULT 'Player';");
} }
} finally { } finally {
close(rs); close(rs);
@ -143,7 +119,7 @@ public class SQLite implements DataSource {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + col.NAME + ")=LOWER(?);");
pst.setString(1, user); pst.setString(1, user);
rs = pst.executeQuery(); rs = pst.executeQuery();
return rs.next(); return rs.next();
@ -161,13 +137,13 @@ public class SQLite implements DataSource {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
pst = con.prepareStatement("SELECT " + columnPassword + "," + columnSalt pst = con.prepareStatement("SELECT " + col.PASSWORD + "," + col.SALT
+ " FROM " + tableName + " WHERE " + columnName + "=?"); + " FROM " + tableName + " WHERE " + col.NAME + "=?");
pst.setString(1, user); pst.setString(1, user);
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
return new HashedPassword(rs.getString(columnPassword), return new HashedPassword(rs.getString(col.PASSWORD),
!columnSalt.isEmpty() ? rs.getString(columnSalt) : null); !col.SALT.isEmpty() ? rs.getString(col.SALT) : null);
} }
} catch (SQLException ex) { } catch (SQLException ex) {
logSqlException(ex); logSqlException(ex);
@ -183,7 +159,7 @@ public class SQLite implements DataSource {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + col.NAME + ")=LOWER(?);");
pst.setString(1, user); pst.setString(1, user);
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
@ -205,13 +181,13 @@ public class SQLite implements DataSource {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
HashedPassword password = auth.getPassword(); HashedPassword password = auth.getPassword();
if (columnSalt.isEmpty()) { if (col.SALT.isEmpty()) {
if (!StringUtils.isEmpty(auth.getPassword().getSalt())) { if (!StringUtils.isEmpty(auth.getPassword().getSalt())) {
ConsoleLogger.showError("Warning! Detected hashed password with separate salt but the salt column " ConsoleLogger.showError("Warning! Detected hashed password with separate salt but the salt column "
+ "is not set in the config!"); + "is not set in the config!");
} }
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + pst = con.prepareStatement("INSERT INTO " + tableName + "(" + col.NAME + "," + col.PASSWORD +
"," + columnIp + "," + columnLastLogin + "," + columnRealName + "," + columnEmail + "," + col.IP + "," + col.LAST_LOGIN + "," + col.REAL_NAME + "," + col.EMAIL +
") VALUES (?,?,?,?,?,?);"); ") VALUES (?,?,?,?,?,?);");
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
pst.setString(2, password.getHash()); pst.setString(2, password.getHash());
@ -221,8 +197,8 @@ public class SQLite implements DataSource {
pst.setString(6, auth.getEmail()); pst.setString(6, auth.getEmail());
pst.executeUpdate(); pst.executeUpdate();
} else { } else {
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," pst = con.prepareStatement("INSERT INTO " + tableName + "(" + col.NAME + "," + col.PASSWORD + ","
+ columnIp + "," + columnLastLogin + "," + columnRealName + "," + columnEmail + "," + columnSalt + col.IP + "," + col.LAST_LOGIN + "," + col.REAL_NAME + "," + col.EMAIL + "," + col.SALT
+ ") VALUES (?,?,?,?,?,?,?);"); + ") VALUES (?,?,?,?,?,?,?);");
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
pst.setString(2, password.getHash()); pst.setString(2, password.getHash());
@ -252,10 +228,10 @@ public class SQLite implements DataSource {
user = user.toLowerCase(); user = user.toLowerCase();
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
boolean useSalt = !columnSalt.isEmpty(); boolean useSalt = !col.SALT.isEmpty();
String sql = "UPDATE " + tableName + " SET " + columnPassword + " = ?" String sql = "UPDATE " + tableName + " SET " + col.PASSWORD + " = ?"
+ (useSalt ? ", " + columnSalt + " = ?" : "") + (useSalt ? ", " + col.SALT + " = ?" : "")
+ " WHERE " + columnName + " = ?"; + " WHERE " + col.NAME + " = ?";
pst = con.prepareStatement(sql); pst = con.prepareStatement(sql);
pst.setString(1, password.getHash()); pst.setString(1, password.getHash());
if (useSalt) { if (useSalt) {
@ -278,7 +254,7 @@ public class SQLite implements DataSource {
public boolean updateSession(PlayerAuth auth) { public boolean updateSession(PlayerAuth auth) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + col.IP + "=?, " + col.LAST_LOGIN + "=?, " + col.REAL_NAME + "=? WHERE " + col.NAME + "=?;");
pst.setString(1, auth.getIp()); pst.setString(1, auth.getIp());
pst.setLong(2, auth.getLastLogin()); pst.setLong(2, auth.getLastLogin());
pst.setString(3, auth.getRealName()); pst.setString(3, auth.getRealName());
@ -298,7 +274,7 @@ public class SQLite implements DataSource {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;");
pst.setLong(1, until); pst.setLong(1, until);
return pst.executeUpdate(); return pst.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
@ -315,11 +291,11 @@ public class SQLite implements DataSource {
ResultSet rs = null; ResultSet rs = null;
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;");
pst.setLong(1, until); pst.setLong(1, until);
rs = pst.executeQuery(); rs = pst.executeQuery();
while (rs.next()) { while (rs.next()) {
list.add(rs.getString(columnName)); list.add(rs.getString(col.NAME));
} }
return list; return list;
} catch (SQLException ex) { } catch (SQLException ex) {
@ -335,7 +311,7 @@ public class SQLite implements DataSource {
public synchronized boolean removeAuth(String user) { public synchronized boolean removeAuth(String user) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;");
pst.setString(1, user); pst.setString(1, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
@ -351,7 +327,7 @@ public class SQLite implements DataSource {
public boolean updateQuitLoc(PlayerAuth auth) { public boolean updateQuitLoc(PlayerAuth auth) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + "=?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + col.LASTLOC_X + "=?, " + col.LASTLOC_Y + "=?, " + col.LASTLOC_Z + "=?, " + col.LASTLOC_WORLD + "=? WHERE " + col.NAME + "=?;");
pst.setDouble(1, auth.getQuitLocX()); pst.setDouble(1, auth.getQuitLocX());
pst.setDouble(2, auth.getQuitLocY()); pst.setDouble(2, auth.getQuitLocY());
pst.setDouble(3, auth.getQuitLocZ()); pst.setDouble(3, auth.getQuitLocZ());
@ -374,7 +350,7 @@ public class SQLite implements DataSource {
int countIp = 0; int countIp = 0;
try { try {
// TODO ljacqu 20151230: Simply fetch COUNT(1) and return that // TODO ljacqu 20151230: Simply fetch COUNT(1) and return that
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + col.IP + "=?;");
pst.setString(1, ip); pst.setString(1, ip);
rs = pst.executeQuery(); rs = pst.executeQuery();
while (rs.next()) { while (rs.next()) {
@ -394,7 +370,7 @@ public class SQLite implements DataSource {
public boolean updateEmail(PlayerAuth auth) { public boolean updateEmail(PlayerAuth auth) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + col.EMAIL + "=? WHERE " + col.NAME + "=?;");
pst.setString(1, auth.getEmail()); pst.setString(1, auth.getEmail());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
@ -446,11 +422,11 @@ public class SQLite implements DataSource {
ResultSet rs = null; ResultSet rs = null;
List<String> countIp = new ArrayList<>(); List<String> countIp = new ArrayList<>();
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + col.IP + "=?;");
pst.setString(1, auth.getIp()); pst.setString(1, auth.getIp());
rs = pst.executeQuery(); rs = pst.executeQuery();
while (rs.next()) { while (rs.next()) {
countIp.add(rs.getString(columnName)); countIp.add(rs.getString(col.NAME));
} }
return countIp; return countIp;
} catch (SQLException ex) { } catch (SQLException ex) {
@ -470,11 +446,11 @@ public class SQLite implements DataSource {
ResultSet rs = null; ResultSet rs = null;
List<String> countIp = new ArrayList<>(); List<String> countIp = new ArrayList<>();
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + col.IP + "=?;");
pst.setString(1, ip); pst.setString(1, ip);
rs = pst.executeQuery(); rs = pst.executeQuery();
while (rs.next()) { while (rs.next()) {
countIp.add(rs.getString(columnName)); countIp.add(rs.getString(col.NAME));
} }
return countIp; return countIp;
} catch (SQLException ex) { } catch (SQLException ex) {
@ -494,11 +470,11 @@ public class SQLite implements DataSource {
ResultSet rs = null; ResultSet rs = null;
List<String> countEmail = new ArrayList<>(); List<String> countEmail = new ArrayList<>();
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + col.EMAIL + "=?;");
pst.setString(1, email); pst.setString(1, email);
rs = pst.executeQuery(); rs = pst.executeQuery();
while (rs.next()) { while (rs.next()) {
countEmail.add(rs.getString(columnName)); countEmail.add(rs.getString(col.NAME));
} }
return countEmail; return countEmail;
} catch (SQLException ex) { } catch (SQLException ex) {
@ -517,7 +493,7 @@ public class SQLite implements DataSource {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
for (String name : banned) { for (String name : banned) {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;");
pst.setString(1, name); pst.setString(1, name);
pst.executeUpdate(); pst.executeUpdate();
} }
@ -538,11 +514,11 @@ public class SQLite implements DataSource {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + col.NAME + ")=?;");
pst.setString(1, user); pst.setString(1, user);
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) if (rs.next())
return (rs.getInt(columnLogged) == 1); return (rs.getInt(col.IS_LOGGED) == 1);
} catch (SQLException ex) { } catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
@ -557,7 +533,7 @@ public class SQLite implements DataSource {
public void setLogged(String user) { public void setLogged(String user) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE LOWER(" + col.NAME + ")=?;");
pst.setInt(1, 1); pst.setInt(1, 1);
pst.setString(2, user); pst.setString(2, user);
pst.executeUpdate(); pst.executeUpdate();
@ -573,7 +549,7 @@ public class SQLite implements DataSource {
PreparedStatement pst = null; PreparedStatement pst = null;
if (user != null) if (user != null)
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE LOWER(" + col.NAME + ")=?;");
pst.setInt(1, 0); pst.setInt(1, 0);
pst.setString(2, user); pst.setString(2, user);
pst.executeUpdate(); pst.executeUpdate();
@ -588,7 +564,7 @@ public class SQLite implements DataSource {
public void purgeLogged() { public void purgeLogged() {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE " + col.IS_LOGGED + "=?;");
pst.setInt(1, 0); pst.setInt(1, 0);
pst.setInt(2, 1); pst.setInt(2, 1);
pst.executeUpdate(); pst.executeUpdate();
@ -623,7 +599,7 @@ public class SQLite implements DataSource {
public void updateName(String oldOne, String newOne) { public void updateName(String oldOne, String newOne) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + col.NAME + "=? WHERE " + col.NAME + "=?;");
pst.setString(1, newOne); pst.setString(1, newOne);
pst.setString(2, oldOne); pst.setString(2, oldOne);
pst.executeUpdate(); pst.executeUpdate();
@ -661,7 +637,7 @@ public class SQLite implements DataSource {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs; ResultSet rs;
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + col.IS_LOGGED + "=1;");
rs = pst.executeQuery(); rs = pst.executeQuery();
while (rs.next()) { while (rs.next()) {
PlayerAuth auth = buildAuthFromResultSet(rs); PlayerAuth auth = buildAuthFromResultSet(rs);
@ -678,7 +654,7 @@ public class SQLite implements DataSource {
@Override @Override
public synchronized boolean isEmailStored(String email) { public synchronized boolean isEmailStored(String email) {
String sql = "SELECT 1 FROM " + tableName + " WHERE " + columnEmail + " = ? COLLATE NOCASE;"; String sql = "SELECT 1 FROM " + tableName + " WHERE " + col.EMAIL + " = ? COLLATE NOCASE;";
ResultSet rs = null; ResultSet rs = null;
try (PreparedStatement ps = con.prepareStatement(sql)) { try (PreparedStatement ps = con.prepareStatement(sql)) {
ps.setString(1, email); ps.setString(1, email);
@ -698,20 +674,20 @@ public class SQLite implements DataSource {
} }
private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException { private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {
String salt = !columnSalt.isEmpty() ? row.getString(columnSalt) : null; String salt = !col.SALT.isEmpty() ? row.getString(col.SALT) : null;
PlayerAuth.Builder authBuilder = PlayerAuth.builder() PlayerAuth.Builder authBuilder = PlayerAuth.builder()
.name(row.getString(columnName)) .name(row.getString(col.NAME))
.email(row.getString(columnEmail)) .email(row.getString(col.EMAIL))
.realName(row.getString(columnRealName)) .realName(row.getString(col.REAL_NAME))
.password(row.getString(columnPassword), salt) .password(row.getString(col.PASSWORD), salt)
.lastLogin(row.getLong(columnLastLogin)) .lastLogin(row.getLong(col.LAST_LOGIN))
.locX(row.getDouble(lastlocX)) .locX(row.getDouble(col.LASTLOC_X))
.locY(row.getDouble(lastlocY)) .locY(row.getDouble(col.LASTLOC_Y))
.locZ(row.getDouble(lastlocZ)) .locZ(row.getDouble(col.LASTLOC_Z))
.locWorld(row.getString(lastlocWorld)); .locWorld(row.getString(col.LASTLOC_WORLD));
String ip = row.getString(columnIp); String ip = row.getString(col.IP);
if (!ip.isEmpty()) { if (!ip.isEmpty()) {
authBuilder.ip(ip); authBuilder.ip(ip);
} }

View File

@ -32,7 +32,6 @@ public final class Settings {
public static List<String> getJoinPermissions; public static List<String> getJoinPermissions;
public static List<String> getUnrestrictedName; public static List<String> getUnrestrictedName;
public static List<String> getRestrictedIp; public static List<String> getRestrictedIp;
public static List<String> getMySQLOtherUsernameColumn;
public static List<String> getForcedWorlds; public static List<String> getForcedWorlds;
public static List<String> countries; public static List<String> countries;
public static List<String> countriesBlacklist; public static List<String> countriesBlacklist;
@ -54,7 +53,6 @@ public final class Settings {
isMovementAllowed, isKickNonRegisteredEnabled, isMovementAllowed, isKickNonRegisteredEnabled,
isForceSingleSessionEnabled, isForceSpawnLocOnJoinEnabled, isForceSingleSessionEnabled, isForceSpawnLocOnJoinEnabled,
isSaveQuitLocationEnabled, isForceSurvivalModeEnabled, isSaveQuitLocationEnabled, isForceSurvivalModeEnabled,
isCachingEnabled,
isKickOnWrongPasswordEnabled, enablePasswordConfirmation, isKickOnWrongPasswordEnabled, enablePasswordConfirmation,
protectInventoryBeforeLogInEnabled, isStopEnabled, reloadSupport, protectInventoryBeforeLogInEnabled, isStopEnabled, reloadSupport,
rakamakUseIp, noConsoleSpam, removePassword, displayOtherAccounts, rakamakUseIp, noConsoleSpam, removePassword, displayOtherAccounts,
@ -69,18 +67,12 @@ public final class Settings {
noTeleport, applyBlindEffect, hideTablistBeforeLogin, denyTabcompleteBeforeLogin, noTeleport, applyBlindEffect, hideTablistBeforeLogin, denyTabcompleteBeforeLogin,
kickPlayersBeforeStopping, allowAllCommandsIfRegIsOptional, kickPlayersBeforeStopping, allowAllCommandsIfRegIsOptional,
customAttributes, generateImage, isRemoveSpeedEnabled, preventOtherCase; customAttributes, generateImage, isRemoveSpeedEnabled, preventOtherCase;
public static String getNickRegex, getUnloggedinGroup, getMySQLHost, public static String getNickRegex, getUnloggedinGroup,
getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, getMySQLColumnGroup, unRegisteredGroup,
getMySQLTablename, getMySQLColumnName, getMySQLColumnPassword,
getMySQLColumnIp, getMySQLColumnLastLogin, getMySQLColumnSalt,
getMySQLColumnGroup, getMySQLColumnEmail, unRegisteredGroup,
backupWindowsPath, getRegisteredGroup, backupWindowsPath, getRegisteredGroup,
getMySQLlastlocX, getMySQLlastlocY, rakamakUsers, rakamakUsersIp, getmailAccount, defaultWorld,
getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount, getPhpbbPrefix, getWordPressPrefix,
getMySQLColumnId, getMySQLlastlocWorld, defaultWorld, spawnPriority, crazyloginFileName, getPassRegex, sendPlayerTo;
getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged,
spawnPriority, crazyloginFileName, getPassRegex,
getMySQLColumnRealName, sendPlayerTo;
public static int getWarnMessageInterval, getSessionTimeout, public static int getWarnMessageInterval, getSessionTimeout,
getRegistrationTimeout, getMaxNickLength, getMinNickLength, getRegistrationTimeout, getMaxNickLength, getMinNickLength,
getPasswordMinLen, getMovementRadius, getmaxRegPerIp, getPasswordMinLen, getMovementRadius, getmaxRegPerIp,
@ -136,25 +128,7 @@ public final class Settings {
getPasswordHash = load(SecuritySettings.PASSWORD_HASH); getPasswordHash = load(SecuritySettings.PASSWORD_HASH);
getUnloggedinGroup = load(SecuritySettings.UNLOGGEDIN_GROUP); getUnloggedinGroup = load(SecuritySettings.UNLOGGEDIN_GROUP);
getDataSource = load(DatabaseSettings.BACKEND); getDataSource = load(DatabaseSettings.BACKEND);
isCachingEnabled = load(DatabaseSettings.USE_CACHING);
getMySQLHost = load(DatabaseSettings.MYSQL_HOST);
getMySQLPort = load(DatabaseSettings.MYSQL_PORT);
getMySQLUsername = load(DatabaseSettings.MYSQL_USERNAME);
getMySQLPassword = load(DatabaseSettings.MYSQL_PASSWORD);
getMySQLDatabase = load(DatabaseSettings.MYSQL_DATABASE);
getMySQLTablename = load(DatabaseSettings.MYSQL_TABLE);
getMySQLColumnEmail = configFile.getString("DataSource.mySQLColumnEmail", "email");
getMySQLColumnName = configFile.getString("DataSource.mySQLColumnName", "username");
getMySQLColumnPassword = configFile.getString("DataSource.mySQLColumnPassword", "password");
getMySQLColumnIp = configFile.getString("DataSource.mySQLColumnIp", "ip");
getMySQLColumnLastLogin = configFile.getString("DataSource.mySQLColumnLastLogin", "lastlogin");
getMySQLColumnSalt = configFile.getString("ExternalBoardOptions.mySQLColumnSalt");
getMySQLColumnGroup = configFile.getString("ExternalBoardOptions.mySQLColumnGroup", ""); getMySQLColumnGroup = configFile.getString("ExternalBoardOptions.mySQLColumnGroup", "");
getMySQLlastlocX = configFile.getString("DataSource.mySQLlastlocX", "x");
getMySQLlastlocY = configFile.getString("DataSource.mySQLlastlocY", "y");
getMySQLlastlocZ = configFile.getString("DataSource.mySQLlastlocZ", "z");
getMySQLlastlocWorld = configFile.getString("DataSource.mySQLlastlocWorld", "world");
getMySQLColumnRealName = configFile.getString("DataSource.mySQLRealName", "realname");
getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1); getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1);
unRegisteredGroup = configFile.getString("GroupOptions.UnregisteredPlayerGroup", ""); unRegisteredGroup = configFile.getString("GroupOptions.UnregisteredPlayerGroup", "");
@ -195,9 +169,7 @@ public final class Settings {
getmailAccount = configFile.getString("Email.mailAccount", ""); getmailAccount = configFile.getString("Email.mailAccount", "");
getMailPort = configFile.getInt("Email.mailPort", 465); getMailPort = configFile.getInt("Email.mailPort", 465);
getRecoveryPassLength = configFile.getInt("Email.RecoveryPasswordLength", 8); getRecoveryPassLength = configFile.getInt("Email.RecoveryPasswordLength", 8);
getMySQLOtherUsernameColumn = configFile.getStringList("ExternalBoardOptions.mySQLOtherUsernameColumns");
displayOtherAccounts = configFile.getBoolean("settings.restrictions.displayOtherAccounts", true); displayOtherAccounts = configFile.getBoolean("settings.restrictions.displayOtherAccounts", true);
getMySQLColumnId = configFile.getString("DataSource.mySQLColumnId", "id");
useCaptcha = configFile.getBoolean("Security.captcha.useCaptcha", false); useCaptcha = configFile.getBoolean("Security.captcha.useCaptcha", false);
maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5); maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5);
captchaLength = configFile.getInt("Security.captcha.captchaLength", 5); captchaLength = configFile.getInt("Security.captcha.captchaLength", 5);
@ -241,7 +213,6 @@ public final class Settings {
broadcastWelcomeMessage = configFile.getBoolean("settings.broadcastWelcomeMessage", false); broadcastWelcomeMessage = configFile.getBoolean("settings.broadcastWelcomeMessage", false);
forceRegKick = configFile.getBoolean("settings.registration.forceKickAfterRegister", false); forceRegKick = configFile.getBoolean("settings.registration.forceKickAfterRegister", false);
forceRegLogin = configFile.getBoolean("settings.registration.forceLoginAfterRegister", false); forceRegLogin = configFile.getBoolean("settings.registration.forceLoginAfterRegister", false);
getMySQLColumnLogged = configFile.getString("DataSource.mySQLColumnLogged", "isLogged");
spawnPriority = configFile.getString("settings.restrictions.spawnPriority", "authme,essentials,multiverse,default"); spawnPriority = configFile.getString("settings.restrictions.spawnPriority", "authme,essentials,multiverse,default");
getMaxLoginPerIp = configFile.getInt("settings.restrictions.maxLoginPerIp", 0); getMaxLoginPerIp = configFile.getInt("settings.restrictions.maxLoginPerIp", 0);
getMaxJoinPerIp = configFile.getInt("settings.restrictions.maxJoinPerIp", 0); getMaxJoinPerIp = configFile.getInt("settings.restrictions.maxJoinPerIp", 0);