diff --git a/src/main/java/fr/xephi/authme/ConsoleLogger.java b/src/main/java/fr/xephi/authme/ConsoleLogger.java index 0bbacbfc..86c2570c 100644 --- a/src/main/java/fr/xephi/authme/ConsoleLogger.java +++ b/src/main/java/fr/xephi/authme/ConsoleLogger.java @@ -67,8 +67,8 @@ public class ConsoleLogger { } try { Files.write(Settings.LOG_FILE.toPath(), (dateTime + ": " + message + StringUtils.newline).getBytes(), - StandardOpenOption.APPEND, - StandardOpenOption.CREATE); + StandardOpenOption.APPEND, + StandardOpenOption.CREATE); } catch (IOException ignored) { } } diff --git a/src/main/java/fr/xephi/authme/Log4JFilter.java b/src/main/java/fr/xephi/authme/Log4JFilter.java index 0db37bb7..f66d7ba4 100644 --- a/src/main/java/fr/xephi/authme/Log4JFilter.java +++ b/src/main/java/fr/xephi/authme/Log4JFilter.java @@ -19,8 +19,8 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter { * List of commands (lower-case) to skip. */ private static final String[] COMMANDS_TO_SKIP = {"/login ", "/l ", "/reg ", "/changepassword ", - "/unregister ", "/authme register ", "/authme changepassword ", "/authme reg ", "/authme cp ", - "/register "}; + "/unregister ", "/authme register ", "/authme changepassword ", "/authme reg ", "/authme cp ", + "/register "}; /** * Constructor. @@ -57,7 +57,7 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter { String lowerMessage = message.toLowerCase(); if (lowerMessage.contains("issued server command:") - && StringUtils.containsAny(lowerMessage, COMMANDS_TO_SKIP)) { + && StringUtils.containsAny(lowerMessage, COMMANDS_TO_SKIP)) { return Result.DENY; } return Result.NEUTRAL; diff --git a/src/main/java/fr/xephi/authme/PerformBackup.java b/src/main/java/fr/xephi/authme/PerformBackup.java index e8349f5e..ea008647 100644 --- a/src/main/java/fr/xephi/authme/PerformBackup.java +++ b/src/main/java/fr/xephi/authme/PerformBackup.java @@ -38,7 +38,7 @@ public class PerformBackup { * @param cause BackupCause The cause of the backup. */ public void doBackup(BackupCause cause) { - if(!Settings.isBackupActivated) { + if (!Settings.isBackupActivated) { ConsoleLogger.showError("Can't perform a Backup: disabled in configuration. Cause of the Backup: " + cause.name()); } // Check whether a backup should be made at the specified point in time diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java index 2bfcd4f6..fe145747 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java @@ -437,12 +437,12 @@ public class PlayerAuth { @Override public String toString() { return ("Player : " + nickname + " | " + realName - + " ! IP : " + ip - + " ! LastLogin : " + lastLogin - + " ! LastPosition : " + x + "," + y + "," + z + "," + world - + " ! Email : " + email - + " ! Hash : " + hash - + " ! Salt : " + salt); + + " ! IP : " + ip + + " ! LastLogin : " + lastLogin + + " ! LastPosition : " + x + "," + y + "," + z + "," + world + + " ! Email : " + email + + " ! Hash : " + hash + + " ! Salt : " + salt); } } diff --git a/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java b/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java index 9b0b7f36..f855a583 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java @@ -25,10 +25,10 @@ public class JsonCache { ConsoleLogger.showError("Failed to create cache directory."); } gson = new GsonBuilder() - .registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer()) - .registerTypeAdapter(DataFileCache.class, new PlayerDataDeserializer()) - .setPrettyPrinting() - .create(); + .registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer()) + .registerTypeAdapter(DataFileCache.class, new PlayerDataDeserializer()) + .setPrettyPrinting() + .create(); } /** diff --git a/src/main/java/fr/xephi/authme/command/CommandDescription.java b/src/main/java/fr/xephi/authme/command/CommandDescription.java index 23373088..3db419b0 100644 --- a/src/main/java/fr/xephi/authme/command/CommandDescription.java +++ b/src/main/java/fr/xephi/authme/command/CommandDescription.java @@ -781,10 +781,10 @@ public class CommandDescription { // Check whether this description is for the last element in the command reference, if so return the current command if (queryReference.getCount() <= getParentCount() + 1) return new FoundCommandResult( - this, - getCommandReference(queryReference), - new CommandParts(), - queryReference); + this, + getCommandReference(queryReference), + new CommandParts(), + queryReference); // Get the new command reference and arguments CommandParts newReference = new CommandParts(queryReference.getRange(0, getParentCount() + 1)); @@ -798,8 +798,8 @@ public class CommandDescription { @Override public int compare(CommandDescription o1, CommandDescription o2) { return Double.compare( - o1.getCommandDifference(queryReference), - o2.getCommandDifference(queryReference)); + o1.getCommandDifference(queryReference), + o2.getCommandDifference(queryReference)); } }); diff --git a/src/main/java/fr/xephi/authme/command/CommandHandler.java b/src/main/java/fr/xephi/authme/command/CommandHandler.java index bf34355d..365a63f4 100644 --- a/src/main/java/fr/xephi/authme/command/CommandHandler.java +++ b/src/main/java/fr/xephi/authme/command/CommandHandler.java @@ -133,7 +133,7 @@ public class CommandHandler { // Show the suggested command sender.sendMessage(ChatColor.DARK_RED + "Unknown command, assuming " + ChatColor.GOLD + "/" + suggestedCommandParts + - ChatColor.DARK_RED + "!"); + ChatColor.DARK_RED + "!"); } // Make sure the command is executable diff --git a/src/main/java/fr/xephi/authme/command/help/HelpSyntaxHelper.java b/src/main/java/fr/xephi/authme/command/help/HelpSyntaxHelper.java index 80e02c36..db49a567 100644 --- a/src/main/java/fr/xephi/authme/command/help/HelpSyntaxHelper.java +++ b/src/main/java/fr/xephi/authme/command/help/HelpSyntaxHelper.java @@ -29,13 +29,13 @@ public final class HelpSyntaxHelper { String alternativeLabel, boolean highlight) { // Create a string builder with white color and prefixed slash StringBuilder sb = new StringBuilder() - .append(ChatColor.WHITE) - .append("/"); + .append(ChatColor.WHITE) + .append("/"); // Get the help command reference, and the command label CommandParts helpCommandReference = commandDescription.getCommandReference(commandReference); final String parentCommand = new CommandParts( - helpCommandReference.getRange(0, helpCommandReference.getCount() - 1)).toString(); + helpCommandReference.getRange(0, helpCommandReference.getCount() - 1)).toString(); // Check whether the alternative label should be used String commandLabel; @@ -47,9 +47,9 @@ public final class HelpSyntaxHelper { // Show the important bit of the command, highlight this part if required sb.append(parentCommand) - .append(" ") - .append(highlight ? ChatColor.YELLOW.toString() + ChatColor.BOLD : "") - .append(commandLabel); + .append(" ") + .append(highlight ? ChatColor.YELLOW.toString() + ChatColor.BOLD : "") + .append(commandLabel); if (highlight) { sb.append(ChatColor.YELLOW); diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 9e2dca1d..71a8e27f 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -1,1268 +1,1268 @@ -package fr.xephi.authme.datasource; - -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; -import com.zaxxer.hikari.pool.PoolInitializationException; -import fr.xephi.authme.AuthMe; -import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.security.HashAlgorithm; -import fr.xephi.authme.settings.Settings; - -import java.sql.*; -import java.util.ArrayList; -import java.util.List; - -/** - */ -public class MySQL implements DataSource { - - private String host; - private String port; - private String username; - private String password; - private String database; - private String tableName; - private String columnName; - private String columnPassword; - private String columnIp; - private String columnLastLogin; - private String columnSalt; - private String columnGroup; - private String lastlocX; - private String lastlocY; - private String lastlocZ; - private String lastlocWorld; - private String columnEmail; - private String columnID; - private String columnLogged; - private List columnOthers; - private HikariDataSource ds; - private String columnRealName; - private int maxConnections; - - /** - * Constructor for MySQL. - * - * @throws ClassNotFoundException * @throws SQLException * @throws PoolInitializationException - */ - public MySQL() throws ClassNotFoundException, SQLException, PoolInitializationException { - this.host = Settings.getMySQLHost; - this.port = Settings.getMySQLPort; - this.username = Settings.getMySQLUsername; - this.password = Settings.getMySQLPassword; - this.database = Settings.getMySQLDatabase; - this.tableName = Settings.getMySQLTablename; - this.columnName = Settings.getMySQLColumnName; - this.columnPassword = Settings.getMySQLColumnPassword; - this.columnIp = Settings.getMySQLColumnIp; - 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; - this.maxConnections = Settings.getMySQLMaxConnections; - - // Set the connection arguments (and check if connection is ok) - try { - this.setConnectionArguments(); - } catch (RuntimeException e) { - if (e instanceof IllegalArgumentException) { - ConsoleLogger.showError("Invalid database arguments! Please check your configuration!"); - ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN..."); - throw new IllegalArgumentException(e); - } - if (e instanceof PoolInitializationException) { - ConsoleLogger.showError("Can't initialize database connection! Please check your configuration!"); - ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN..."); - throw new PoolInitializationException(e); - } - ConsoleLogger.showError("Can't use the Hikari Connection Pool! Please, report this error to the developer! SHUTDOWN..."); - throw e; - } - - // Initialize the database - try { - this.setupConnection(); - } catch (SQLException e) { - this.close(); - ConsoleLogger.showError("Can't initialize the MySQL database... Please check your database settings in the config.yml file! SHUTDOWN..."); - ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN..."); - throw e; - } - } - - /** - * Method setConnectionArguments. - * - * @throws ClassNotFoundException * @throws IllegalArgumentException - */ - private synchronized void setConnectionArguments() - throws ClassNotFoundException, IllegalArgumentException { - HikariConfig config = new HikariConfig(); - config.setPoolName("AuthMeMYSQLPool"); - config.setDriverClassName("com.mysql.jdbc.Driver"); - config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database); - config.setUsername(this.username); - config.setPassword(this.password); - config.addDataSourceProperty("cachePrepStmts", "false"); - config.addDataSourceProperty("autoReconnect", false); - config.setInitializationFailFast(true); // Don't start the plugin if the database is unavailable - config.setMaxLifetime(180000); // 3 Min - config.setIdleTimeout(60000); // 1 Min - config.setMinimumIdle(2); - config.setMaximumPoolSize(maxConnections); - ds = new HikariDataSource(config); - ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!"); - } - - /** - * Method reloadArguments. - * - * @throws ClassNotFoundException * @throws IllegalArgumentException - */ - private synchronized void reloadArguments() - throws ClassNotFoundException, IllegalArgumentException { - if (ds != null) { - ds.close(); - } - setConnectionArguments(); - ConsoleLogger.info("Hikari ConnectionPool arguments reloaded!"); - } - - /** - * Method getConnection. - * - * @return Connection * @throws SQLException - */ - private synchronized Connection getConnection() throws SQLException { - return ds.getConnection(); - } - - /** - * Method setupConnection. - * - * @throws SQLException - */ - private synchronized void setupConnection() throws SQLException { - Connection con = null; - Statement st = null; - ResultSet rs = null; - try { - if ((con = getConnection()) == null) - return; - 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 DEFAULT '127.0.0.1'," + columnLastLogin + " BIGINT NOT NULL DEFAULT '" + System.currentTimeMillis() + "'," + 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'," + columnLogged + " SMALLINT NOT NULL DEFAULT '0'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));"); - rs = con.getMetaData().getColumns(null, null, tableName, columnPassword); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnPassword + " VARCHAR(255) NOT NULL;"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, columnIp); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnIp + " VARCHAR(40) NOT NULL;"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " BIGINT;"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + columnLastLogin + " , ADD " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + lastlocX + " , ADD " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + lastlocY + ";"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + lastlocZ + ";"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, columnEmail); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com' AFTER " + lastlocWorld + ";"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, columnLogged); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLogged + " SMALLINT NOT NULL DEFAULT '0' AFTER " + columnEmail + ";"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); - if (rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " MODIFY " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, columnRealName); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnRealName + " VARCHAR(255) NOT NULL DEFAULT 'Player' AFTER " + columnLogged + ";"); - } - if (Settings.isMySQLWebsite) - st.execute("SET GLOBAL query_cache_size = 0; SET GLOBAL query_cache_type = 0;"); - } finally { - close(rs); - close(st); - close(con); - } - ConsoleLogger.info("MySQL Setup finished"); - } - - /** - * Method isAuthAvailable. - * - * @param user String - * @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) - */ - @Override - public synchronized boolean isAuthAvailable(String user) { - Connection con = null; - PreparedStatement pst = null; - ResultSet rs = null; - try { - if ((con = getConnection()) == null) - return true; - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);"); - pst.setString(1, user); - rs = pst.executeQuery(); - return rs.next(); - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(rs); - close(pst); - close(con); - } - } - - /** - * Method getAuth. - * - * @param user String - * @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) - */ - @Override - public synchronized PlayerAuth getAuth(String user) { - Connection con = null; - PreparedStatement pst = null; - ResultSet rs = null; - PlayerAuth pAuth = null; - int id; - try { - if ((con = getConnection()) == null) - return null; - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);"); - pst.setString(1, user); - rs = pst.executeQuery(); - if (rs.next()) { - id = rs.getInt(columnID); - if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { - pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } else { - if (!columnSalt.isEmpty()) { - if (!columnGroup.isEmpty()) - pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - else - pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } else { - pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } - } - if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { - rs.close(); - pst.close(); - pst = con.prepareStatement("SELECT * FROM xf_user_authenticate WHERE " + columnID + "=?;"); - pst.setInt(1, id); - rs = pst.executeQuery(); - if (rs.next()) { - Blob blob = rs.getBlob("data"); - byte[] bytes = blob.getBytes(1, (int) blob.length()); - pAuth.setHash(new String(bytes)); - } - } - } else { - return null; - } - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return null; - } finally { - close(rs); - close(pst); - close(con); - } - return pAuth; - } - - /** - * Method saveAuth. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) - */ - @Override - public synchronized boolean saveAuth(PlayerAuth auth) { - Connection con = null; - PreparedStatement pst = null; - ResultSet rs = null; - try { - if ((con = getConnection()) == null) - return false; - if ((columnSalt == null || columnSalt.isEmpty()) || (auth.getSalt() == null || auth.getSalt().isEmpty())) { - pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnRealName + ") VALUES (?,?,?,?,?);"); - pst.setString(1, auth.getNickname()); - pst.setString(2, auth.getHash()); - pst.setString(3, auth.getIp()); - pst.setLong(4, auth.getLastLogin()); - pst.setString(5, auth.getRealName()); - pst.executeUpdate(); - pst.close(); - } else { - pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnSalt + "," + columnRealName + ") VALUES (?,?,?,?,?,?);"); - pst.setString(1, auth.getNickname()); - pst.setString(2, auth.getHash()); - pst.setString(3, auth.getIp()); - pst.setLong(4, auth.getLastLogin()); - pst.setString(5, auth.getSalt()); - pst.setString(6, auth.getRealName()); - pst.executeUpdate(); - pst.close(); - } - if (!columnOthers.isEmpty()) { - for (String column : columnOthers) { - pst = con.prepareStatement("UPDATE " + tableName + " SET " + column + "=? WHERE " + columnName + "=?;"); - pst.setString(1, auth.getRealName()); - pst.setString(2, auth.getNickname()); - pst.executeUpdate(); - pst.close(); - } - } - if (Settings.getPasswordHash == HashAlgorithm.PHPBB) { - PreparedStatement pst2 = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;"); - pst2.setString(1, auth.getNickname()); - rs = pst2.executeQuery(); - if (rs.next()) { - int id = rs.getInt(columnID); - // Insert player in phpbb_user_group - pst = con.prepareStatement("INSERT INTO " + Settings.getPhpbbPrefix + "user_group (group_id, user_id, group_leader, user_pending) VALUES (?,?,?,?);"); - pst.setInt(1, Settings.getPhpbbGroup); - pst.setInt(2, id); - pst.setInt(3, 0); - pst.setInt(4, 0); - pst.executeUpdate(); - pst.close(); - // Update username_clean in phpbb_users - pst = con.prepareStatement("UPDATE " + tableName + " SET " + tableName + ".username_clean=? WHERE " + columnName + "=?;"); - pst.setString(1, auth.getNickname().toLowerCase()); - pst.setString(2, auth.getNickname()); - pst.executeUpdate(); - pst.close(); - // Update player group in phpbb_users - pst = con.prepareStatement("UPDATE " + tableName + " SET " + tableName + ".group_id=? WHERE " + columnName + "=?;"); - pst.setInt(1, Settings.getPhpbbGroup); - pst.setString(2, auth.getNickname()); - pst.executeUpdate(); - pst.close(); - // Get current time without ms - long time = System.currentTimeMillis() / 1000; - // Update user_regdate - pst = con.prepareStatement("UPDATE " + tableName + " SET " + tableName + ".user_regdate=? WHERE " + columnName + "=?;"); - pst.setLong(1, time); - pst.setString(2, auth.getNickname()); - pst.executeUpdate(); - pst.close(); - // Update user_lastvisit - pst = con.prepareStatement("UPDATE " + tableName + " SET " + tableName + ".user_lastvisit=? WHERE " + columnName + "=?;"); - pst.setLong(1, time); - pst.setString(2, auth.getNickname()); - pst.executeUpdate(); - pst.close(); - // Increment num_users - pst = con.prepareStatement("UPDATE " + Settings.getPhpbbPrefix + "config SET config_value = config_value + 1 WHERE config_name = 'num_users';"); - pst.executeUpdate(); - pst.close(); - } - rs.close(); - pst2.close(); - } - if (Settings.getPasswordHash == HashAlgorithm.WORDPRESS) { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;"); - pst.setString(1, auth.getNickname()); - rs = pst.executeQuery(); - if (rs.next()) { - int id = rs.getInt(columnID); - // First Name - pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "first_name"); - pst.setString(3, ""); - pst.executeUpdate(); - pst.close(); - // Last Name - pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "last_name"); - pst.setString(3, ""); - pst.executeUpdate(); - pst.close(); - // Nick Name - pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "nickname"); - pst.setString(3, auth.getNickname()); - pst.executeUpdate(); - pst.close(); - // Description - pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "description"); - pst.setString(3, ""); - pst.executeUpdate(); - pst.close(); - // Rich_Editing - pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "rich_editing"); - pst.setString(3, "true"); - pst.executeUpdate(); - pst.close(); - // Comments_Shortcuts - pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "comment_shortcuts"); - pst.setString(3, "false"); - pst.executeUpdate(); - pst.close(); - // admin_color - pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "admin_color"); - pst.setString(3, "fresh"); - pst.executeUpdate(); - pst.close(); - // use_ssl - pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "use_ssl"); - pst.setString(3, "0"); - pst.executeUpdate(); - pst.close(); - // show_admin_bar_front - pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "show_admin_bar_front"); - pst.setString(3, "true"); - pst.executeUpdate(); - pst.close(); - // wp_capabilities - pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "wp_capabilities"); - pst.setString(3, "a:1:{s:10:\"subscriber\";b:1;}"); - pst.executeUpdate(); - pst.close(); - // wp_user_level - pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "wp_user_level"); - pst.setString(3, "0"); - pst.executeUpdate(); - pst.close(); - // default_password_nag - pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "default_password_nag"); - pst.setString(3, ""); - pst.executeUpdate(); - pst.close(); - } - rs.close(); - } - if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;"); - pst.setString(1, auth.getNickname()); - rs = pst.executeQuery(); - if (rs.next()) { - int id = rs.getInt(columnID); - // Insert password in the correct table - pst = con.prepareStatement("INSERT INTO xf_user_authenticate (user_id, scheme_class, data) VALUES (?,?,?);"); - pst.setInt(1, id); - pst.setString(2, "XenForo_Authentication_Core12"); - byte[] bytes = auth.getHash().getBytes(); - Blob blob = con.createBlob(); - blob.setBytes(1, bytes); - pst.setBlob(3, blob); - pst.executeUpdate(); - } - rs.close(); - } - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(rs); - close(pst); - close(con); - } - return true; - } - - /** - * Method updatePassword. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) - */ - @Override - public synchronized boolean updatePassword(PlayerAuth auth) { - Connection con = null; - PreparedStatement pst = null; - ResultSet rs = null; - try { - if ((con = getConnection()) == null) - return false; - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE LOWER(" + columnName + ")=?;"); - pst.setString(1, auth.getHash()); - pst.setString(2, auth.getNickname()); - pst.executeUpdate(); - pst.close(); - if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); - pst.setString(1, auth.getNickname()); - rs = pst.executeQuery(); - if (rs.next()) { - int id = rs.getInt(columnID); - // Insert password in the correct table - pst = con.prepareStatement("UPDATE xf_user_authenticate SET data=? WHERE " + columnID + "=?;"); - byte[] bytes = auth.getHash().getBytes(); - Blob blob = con.createBlob(); - blob.setBytes(1, bytes); - pst.setBlob(1, blob); - pst.setInt(2, id); - pst.executeUpdate(); - pst = con.prepareStatement("UPDATE xf_user_authenticate SET scheme_class=? WHERE " + columnID + "=?;"); - pst.setString(1, "XenForo_Authentication_Core12"); - pst.setInt(2, id); - pst.executeUpdate(); - } - rs.close(); - } - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(rs); - close(pst); - close(con); - } - return true; - } - - /** - * Method updateSession. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) - */ - @Override - public synchronized boolean updateSession(PlayerAuth auth) { - Connection con = null; - PreparedStatement pst = null; - try { - if ((con = getConnection()) == null) - return false; - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE LOWER(" + columnName + ")=?;"); - pst.setString(1, auth.getIp()); - pst.setLong(2, auth.getLastLogin()); - pst.setString(3, auth.getRealName()); - pst.setString(4, auth.getNickname()); - pst.executeUpdate(); - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(pst); - close(con); - } - return true; - } - - /** - * Method purgeDatabase. - * - * @param until long - * @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) - */ - @Override - public synchronized int purgeDatabase(long until) { - Connection con = null; - PreparedStatement pst = null; - try { - if ((con = getConnection()) == null) - return 0; - pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + " * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) - */ - @Override - public synchronized List autoPurgeDatabase(long until) { - Connection con = null; - PreparedStatement pst = null; - ResultSet rs = null; - List list = new ArrayList<>(); - try { - if ((con = getConnection()) == null) - return list; - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "(); - } finally { - close(rs); - close(pst); - close(con); - } - } - - /** - * Method removeAuth. - * - * @param user String - * @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) - */ - @Override - public synchronized boolean removeAuth(String user) { - Connection con = null; - PreparedStatement pst = null; - try { - if ((con = getConnection()) == null) - return false; - if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { - int id; - ResultSet rs; - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); - pst.setString(1, user); - rs = pst.executeQuery(); - if (rs.next()) { - id = rs.getInt(columnID); - // Remove data - PreparedStatement pst2 = con.prepareStatement("DELETE FROM xf_user_authenticate WHERE " + columnID + "=?;"); - pst2.setInt(1, id); - pst2.executeUpdate(); - pst2.close(); - } - } - if (pst != null && !pst.isClosed()) - pst.close(); - pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); - pst.setString(1, user); - pst.executeUpdate(); - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(pst); - close(con); - } - return true; - } - - /** - * Method updateQuitLoc. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) - */ - @Override - public synchronized boolean updateQuitLoc(PlayerAuth auth) { - Connection con = null; - PreparedStatement pst = null; - try { - if ((con = getConnection()) == null) - return false; - pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + " =?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE LOWER(" + columnName + ")=?;"); - pst.setDouble(1, auth.getQuitLocX()); - pst.setDouble(2, auth.getQuitLocY()); - pst.setDouble(3, auth.getQuitLocZ()); - pst.setString(4, auth.getWorld()); - pst.setString(5, auth.getNickname()); - pst.executeUpdate(); - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(pst); - close(con); - } - return true; - } - - /** - * Method getIps. - * - * @param ip String - * @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) - */ - @Override - public synchronized int getIps(String ip) { - Connection con = null; - PreparedStatement pst = null; - ResultSet rs = null; - int countIp = 0; - try { - if ((con = getConnection()) == null) - return 0; - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); - pst.setString(1, ip); - rs = pst.executeQuery(); - while (rs.next()) { - countIp++; - } - return countIp; - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return 0; - } finally { - close(rs); - close(pst); - close(con); - } - } - - /** - * Method updateEmail. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) - */ - @Override - public synchronized boolean updateEmail(PlayerAuth auth) { - Connection con = null; - PreparedStatement pst = null; - try { - if ((con = getConnection()) == null) - return false; - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + " =? WHERE LOWER(" + columnName + ")=?;"); - pst.setString(1, auth.getEmail()); - pst.setString(2, auth.getNickname()); - pst.executeUpdate(); - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); - return false; - } finally { - close(pst); - close(con); - } - return true; - } - - /** - * Method updateSalt. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) - */ - @Override - public synchronized boolean updateSalt(PlayerAuth auth) { - if (columnSalt.isEmpty()) { - return false; - } - Connection con = null; - PreparedStatement pst = null; - try { - if ((con = getConnection()) == null) - return false; - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnSalt + " =? WHERE LOWER(" + columnName + ")=?;"); - pst.setString(1, auth.getSalt()); - pst.setString(2, auth.getNickname()); - pst.executeUpdate(); - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(pst); - close(con); - } - return true; - } - - /** - * Method reload. - * - * @see fr.xephi.authme.datasource.DataSource#reload() - */ - @Override - public void reload() { - try { - reloadArguments(); - } catch (Exception e) { - ConsoleLogger.showError(e.getMessage()); - ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL informations ! SHUTDOWN..."); - if (Settings.isStopEnabled) { - AuthMe.getInstance().getServer().shutdown(); - } - if (!Settings.isStopEnabled) - AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); - } - } - - /** - * Method close. - * - * @see fr.xephi.authme.datasource.DataSource#close() - */ - @Override - public synchronized void close() { - if (ds != null && !ds.isClosed()) - ds.close(); - } - - /** - * Method close. - * - * @param o AutoCloseable - */ - private void close(AutoCloseable o) { - if (o != null) { - try { - o.close(); - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); - } - } - } - - /** - * Method getAllAuthsByName. - * - * @param auth PlayerAuth - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) - */ - @Override - public synchronized List getAllAuthsByName(PlayerAuth auth) { - Connection con = null; - PreparedStatement pst = null; - ResultSet rs = null; - List countIp = new ArrayList<>(); - try { - if ((con = getConnection()) == null) - return countIp; - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); - pst.setString(1, auth.getIp()); - rs = pst.executeQuery(); - while (rs.next()) { - countIp.add(rs.getString(columnName)); - } - return countIp; - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return new ArrayList<>(); - } finally { - close(rs); - close(pst); - close(con); - } - } - - /** - * Method getAllAuthsByIp. - * - * @param ip String - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) - */ - @Override - public synchronized List getAllAuthsByIp(String ip) { - Connection con = null; - PreparedStatement pst = null; - ResultSet rs = null; - List countIp = new ArrayList<>(); - try { - if ((con = getConnection()) == null) - return countIp; - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); - pst.setString(1, ip); - rs = pst.executeQuery(); - while (rs.next()) { - countIp.add(rs.getString(columnName)); - } - return countIp; - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return new ArrayList<>(); - } finally { - close(rs); - close(pst); - close(con); - } - } - - /** - * Method getAllAuthsByEmail. - * - * @param email String - * @return List * @throws SQLException * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) - */ - @Override - public synchronized List getAllAuthsByEmail(String email) throws SQLException { - final Connection con = getConnection(); - PreparedStatement pst = null; - ResultSet rs = null; - List countEmail = new ArrayList<>(); - - try { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;"); - pst.setString(1, email); - rs = pst.executeQuery(); - while (rs.next()) { - countEmail.add(rs.getString(columnName)); - } - return countEmail; - } finally { - close(rs); - close(pst); - close(con); - } - } - - /** - * Method purgeBanned. - * - * @param banned List - * @see fr.xephi.authme.datasource.DataSource#purgeBanned(List) - */ - @Override - public synchronized void purgeBanned(List banned) { - Connection con = null; - PreparedStatement pst = null; - try { - if ((con = getConnection()) == null) - return; - for (String name : banned) { - pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); - pst.setString(1, name); - pst.executeUpdate(); - } - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - } finally { - close(pst); - close(con); - } - } - - /** - * Method getType. - * - * @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType() - */ - @Override - public DataSourceType getType() { - return DataSourceType.MYSQL; - } - - /** - * Method isLogged. - * - * @param user String - * @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) - */ - @Override - public boolean isLogged(String user) { - Connection con = null; - PreparedStatement pst = null; - ResultSet rs = null; - try { - if ((con = getConnection()) == null) - return false; - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); - pst.setString(1, user); - rs = pst.executeQuery(); - if (rs.next()) - return (rs.getInt(columnLogged) == 1); - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(rs); - close(pst); - close(con); - } - return false; - } - - /** - * Method setLogged. - * - * @param user String - * @see fr.xephi.authme.datasource.DataSource#setLogged(String) - */ - @Override - public void setLogged(String user) { - Connection con = null; - PreparedStatement pst = null; - try { - if ((con = getConnection()) == null) - return; - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); - pst.setInt(1, 1); - pst.setString(2, user); - pst.executeUpdate(); - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - } finally { - close(pst); - close(con); - } - } - - /** - * Method setUnlogged. - * - * @param user String - * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) - */ - @Override - public void setUnlogged(String user) { - Connection con = null; - PreparedStatement pst = null; - if (user != null) - try { - if ((con = getConnection()) == null) - return; - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); - pst.setInt(1, 0); - pst.setString(2, user); - pst.executeUpdate(); - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - } finally { - close(pst); - close(con); - } - } - - /** - * Method purgeLogged. - * - * @see fr.xephi.authme.datasource.DataSource#purgeLogged() - */ - @Override - public void purgeLogged() { - Connection con = null; - PreparedStatement pst = null; - try { - if ((con = getConnection()) == null) - return; - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;"); - pst.setInt(1, 0); - pst.setInt(2, 1); - pst.executeUpdate(); - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - } finally { - close(pst); - close(con); - } - } - - /** - * Method getAccountsRegistered. - * - * @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered() - */ - @Override - public int getAccountsRegistered() { - int result = 0; - Connection con = null; - PreparedStatement pst = null; - ResultSet rs; - try { - if ((con = getConnection()) == null) - return result; - pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";"); - rs = pst.executeQuery(); - if (rs != null && rs.next()) { - result = rs.getInt(1); - } - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return result; - } finally { - close(pst); - close(con); - } - return result; - } - - /** - * Method updateName. - * - * @param oldone String - * @param newone String - * @see fr.xephi.authme.datasource.DataSource#updateName(String, String) - */ - @Override - public void updateName(String oldone, String newone) { - Connection con = null; - PreparedStatement pst = null; - try { - if ((con = getConnection()) == null) - return; - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE LOWER(" + columnName + ")=?;"); - pst.setString(1, newone); - pst.setString(2, oldone); - pst.executeUpdate(); - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - } finally { - close(pst); - close(con); - } - } - - /** - * Method getAllAuths. - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuths() - */ - @Override - public List getAllAuths() { - List auths = new ArrayList<>(); - Connection con = null; - PreparedStatement pst = null; - ResultSet rs = null; - try { - if ((con = getConnection()) == null) - return auths; - pst = con.prepareStatement("SELECT * FROM " + tableName + ";"); - rs = pst.executeQuery(); - while (rs.next()) { - PlayerAuth pAuth; - int id = rs.getInt(columnID); - if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } else { - if (!columnSalt.isEmpty()) { - if (!columnGroup.isEmpty()) - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - else - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } else { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } - } - if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { - ResultSet rsid; - pst = con.prepareStatement("SELECT * FROM xf_user_authenticate WHERE " + columnID + "=?;"); - pst.setInt(1, id); - rsid = pst.executeQuery(); - if (rsid.next()) { - Blob blob = rsid.getBlob("data"); - byte[] bytes = blob.getBytes(1, (int) blob.length()); - pAuth.setHash(new String(bytes)); - } - rsid.close(); - } - auths.add(pAuth); - } - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return auths; - } finally { - close(pst); - close(con); - close(rs); - } - return auths; - } - - /** - * Method getLoggedPlayers. - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers() - */ - @Override - public List getLoggedPlayers() { - List auths = new ArrayList<>(); - Connection con = null; - PreparedStatement pst = null; - ResultSet rs = null; - try { - if ((con = getConnection()) == null) - return auths; - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;"); - rs = pst.executeQuery(); - while (rs.next()) { - PlayerAuth pAuth; - int id = rs.getInt(columnID); - if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } else { - if (!columnSalt.isEmpty()) { - if (!columnGroup.isEmpty()) - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - else - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } else { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } - } - if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { - ResultSet rsid; - pst = con.prepareStatement("SELECT * FROM xf_user_authenticate WHERE " + columnID + "=?;"); - pst.setInt(1, id); - rsid = pst.executeQuery(); - if (rsid.next()) { - Blob blob = rsid.getBlob("data"); - byte[] bytes = blob.getBytes(1, (int) blob.length()); - pAuth.setHash(new String(bytes)); - } - rsid.close(); - } - auths.add(pAuth); - } - } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - return auths; - } finally { - close(pst); - close(rs); - close(con); - } - return auths; - } - -} +package fr.xephi.authme.datasource; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import com.zaxxer.hikari.pool.PoolInitializationException; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.security.HashAlgorithm; +import fr.xephi.authme.settings.Settings; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + +/** + */ +public class MySQL implements DataSource { + + private String host; + private String port; + private String username; + private String password; + private String database; + private String tableName; + private String columnName; + private String columnPassword; + private String columnIp; + private String columnLastLogin; + private String columnSalt; + private String columnGroup; + private String lastlocX; + private String lastlocY; + private String lastlocZ; + private String lastlocWorld; + private String columnEmail; + private String columnID; + private String columnLogged; + private List columnOthers; + private HikariDataSource ds; + private String columnRealName; + private int maxConnections; + + /** + * Constructor for MySQL. + * + * @throws ClassNotFoundException * @throws SQLException * @throws PoolInitializationException + */ + public MySQL() throws ClassNotFoundException, SQLException, PoolInitializationException { + this.host = Settings.getMySQLHost; + this.port = Settings.getMySQLPort; + this.username = Settings.getMySQLUsername; + this.password = Settings.getMySQLPassword; + this.database = Settings.getMySQLDatabase; + this.tableName = Settings.getMySQLTablename; + this.columnName = Settings.getMySQLColumnName; + this.columnPassword = Settings.getMySQLColumnPassword; + this.columnIp = Settings.getMySQLColumnIp; + 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; + this.maxConnections = Settings.getMySQLMaxConnections; + + // Set the connection arguments (and check if connection is ok) + try { + this.setConnectionArguments(); + } catch (RuntimeException e) { + if (e instanceof IllegalArgumentException) { + ConsoleLogger.showError("Invalid database arguments! Please check your configuration!"); + ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN..."); + throw new IllegalArgumentException(e); + } + if (e instanceof PoolInitializationException) { + ConsoleLogger.showError("Can't initialize database connection! Please check your configuration!"); + ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN..."); + throw new PoolInitializationException(e); + } + ConsoleLogger.showError("Can't use the Hikari Connection Pool! Please, report this error to the developer! SHUTDOWN..."); + throw e; + } + + // Initialize the database + try { + this.setupConnection(); + } catch (SQLException e) { + this.close(); + ConsoleLogger.showError("Can't initialize the MySQL database... Please check your database settings in the config.yml file! SHUTDOWN..."); + ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN..."); + throw e; + } + } + + /** + * Method setConnectionArguments. + * + * @throws ClassNotFoundException * @throws IllegalArgumentException + */ + private synchronized void setConnectionArguments() + throws ClassNotFoundException, IllegalArgumentException { + HikariConfig config = new HikariConfig(); + config.setPoolName("AuthMeMYSQLPool"); + config.setDriverClassName("com.mysql.jdbc.Driver"); + config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database); + config.setUsername(this.username); + config.setPassword(this.password); + config.addDataSourceProperty("cachePrepStmts", "false"); + config.addDataSourceProperty("autoReconnect", false); + config.setInitializationFailFast(true); // Don't start the plugin if the database is unavailable + config.setMaxLifetime(180000); // 3 Min + config.setIdleTimeout(60000); // 1 Min + config.setMinimumIdle(2); + config.setMaximumPoolSize(maxConnections); + ds = new HikariDataSource(config); + ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!"); + } + + /** + * Method reloadArguments. + * + * @throws ClassNotFoundException * @throws IllegalArgumentException + */ + private synchronized void reloadArguments() + throws ClassNotFoundException, IllegalArgumentException { + if (ds != null) { + ds.close(); + } + setConnectionArguments(); + ConsoleLogger.info("Hikari ConnectionPool arguments reloaded!"); + } + + /** + * Method getConnection. + * + * @return Connection * @throws SQLException + */ + private synchronized Connection getConnection() throws SQLException { + return ds.getConnection(); + } + + /** + * Method setupConnection. + * + * @throws SQLException + */ + private synchronized void setupConnection() throws SQLException { + Connection con = null; + Statement st = null; + ResultSet rs = null; + try { + if ((con = getConnection()) == null) + return; + 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 DEFAULT '127.0.0.1'," + columnLastLogin + " BIGINT NOT NULL DEFAULT '" + System.currentTimeMillis() + "'," + 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'," + columnLogged + " SMALLINT NOT NULL DEFAULT '0'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));"); + rs = con.getMetaData().getColumns(null, null, tableName, columnPassword); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnPassword + " VARCHAR(255) NOT NULL;"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnIp); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnIp + " VARCHAR(40) NOT NULL;"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " BIGINT;"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + columnLastLogin + " , ADD " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + lastlocX + " , ADD " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + lastlocY + ";"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + lastlocZ + ";"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnEmail); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com' AFTER " + lastlocWorld + ";"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnLogged); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLogged + " SMALLINT NOT NULL DEFAULT '0' AFTER " + columnEmail + ";"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); + if (rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " MODIFY " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnRealName); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnRealName + " VARCHAR(255) NOT NULL DEFAULT 'Player' AFTER " + columnLogged + ";"); + } + if (Settings.isMySQLWebsite) + st.execute("SET GLOBAL query_cache_size = 0; SET GLOBAL query_cache_type = 0;"); + } finally { + close(rs); + close(st); + close(con); + } + ConsoleLogger.info("MySQL Setup finished"); + } + + /** + * Method isAuthAvailable. + * + * @param user String + * @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) + */ + @Override + public synchronized boolean isAuthAvailable(String user) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + try { + if ((con = getConnection()) == null) + return true; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);"); + pst.setString(1, user); + rs = pst.executeQuery(); + return rs.next(); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(rs); + close(pst); + close(con); + } + } + + /** + * Method getAuth. + * + * @param user String + * @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) + */ + @Override + public synchronized PlayerAuth getAuth(String user) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + PlayerAuth pAuth = null; + int id; + try { + if ((con = getConnection()) == null) + return null; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);"); + pst.setString(1, user); + rs = pst.executeQuery(); + if (rs.next()) { + id = rs.getInt(columnID); + if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { + pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } else { + if (!columnSalt.isEmpty()) { + if (!columnGroup.isEmpty()) + pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + else + pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } else { + pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } + } + if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { + rs.close(); + pst.close(); + pst = con.prepareStatement("SELECT * FROM xf_user_authenticate WHERE " + columnID + "=?;"); + pst.setInt(1, id); + rs = pst.executeQuery(); + if (rs.next()) { + Blob blob = rs.getBlob("data"); + byte[] bytes = blob.getBytes(1, (int) blob.length()); + pAuth.setHash(new String(bytes)); + } + } + } else { + return null; + } + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return null; + } finally { + close(rs); + close(pst); + close(con); + } + return pAuth; + } + + /** + * Method saveAuth. + * + * @param auth PlayerAuth + * @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) + */ + @Override + public synchronized boolean saveAuth(PlayerAuth auth) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + try { + if ((con = getConnection()) == null) + return false; + if ((columnSalt == null || columnSalt.isEmpty()) || (auth.getSalt() == null || auth.getSalt().isEmpty())) { + pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnRealName + ") VALUES (?,?,?,?,?);"); + pst.setString(1, auth.getNickname()); + pst.setString(2, auth.getHash()); + pst.setString(3, auth.getIp()); + pst.setLong(4, auth.getLastLogin()); + pst.setString(5, auth.getRealName()); + pst.executeUpdate(); + pst.close(); + } else { + pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnSalt + "," + columnRealName + ") VALUES (?,?,?,?,?,?);"); + pst.setString(1, auth.getNickname()); + pst.setString(2, auth.getHash()); + pst.setString(3, auth.getIp()); + pst.setLong(4, auth.getLastLogin()); + pst.setString(5, auth.getSalt()); + pst.setString(6, auth.getRealName()); + pst.executeUpdate(); + pst.close(); + } + if (!columnOthers.isEmpty()) { + for (String column : columnOthers) { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + column + "=? WHERE " + columnName + "=?;"); + pst.setString(1, auth.getRealName()); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + pst.close(); + } + } + if (Settings.getPasswordHash == HashAlgorithm.PHPBB) { + PreparedStatement pst2 = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;"); + pst2.setString(1, auth.getNickname()); + rs = pst2.executeQuery(); + if (rs.next()) { + int id = rs.getInt(columnID); + // Insert player in phpbb_user_group + pst = con.prepareStatement("INSERT INTO " + Settings.getPhpbbPrefix + "user_group (group_id, user_id, group_leader, user_pending) VALUES (?,?,?,?);"); + pst.setInt(1, Settings.getPhpbbGroup); + pst.setInt(2, id); + pst.setInt(3, 0); + pst.setInt(4, 0); + pst.executeUpdate(); + pst.close(); + // Update username_clean in phpbb_users + pst = con.prepareStatement("UPDATE " + tableName + " SET " + tableName + ".username_clean=? WHERE " + columnName + "=?;"); + pst.setString(1, auth.getNickname().toLowerCase()); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + pst.close(); + // Update player group in phpbb_users + pst = con.prepareStatement("UPDATE " + tableName + " SET " + tableName + ".group_id=? WHERE " + columnName + "=?;"); + pst.setInt(1, Settings.getPhpbbGroup); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + pst.close(); + // Get current time without ms + long time = System.currentTimeMillis() / 1000; + // Update user_regdate + pst = con.prepareStatement("UPDATE " + tableName + " SET " + tableName + ".user_regdate=? WHERE " + columnName + "=?;"); + pst.setLong(1, time); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + pst.close(); + // Update user_lastvisit + pst = con.prepareStatement("UPDATE " + tableName + " SET " + tableName + ".user_lastvisit=? WHERE " + columnName + "=?;"); + pst.setLong(1, time); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + pst.close(); + // Increment num_users + pst = con.prepareStatement("UPDATE " + Settings.getPhpbbPrefix + "config SET config_value = config_value + 1 WHERE config_name = 'num_users';"); + pst.executeUpdate(); + pst.close(); + } + rs.close(); + pst2.close(); + } + if (Settings.getPasswordHash == HashAlgorithm.WORDPRESS) { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;"); + pst.setString(1, auth.getNickname()); + rs = pst.executeQuery(); + if (rs.next()) { + int id = rs.getInt(columnID); + // First Name + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "first_name"); + pst.setString(3, ""); + pst.executeUpdate(); + pst.close(); + // Last Name + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "last_name"); + pst.setString(3, ""); + pst.executeUpdate(); + pst.close(); + // Nick Name + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "nickname"); + pst.setString(3, auth.getNickname()); + pst.executeUpdate(); + pst.close(); + // Description + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "description"); + pst.setString(3, ""); + pst.executeUpdate(); + pst.close(); + // Rich_Editing + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "rich_editing"); + pst.setString(3, "true"); + pst.executeUpdate(); + pst.close(); + // Comments_Shortcuts + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "comment_shortcuts"); + pst.setString(3, "false"); + pst.executeUpdate(); + pst.close(); + // admin_color + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "admin_color"); + pst.setString(3, "fresh"); + pst.executeUpdate(); + pst.close(); + // use_ssl + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "use_ssl"); + pst.setString(3, "0"); + pst.executeUpdate(); + pst.close(); + // show_admin_bar_front + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "show_admin_bar_front"); + pst.setString(3, "true"); + pst.executeUpdate(); + pst.close(); + // wp_capabilities + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "wp_capabilities"); + pst.setString(3, "a:1:{s:10:\"subscriber\";b:1;}"); + pst.executeUpdate(); + pst.close(); + // wp_user_level + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "wp_user_level"); + pst.setString(3, "0"); + pst.executeUpdate(); + pst.close(); + // default_password_nag + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "default_password_nag"); + pst.setString(3, ""); + pst.executeUpdate(); + pst.close(); + } + rs.close(); + } + if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;"); + pst.setString(1, auth.getNickname()); + rs = pst.executeQuery(); + if (rs.next()) { + int id = rs.getInt(columnID); + // Insert password in the correct table + pst = con.prepareStatement("INSERT INTO xf_user_authenticate (user_id, scheme_class, data) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "XenForo_Authentication_Core12"); + byte[] bytes = auth.getHash().getBytes(); + Blob blob = con.createBlob(); + blob.setBytes(1, bytes); + pst.setBlob(3, blob); + pst.executeUpdate(); + } + rs.close(); + } + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(rs); + close(pst); + close(con); + } + return true; + } + + /** + * Method updatePassword. + * + * @param auth PlayerAuth + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) + */ + @Override + public synchronized boolean updatePassword(PlayerAuth auth) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + try { + if ((con = getConnection()) == null) + return false; + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE LOWER(" + columnName + ")=?;"); + pst.setString(1, auth.getHash()); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + pst.close(); + if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); + pst.setString(1, auth.getNickname()); + rs = pst.executeQuery(); + if (rs.next()) { + int id = rs.getInt(columnID); + // Insert password in the correct table + pst = con.prepareStatement("UPDATE xf_user_authenticate SET data=? WHERE " + columnID + "=?;"); + byte[] bytes = auth.getHash().getBytes(); + Blob blob = con.createBlob(); + blob.setBytes(1, bytes); + pst.setBlob(1, blob); + pst.setInt(2, id); + pst.executeUpdate(); + pst = con.prepareStatement("UPDATE xf_user_authenticate SET scheme_class=? WHERE " + columnID + "=?;"); + pst.setString(1, "XenForo_Authentication_Core12"); + pst.setInt(2, id); + pst.executeUpdate(); + } + rs.close(); + } + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(rs); + close(pst); + close(con); + } + return true; + } + + /** + * Method updateSession. + * + * @param auth PlayerAuth + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) + */ + @Override + public synchronized boolean updateSession(PlayerAuth auth) { + Connection con = null; + PreparedStatement pst = null; + try { + if ((con = getConnection()) == null) + return false; + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE LOWER(" + columnName + ")=?;"); + pst.setString(1, auth.getIp()); + pst.setLong(2, auth.getLastLogin()); + pst.setString(3, auth.getRealName()); + pst.setString(4, auth.getNickname()); + pst.executeUpdate(); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + close(con); + } + return true; + } + + /** + * Method purgeDatabase. + * + * @param until long + * @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) + */ + @Override + public synchronized int purgeDatabase(long until) { + Connection con = null; + PreparedStatement pst = null; + try { + if ((con = getConnection()) == null) + return 0; + pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + " * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) + */ + @Override + public synchronized List autoPurgeDatabase(long until) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + List list = new ArrayList<>(); + try { + if ((con = getConnection()) == null) + return list; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "(); + } finally { + close(rs); + close(pst); + close(con); + } + } + + /** + * Method removeAuth. + * + * @param user String + * @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) + */ + @Override + public synchronized boolean removeAuth(String user) { + Connection con = null; + PreparedStatement pst = null; + try { + if ((con = getConnection()) == null) + return false; + if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { + int id; + ResultSet rs; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); + pst.setString(1, user); + rs = pst.executeQuery(); + if (rs.next()) { + id = rs.getInt(columnID); + // Remove data + PreparedStatement pst2 = con.prepareStatement("DELETE FROM xf_user_authenticate WHERE " + columnID + "=?;"); + pst2.setInt(1, id); + pst2.executeUpdate(); + pst2.close(); + } + } + if (pst != null && !pst.isClosed()) + pst.close(); + pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); + pst.setString(1, user); + pst.executeUpdate(); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + close(con); + } + return true; + } + + /** + * Method updateQuitLoc. + * + * @param auth PlayerAuth + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) + */ + @Override + public synchronized boolean updateQuitLoc(PlayerAuth auth) { + Connection con = null; + PreparedStatement pst = null; + try { + if ((con = getConnection()) == null) + return false; + pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + " =?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE LOWER(" + columnName + ")=?;"); + pst.setDouble(1, auth.getQuitLocX()); + pst.setDouble(2, auth.getQuitLocY()); + pst.setDouble(3, auth.getQuitLocZ()); + pst.setString(4, auth.getWorld()); + pst.setString(5, auth.getNickname()); + pst.executeUpdate(); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + close(con); + } + return true; + } + + /** + * Method getIps. + * + * @param ip String + * @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) + */ + @Override + public synchronized int getIps(String ip) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + int countIp = 0; + try { + if ((con = getConnection()) == null) + return 0; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); + pst.setString(1, ip); + rs = pst.executeQuery(); + while (rs.next()) { + countIp++; + } + return countIp; + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return 0; + } finally { + close(rs); + close(pst); + close(con); + } + } + + /** + * Method updateEmail. + * + * @param auth PlayerAuth + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) + */ + @Override + public synchronized boolean updateEmail(PlayerAuth auth) { + Connection con = null; + PreparedStatement pst = null; + try { + if ((con = getConnection()) == null) + return false; + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + " =? WHERE LOWER(" + columnName + ")=?;"); + pst.setString(1, auth.getEmail()); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + ConsoleLogger.writeStackTrace(ex); + return false; + } finally { + close(pst); + close(con); + } + return true; + } + + /** + * Method updateSalt. + * + * @param auth PlayerAuth + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) + */ + @Override + public synchronized boolean updateSalt(PlayerAuth auth) { + if (columnSalt.isEmpty()) { + return false; + } + Connection con = null; + PreparedStatement pst = null; + try { + if ((con = getConnection()) == null) + return false; + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnSalt + " =? WHERE LOWER(" + columnName + ")=?;"); + pst.setString(1, auth.getSalt()); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + close(con); + } + return true; + } + + /** + * Method reload. + * + * @see fr.xephi.authme.datasource.DataSource#reload() + */ + @Override + public void reload() { + try { + reloadArguments(); + } catch (Exception e) { + ConsoleLogger.showError(e.getMessage()); + ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL informations ! SHUTDOWN..."); + if (Settings.isStopEnabled) { + AuthMe.getInstance().getServer().shutdown(); + } + if (!Settings.isStopEnabled) + AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); + } + } + + /** + * Method close. + * + * @see fr.xephi.authme.datasource.DataSource#close() + */ + @Override + public synchronized void close() { + if (ds != null && !ds.isClosed()) + ds.close(); + } + + /** + * Method close. + * + * @param o AutoCloseable + */ + private void close(AutoCloseable o) { + if (o != null) { + try { + o.close(); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + ConsoleLogger.writeStackTrace(ex); + } + } + } + + /** + * Method getAllAuthsByName. + * + * @param auth PlayerAuth + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) + */ + @Override + public synchronized List getAllAuthsByName(PlayerAuth auth) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + List countIp = new ArrayList<>(); + try { + if ((con = getConnection()) == null) + return countIp; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); + pst.setString(1, auth.getIp()); + rs = pst.executeQuery(); + while (rs.next()) { + countIp.add(rs.getString(columnName)); + } + return countIp; + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList<>(); + } finally { + close(rs); + close(pst); + close(con); + } + } + + /** + * Method getAllAuthsByIp. + * + * @param ip String + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) + */ + @Override + public synchronized List getAllAuthsByIp(String ip) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + List countIp = new ArrayList<>(); + try { + if ((con = getConnection()) == null) + return countIp; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); + pst.setString(1, ip); + rs = pst.executeQuery(); + while (rs.next()) { + countIp.add(rs.getString(columnName)); + } + return countIp; + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList<>(); + } finally { + close(rs); + close(pst); + close(con); + } + } + + /** + * Method getAllAuthsByEmail. + * + * @param email String + * @return List * @throws SQLException * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) + */ + @Override + public synchronized List getAllAuthsByEmail(String email) throws SQLException { + final Connection con = getConnection(); + PreparedStatement pst = null; + ResultSet rs = null; + List countEmail = new ArrayList<>(); + + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;"); + pst.setString(1, email); + rs = pst.executeQuery(); + while (rs.next()) { + countEmail.add(rs.getString(columnName)); + } + return countEmail; + } finally { + close(rs); + close(pst); + close(con); + } + } + + /** + * Method purgeBanned. + * + * @param banned List + * @see fr.xephi.authme.datasource.DataSource#purgeBanned(List) + */ + @Override + public synchronized void purgeBanned(List banned) { + Connection con = null; + PreparedStatement pst = null; + try { + if ((con = getConnection()) == null) + return; + for (String name : banned) { + pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); + pst.setString(1, name); + pst.executeUpdate(); + } + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + } finally { + close(pst); + close(con); + } + } + + /** + * Method getType. + * + * @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType() + */ + @Override + public DataSourceType getType() { + return DataSourceType.MYSQL; + } + + /** + * Method isLogged. + * + * @param user String + * @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) + */ + @Override + public boolean isLogged(String user) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + try { + if ((con = getConnection()) == null) + return false; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); + pst.setString(1, user); + rs = pst.executeQuery(); + if (rs.next()) + return (rs.getInt(columnLogged) == 1); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(rs); + close(pst); + close(con); + } + return false; + } + + /** + * Method setLogged. + * + * @param user String + * @see fr.xephi.authme.datasource.DataSource#setLogged(String) + */ + @Override + public void setLogged(String user) { + Connection con = null; + PreparedStatement pst = null; + try { + if ((con = getConnection()) == null) + return; + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); + pst.setInt(1, 1); + pst.setString(2, user); + pst.executeUpdate(); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + } finally { + close(pst); + close(con); + } + } + + /** + * Method setUnlogged. + * + * @param user String + * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) + */ + @Override + public void setUnlogged(String user) { + Connection con = null; + PreparedStatement pst = null; + if (user != null) + try { + if ((con = getConnection()) == null) + return; + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); + pst.setInt(1, 0); + pst.setString(2, user); + pst.executeUpdate(); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + } finally { + close(pst); + close(con); + } + } + + /** + * Method purgeLogged. + * + * @see fr.xephi.authme.datasource.DataSource#purgeLogged() + */ + @Override + public void purgeLogged() { + Connection con = null; + PreparedStatement pst = null; + try { + if ((con = getConnection()) == null) + return; + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;"); + pst.setInt(1, 0); + pst.setInt(2, 1); + pst.executeUpdate(); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + } finally { + close(pst); + close(con); + } + } + + /** + * Method getAccountsRegistered. + * + * @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered() + */ + @Override + public int getAccountsRegistered() { + int result = 0; + Connection con = null; + PreparedStatement pst = null; + ResultSet rs; + try { + if ((con = getConnection()) == null) + return result; + pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";"); + rs = pst.executeQuery(); + if (rs != null && rs.next()) { + result = rs.getInt(1); + } + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return result; + } finally { + close(pst); + close(con); + } + return result; + } + + /** + * Method updateName. + * + * @param oldone String + * @param newone String + * @see fr.xephi.authme.datasource.DataSource#updateName(String, String) + */ + @Override + public void updateName(String oldone, String newone) { + Connection con = null; + PreparedStatement pst = null; + try { + if ((con = getConnection()) == null) + return; + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE LOWER(" + columnName + ")=?;"); + pst.setString(1, newone); + pst.setString(2, oldone); + pst.executeUpdate(); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + } finally { + close(pst); + close(con); + } + } + + /** + * Method getAllAuths. + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuths() + */ + @Override + public List getAllAuths() { + List auths = new ArrayList<>(); + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + try { + if ((con = getConnection()) == null) + return auths; + pst = con.prepareStatement("SELECT * FROM " + tableName + ";"); + rs = pst.executeQuery(); + while (rs.next()) { + PlayerAuth pAuth; + int id = rs.getInt(columnID); + if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } else { + if (!columnSalt.isEmpty()) { + if (!columnGroup.isEmpty()) + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + else + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } else { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } + } + if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { + ResultSet rsid; + pst = con.prepareStatement("SELECT * FROM xf_user_authenticate WHERE " + columnID + "=?;"); + pst.setInt(1, id); + rsid = pst.executeQuery(); + if (rsid.next()) { + Blob blob = rsid.getBlob("data"); + byte[] bytes = blob.getBytes(1, (int) blob.length()); + pAuth.setHash(new String(bytes)); + } + rsid.close(); + } + auths.add(pAuth); + } + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return auths; + } finally { + close(pst); + close(con); + close(rs); + } + return auths; + } + + /** + * Method getLoggedPlayers. + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers() + */ + @Override + public List getLoggedPlayers() { + List auths = new ArrayList<>(); + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + try { + if ((con = getConnection()) == null) + return auths; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;"); + rs = pst.executeQuery(); + while (rs.next()) { + PlayerAuth pAuth; + int id = rs.getInt(columnID); + if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } else { + if (!columnSalt.isEmpty()) { + if (!columnGroup.isEmpty()) + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + else + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } else { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } + } + if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { + ResultSet rsid; + pst = con.prepareStatement("SELECT * FROM xf_user_authenticate WHERE " + columnID + "=?;"); + pst.setInt(1, id); + rsid = pst.executeQuery(); + if (rsid.next()) { + Blob blob = rsid.getBlob("data"); + byte[] bytes = blob.getBytes(1, (int) blob.length()); + pAuth.setHash(new String(bytes)); + } + rsid.close(); + } + auths.add(pAuth); + } + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + return auths; + } finally { + close(pst); + close(rs); + close(con); + } + return auths; + } + +} diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java index b651af60..f4455926 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java @@ -66,7 +66,7 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter { byte windowId = packet.getIntegers().read(0).byteValue(); if (windowId == PLAYER_INVENTORY && Settings.protectInventoryBeforeLogInEnabled - && !PlayerCache.getInstance().isAuthenticated(player.getName())) { + && !PlayerCache.getInstance().isAuthenticated(player.getName())) { packetEvent.setCancelled(true); } } @@ -108,9 +108,9 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter { //storedInventory and hotbar System.arraycopy(storedInventory, 0, completeInventory - , playerCrafting.length + armorContents.length, storedInventory.length); + , playerCrafting.length + armorContents.length, storedInventory.length); System.arraycopy(hotbar, 0, completeInventory - , playerCrafting.length + armorContents.length + storedInventory.length, hotbar.length); + , playerCrafting.length + armorContents.length + storedInventory.length, hotbar.length); inventoryPacket.getItemArrayModifier().write(0, completeInventory); try { diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java index 086d158f..e56fc80f 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java @@ -29,10 +29,10 @@ import java.util.logging.Logger; /** * PermissionsManager. - *

+ *

* A permissions manager, to manage and use various permissions systems. * This manager supports dynamic plugin hooking and various other features. - *

+ *

* Written by Tim Visée. * * @author Tim Visée, http://timvisee.com @@ -267,9 +267,9 @@ public class PermissionsManager { // Check if any known permissions system is enabling if (pluginName.equals("PermissionsEx") || pluginName.equals("PermissionsBukkit") || - pluginName.equals("bPermissions") || pluginName.equals("GroupManager") || - pluginName.equals("zPermissions") || pluginName.equals("Vault") || - pluginName.equals("Permissions")) { + pluginName.equals("bPermissions") || pluginName.equals("GroupManager") || + pluginName.equals("zPermissions") || pluginName.equals("Vault") || + pluginName.equals("Permissions")) { this.log.info(pluginName + " plugin enabled, dynamically updating permissions hooks!"); setup(); } @@ -287,9 +287,9 @@ public class PermissionsManager { // Is the WorldGuard plugin disabled if (pluginName.equals("PermissionsEx") || pluginName.equals("PermissionsBukkit") || - pluginName.equals("bPermissions") || pluginName.equals("GroupManager") || - pluginName.equals("zPermissions") || pluginName.equals("Vault") || - pluginName.equals("Permissions")) { + pluginName.equals("bPermissions") || pluginName.equals("GroupManager") || + pluginName.equals("zPermissions") || pluginName.equals("Vault") || + pluginName.equals("Permissions")) { this.log.info(pluginName + " plugin disabled, updating hooks!"); setup(); } @@ -915,4 +915,4 @@ public class PermissionsManager { return this.name; } } -} \ No newline at end of file +} diff --git a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java index 5bddc07d..9ce2bf4a 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java @@ -248,7 +248,7 @@ public class AsyncronousJoin { } String[] msg = isAuthAvailable ? m.send("login_msg") : - m.send("reg_" + (Settings.emailRegistration ? "email_" : "") + "msg"); + m.send("reg_" + (Settings.emailRegistration ? "email_" : "") + "msg"); BukkitTask msgTask = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval)); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgTask); } @@ -306,7 +306,7 @@ public class AsyncronousJoin { Material cur = player.getLocation().getBlock().getType(); Material top = player.getLocation().add(0D, 1D, 0D).getBlock().getType(); if (cur == Material.PORTAL || cur == Material.ENDER_PORTAL - || top == Material.PORTAL || top == Material.ENDER_PORTAL) { + || top == Material.PORTAL || top == Material.ENDER_PORTAL) { m.send(player, "unsafe_spawn"); player.teleport(spawnLoc); } diff --git a/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java b/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java index 6f115659..fbbb88f8 100644 --- a/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java +++ b/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java @@ -25,8 +25,8 @@ public class ProcessSyncronousPlayerQuit implements Runnable { * @param needToChange boolean */ public ProcessSyncronousPlayerQuit(AuthMe plugin, Player player - , boolean isOp, boolean isFlying - , boolean needToChange) { + , boolean isOp, boolean isFlying + , boolean needToChange) { this.plugin = plugin; this.player = player; this.isOp = isOp; diff --git a/src/main/java/fr/xephi/authme/security/PasswordSecurity.java b/src/main/java/fr/xephi/authme/security/PasswordSecurity.java index 453db7fb..2a679da7 100644 --- a/src/main/java/fr/xephi/authme/security/PasswordSecurity.java +++ b/src/main/java/fr/xephi/authme/security/PasswordSecurity.java @@ -28,7 +28,7 @@ public class PasswordSecurity { * @return String * @throws NoSuchAlgorithmException */ public static String createSalt(int length) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { byte[] msg = new byte[40]; rnd.nextBytes(msg); MessageDigest sha1 = MessageDigest.getInstance("SHA1"); diff --git a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java index b0c1adbe..23412bf1 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java +++ b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java @@ -21,37 +21,37 @@ import java.security.SecureRandom; * BCrypt implements OpenBSD-style Blowfish password hashing using the scheme * described in "A Future-Adaptable Password Scheme" by Niels Provos and David * Mazieres. - *

+ *

* This password hashing system tries to thwart off-line password cracking using * a computationally-intensive hashing algorithm, based on Bruce Schneier's * Blowfish cipher. The work factor of the algorithm is parameterised, so it can * be increased as computers get faster. - *

+ *

* Usage is really simple. To hash a password for the first time, call the * hashpw method with a random salt, like this: - *

+ *

* * String pw_hash = BCrypt.hashpw(plain_password, BCrypt.gensalt());
*
- *

+ *

* To check whether a plaintext password matches one that has been hashed * previously, use the checkpw method: - *

+ *

* * if (BCrypt.checkpw(candidate_password, stored_hash))
*     System.out.println("It matches");
* else
*     System.out.println("It does not match");
*
- *

+ *

* The gensalt() method takes an optional parameter (log_rounds) that determines * the computational complexity of the hashing: - *

+ *

* * String strong_salt = BCrypt.gensalt(10)
* String stronger_salt = BCrypt.gensalt(12)
*
- *

+ *

* The amount of work increases exponentially (2**log_rounds), so each increment * is twice as much work. The default log_rounds is 10, and the valid range is 4 * to 31. @@ -95,7 +95,7 @@ public class BCRYPT implements EncryptionMethod { * @return base64-encoded string * @throws IllegalArgumentException if the length is invalid * @throws IllegalArgumentException */ private static String encode_base64(byte d[], int len) - throws IllegalArgumentException { + throws IllegalArgumentException { int off = 0; StringBuffer rs = new StringBuffer(); int c1, c2; @@ -150,7 +150,7 @@ public class BCRYPT implements EncryptionMethod { * @return an array containing the decoded bytes * @throws IllegalArgumentException if maxolen is invalid * @throws IllegalArgumentException */ private static byte[] decode_base64(String s, int maxolen) - throws IllegalArgumentException { + throws IllegalArgumentException { StringBuffer rs = new StringBuffer(); int off = 0, slen = s.length(), olen = 0; byte ret[]; @@ -513,7 +513,7 @@ public class BCRYPT implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return hashpw(password, salt); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java index 4db8d8c6..2ff8a44f 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java +++ b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java @@ -1,42 +1,42 @@ -package fr.xephi.authme.security.crypts; - -import java.security.NoSuchAlgorithmException; - -/** - */ -public class BCRYPT2Y implements EncryptionMethod { - - /** - * Method getHash. - * - * @param password String - * @param salt String - * @param name String - * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) - */ - @Override - public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { - if (salt.length() == 22) - salt = "$2y$10$" + salt; - return (BCRYPT.hashpw(password, salt)); - } - - /** - * Method comparePassword. - * - * @param hash String - * @param password String - * @param playerName String - * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) - */ - @Override - public boolean comparePassword(String hash, String password, - String playerName) throws NoSuchAlgorithmException { - String ok = hash.substring(0, 29); - if (ok.length() != 29) - return false; - return hash.equals(getHash(password, ok, playerName)); - } - -} +package fr.xephi.authme.security.crypts; + +import java.security.NoSuchAlgorithmException; + +/** + */ +public class BCRYPT2Y implements EncryptionMethod { + + /** + * Method getHash. + * + * @param password String + * @param salt String + * @param name String + * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) + */ + @Override + public String getHash(String password, String salt, String name) + throws NoSuchAlgorithmException { + if (salt.length() == 22) + salt = "$2y$10$" + salt; + return (BCRYPT.hashpw(password, salt)); + } + + /** + * Method comparePassword. + * + * @param hash String + * @param password String + * @param playerName String + * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) + */ + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + String ok = hash.substring(0, 29); + if (ok.length() != 29) + return false; + return hash.equals(getHash(password, ok, playerName)); + } + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/CRAZYCRYPT1.java b/src/main/java/fr/xephi/authme/security/crypts/CRAZYCRYPT1.java index ac890a88..041113c7 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/CRAZYCRYPT1.java +++ b/src/main/java/fr/xephi/authme/security/crypts/CRAZYCRYPT1.java @@ -36,7 +36,7 @@ public class CRAZYCRYPT1 implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { final String text = "ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password; try { final MessageDigest md = MessageDigest.getInstance("SHA-512"); diff --git a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java index e6bc7c03..18e5b532 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java +++ b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java @@ -19,7 +19,7 @@ public class CryptPBKDF2 implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { String result = "pbkdf2_sha256$10000$" + salt + "$"; PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000); PBKDF2Engine engine = new PBKDF2Engine(params); @@ -46,4 +46,4 @@ public class CryptPBKDF2 implements EncryptionMethod { return engine.verifyKey(password); } -} \ No newline at end of file +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2Django.java b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2Django.java index 13aaf49f..0bf1d171 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2Django.java +++ b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2Django.java @@ -20,7 +20,7 @@ public class CryptPBKDF2Django implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { String result = "pbkdf2_sha256$15000$" + salt + "$"; PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 15000); PBKDF2Engine engine = new PBKDF2Engine(params); diff --git a/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java b/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java index 486ffbae..fb008fec 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java +++ b/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java @@ -15,7 +15,7 @@ public class DOUBLEMD5 implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.reset(); md5.update(message.getBytes()); @@ -33,7 +33,7 @@ public class DOUBLEMD5 implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return getMD5(getMD5(password)); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java b/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java index e56e5ecd..ac61f993 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java +++ b/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java @@ -27,7 +27,7 @@ public interface EncryptionMethod { * @return Hashing password * @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException */ String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException; + throws NoSuchAlgorithmException; /** * @param hash @@ -36,6 +36,6 @@ public interface EncryptionMethod { * @return true if password match, false else * @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException */ boolean comparePassword(String hash, String password, String playerName) - throws NoSuchAlgorithmException; + throws NoSuchAlgorithmException; } diff --git a/src/main/java/fr/xephi/authme/security/crypts/IPB3.java b/src/main/java/fr/xephi/authme/security/crypts/IPB3.java index 857c3fef..60bd159b 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/IPB3.java +++ b/src/main/java/fr/xephi/authme/security/crypts/IPB3.java @@ -17,7 +17,7 @@ public class IPB3 implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.reset(); md5.update(message.getBytes()); @@ -35,7 +35,7 @@ public class IPB3 implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return getMD5(getMD5(salt) + getMD5(password)); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java b/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java index 73fbd3bd..9a988ad1 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java +++ b/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java @@ -15,7 +15,7 @@ public class JOOMLA implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.reset(); md5.update(message.getBytes()); @@ -33,7 +33,7 @@ public class JOOMLA implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return getMD5(password + salt) + ":" + salt; } diff --git a/src/main/java/fr/xephi/authme/security/crypts/MD5.java b/src/main/java/fr/xephi/authme/security/crypts/MD5.java index af94098b..38ba26fe 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/MD5.java +++ b/src/main/java/fr/xephi/authme/security/crypts/MD5.java @@ -15,7 +15,7 @@ public class MD5 implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.reset(); md5.update(message.getBytes()); @@ -33,7 +33,7 @@ public class MD5 implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return getMD5(password); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java b/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java index ab2878f4..4004f7a3 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java +++ b/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java @@ -15,7 +15,7 @@ public class MD5VB implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.reset(); md5.update(message.getBytes()); @@ -33,7 +33,7 @@ public class MD5VB implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return "$MD5vb$" + salt + "$" + getMD5(getMD5(password) + salt); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/MYBB.java b/src/main/java/fr/xephi/authme/security/crypts/MYBB.java index 0cae271f..8e1b0d1a 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/MYBB.java +++ b/src/main/java/fr/xephi/authme/security/crypts/MYBB.java @@ -17,7 +17,7 @@ public class MYBB implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.reset(); md5.update(message.getBytes()); @@ -35,7 +35,7 @@ public class MYBB implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return getMD5(getMD5(salt) + getMD5(password)); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java b/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java index 58ebdc74..30e580b6 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java +++ b/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java @@ -214,7 +214,7 @@ public class PHPBB implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return phpbb_hash(password, salt); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java b/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java index 54e6cd66..d793fbd4 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java +++ b/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java @@ -21,7 +21,7 @@ public class PHPFUSION implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getSHA1(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest sha1 = MessageDigest.getInstance("SHA1"); sha1.reset(); sha1.update(message.getBytes()); @@ -39,7 +39,7 @@ public class PHPFUSION implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { String digest = null; String algo = "HmacSHA256"; String keyString = getSHA1(salt); diff --git a/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java b/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java index afb6dde9..7f9bffaa 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java +++ b/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java @@ -16,7 +16,7 @@ public class PLAINTEXT implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return password; } diff --git a/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java b/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java index ad3901e4..8c6f4a51 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java +++ b/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java @@ -17,7 +17,7 @@ public class ROYALAUTH implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { for (int i = 0; i < 25; i++) password = hash(password, salt); return password; @@ -31,7 +31,7 @@ public class ROYALAUTH implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ public String hash(String password, String salt) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA-512"); md.update(password.getBytes()); byte byteData[] = md.digest(); diff --git a/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java b/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java index f71018ac..88194ad7 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java @@ -17,7 +17,7 @@ public class SALTED2MD5 implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.reset(); md5.update(message.getBytes()); @@ -35,7 +35,7 @@ public class SALTED2MD5 implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return getMD5(getMD5(password) + salt); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java b/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java index dcacb63c..ea58023a 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java @@ -17,7 +17,7 @@ public class SALTEDSHA512 implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getSHA512(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest sha512 = MessageDigest.getInstance("SHA-512"); sha512.reset(); sha512.update(message.getBytes()); @@ -35,7 +35,7 @@ public class SALTEDSHA512 implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return getSHA512(password + salt); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/SHA1.java b/src/main/java/fr/xephi/authme/security/crypts/SHA1.java index 7d1a48a6..834428af 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SHA1.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SHA1.java @@ -15,7 +15,7 @@ public class SHA1 implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getSHA1(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest sha1 = MessageDigest.getInstance("SHA1"); sha1.reset(); sha1.update(message.getBytes()); @@ -33,7 +33,7 @@ public class SHA1 implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return getSHA1(password); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/SHA256.java b/src/main/java/fr/xephi/authme/security/crypts/SHA256.java index b0ddfa56..2522852c 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SHA256.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SHA256.java @@ -15,7 +15,7 @@ public class SHA256 implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getSHA256(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest sha256 = MessageDigest.getInstance("SHA-256"); sha256.reset(); sha256.update(message.getBytes()); @@ -33,7 +33,7 @@ public class SHA256 implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return "$SHA$" + salt + "$" + getSHA256(getSHA256(password) + salt); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/SHA512.java b/src/main/java/fr/xephi/authme/security/crypts/SHA512.java index a6ccd615..df4f7e41 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SHA512.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SHA512.java @@ -15,7 +15,7 @@ public class SHA512 implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getSHA512(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest sha512 = MessageDigest.getInstance("SHA-512"); sha512.reset(); sha512.update(message.getBytes()); @@ -33,7 +33,7 @@ public class SHA512 implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return getSHA512(password); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/SMF.java b/src/main/java/fr/xephi/authme/security/crypts/SMF.java index ce15e030..af40aa81 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SMF.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SMF.java @@ -15,7 +15,7 @@ public class SMF implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getSHA1(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest sha1 = MessageDigest.getInstance("SHA1"); sha1.reset(); sha1.update(message.getBytes()); @@ -33,7 +33,7 @@ public class SMF implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return getSHA1(name.toLowerCase() + password); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/WBB3.java b/src/main/java/fr/xephi/authme/security/crypts/WBB3.java index 1d966423..57bd1b2c 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/WBB3.java +++ b/src/main/java/fr/xephi/authme/security/crypts/WBB3.java @@ -17,7 +17,7 @@ public class WBB3 implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException */ private static String getSHA1(String message) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { MessageDigest sha1 = MessageDigest.getInstance("SHA1"); sha1.reset(); sha1.update(message.getBytes()); @@ -35,7 +35,7 @@ public class WBB3 implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return getSHA1(salt.concat(getSHA1(salt.concat(getSHA1(password))))); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/WBB4.java b/src/main/java/fr/xephi/authme/security/crypts/WBB4.java index ebe79438..50ef3fb7 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/WBB4.java +++ b/src/main/java/fr/xephi/authme/security/crypts/WBB4.java @@ -16,7 +16,7 @@ public class WBB4 implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return BCRYPT.getDoubleHash(password, salt); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java b/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java index 596aafe8..eee8bd69 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java +++ b/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java @@ -2,15 +2,15 @@ package fr.xephi.authme.security.crypts; /** * The Whirlpool hashing function. - *

- *

+ *

+ *

* References - *

- *

+ *

+ *

* The Whirlpool algorithm was developed by Paulo S. L. M. Barreto and Vincent Rijmen. - *

+ *

* See P.S.L.M. Barreto, V. Rijmen, ``The Whirlpool hashing function,'' First * NESSIE workshop, 2000 (tweaked version, 2003), * + *

* ==================================================================== * ========= - *

+ *

* Differences from version 2.1: - *

+ *

* - Suboptimal diffusion matrix replaced by cir(1, 1, 4, 1, 8, 5, 2, * 9). - *

+ *

* ==================================================================== * ========= - *

+ *

* Differences from version 2.0: - *

+ *

* - Generation of ISO/IEC 10118-3 test vectors. - Bug fix: nonzero * carry was ignored when tallying the data length (this bug apparently * only manifested itself when feeding data in pieces rather than in a * single chunk at once). - *

+ *

* Differences from version 1.0: - *

+ *

* - Original S-box replaced by the tweaked, hardware-efficient * version. - *

+ *

* ==================================================================== * ========= - *

+ *

* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -401,7 +401,7 @@ public class WHIRLPOOL implements EncryptionMethod { * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { byte[] digest = new byte[DIGESTBYTES]; NESSIEinit(); NESSIEadd(password); diff --git a/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java b/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java index 557c4bdd..b16015ad 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java +++ b/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java @@ -137,7 +137,7 @@ public class WORDPRESS implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { byte random[] = new byte[6]; this.randomGen.nextBytes(random); return crypt(password, gensaltPrivate(stringToUtf8(new String(random)))); diff --git a/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java b/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java index 6848d2ea..1560f956 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java +++ b/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java @@ -31,7 +31,7 @@ public class XAUTH implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { String hash = getWhirlpool(salt + password).toLowerCase(); int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length()); return hash.substring(0, saltPos) + salt + hash.substring(saltPos); diff --git a/src/main/java/fr/xephi/authme/security/crypts/XF.java b/src/main/java/fr/xephi/authme/security/crypts/XF.java index 41d665ac..0a879a21 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/XF.java +++ b/src/main/java/fr/xephi/authme/security/crypts/XF.java @@ -23,7 +23,7 @@ public class XF implements EncryptionMethod { */ @Override public String getHash(String password, String salt, String name) - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException { return getSHA256(getSHA256(password) + regmatch("\"salt\";.:..:\"(.*)\";.:.:\"hashFunc\"", salt)); } diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java index fb8252ba..f1009c0a 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java @@ -115,7 +115,7 @@ public class PBKDF2Engine implements PBKDF2 { * ISO-8559-1 encoding. Output result as * "Salt:iteration-count:PBKDF2" with binary data in hexadecimal * encoding. - *

+ *

* Example: Password "password" (without the quotes) leads to * 48290A0B96C426C3:1000:973899B1D4AFEB3ED371060D0797E0EE0142BD04 * @@ -123,7 +123,7 @@ public class PBKDF2Engine implements PBKDF2 { * @throws IOException * @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException */ public static void main(String[] args) - throws IOException, NoSuchAlgorithmException { + throws IOException, NoSuchAlgorithmException { String password = "password"; String candidate = null; PBKDF2Formatter formatter = new PBKDF2HexFormatter(); diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 49a78db0..7dbb2f26 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -48,46 +48,46 @@ public final class Settings extends YamlConfiguration { // Due to compatibility issues with plugins like FactionsChat public static Boolean isChatAllowed; public static boolean isPermissionCheckEnabled, isRegistrationEnabled, - isForcedRegistrationEnabled, isTeleportToSpawnEnabled, - isSessionsEnabled, isAllowRestrictedIp, - isMovementAllowed, isKickNonRegisteredEnabled, - isForceSingleSessionEnabled, isForceSpawnLocOnJoinEnabled, - isSaveQuitLocationEnabled, isForceSurvivalModeEnabled, - isResetInventoryIfCreative, isCachingEnabled, - isKickOnWrongPasswordEnabled, getEnablePasswordVerifier, - protectInventoryBeforeLogInEnabled, isBackupActivated, - isBackupOnStart, isBackupOnStop, isStopEnabled, reloadSupport, - rakamakUseIp, noConsoleSpam, removePassword, displayOtherAccounts, - useCaptcha, emailRegistration, multiverse, bungee, - banUnsafeIp, doubleEmailCheck, sessionExpireOnIpChange, - disableSocialSpy, forceOnlyAfterLogin, useEssentialsMotd, usePurge, - purgePlayerDat, purgeEssentialsFile, supportOldPassword, - purgeLimitedCreative, purgeAntiXray, purgePermissions, - enableProtection, enableAntiBot, recallEmail, useWelcomeMessage, - broadcastWelcomeMessage, forceRegKick, forceRegLogin, - checkVeryGames, delayJoinLeaveMessages, noTeleport, applyBlindEffect, - customAttributes, generateImage, isRemoveSpeedEnabled, isMySQLWebsite; + isForcedRegistrationEnabled, isTeleportToSpawnEnabled, + isSessionsEnabled, isAllowRestrictedIp, + isMovementAllowed, isKickNonRegisteredEnabled, + isForceSingleSessionEnabled, isForceSpawnLocOnJoinEnabled, + isSaveQuitLocationEnabled, isForceSurvivalModeEnabled, + isResetInventoryIfCreative, isCachingEnabled, + isKickOnWrongPasswordEnabled, getEnablePasswordVerifier, + protectInventoryBeforeLogInEnabled, isBackupActivated, + isBackupOnStart, isBackupOnStop, isStopEnabled, reloadSupport, + rakamakUseIp, noConsoleSpam, removePassword, displayOtherAccounts, + useCaptcha, emailRegistration, multiverse, bungee, + banUnsafeIp, doubleEmailCheck, sessionExpireOnIpChange, + disableSocialSpy, forceOnlyAfterLogin, useEssentialsMotd, usePurge, + purgePlayerDat, purgeEssentialsFile, supportOldPassword, + purgeLimitedCreative, purgeAntiXray, purgePermissions, + enableProtection, enableAntiBot, recallEmail, useWelcomeMessage, + broadcastWelcomeMessage, forceRegKick, forceRegLogin, + checkVeryGames, delayJoinLeaveMessages, noTeleport, applyBlindEffect, + customAttributes, generateImage, isRemoveSpeedEnabled, isMySQLWebsite; public static String getNickRegex, getUnloggedinGroup, getMySQLHost, - getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, - getMySQLTablename, getMySQLColumnName, getMySQLColumnPassword, - getMySQLColumnIp, getMySQLColumnLastLogin, getMySQLColumnSalt, - getMySQLColumnGroup, getMySQLColumnEmail, unRegisteredGroup, - backupWindowsPath, getRegisteredGroup, - messagesLanguage, getMySQLlastlocX, getMySQLlastlocY, - getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount, - getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName, - getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld, - getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged, - spawnPriority, crazyloginFileName, getPassRegex, - getMySQLColumnRealName; + getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, + getMySQLTablename, getMySQLColumnName, getMySQLColumnPassword, + getMySQLColumnIp, getMySQLColumnLastLogin, getMySQLColumnSalt, + getMySQLColumnGroup, getMySQLColumnEmail, unRegisteredGroup, + backupWindowsPath, getRegisteredGroup, + messagesLanguage, getMySQLlastlocX, getMySQLlastlocY, + getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount, + getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName, + getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld, + getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged, + spawnPriority, crazyloginFileName, getPassRegex, + getMySQLColumnRealName; public static int getWarnMessageInterval, getSessionTimeout, - getRegistrationTimeout, getMaxNickLength, getMinNickLength, - getPasswordMinLen, getMovementRadius, getmaxRegPerIp, - getNonActivatedGroup, passwordMaxLength, getRecoveryPassLength, - getMailPort, maxLoginTry, captchaLength, saltLength, - getmaxRegPerEmail, bCryptLog2Rounds, getPhpbbGroup, - antiBotSensibility, antiBotDuration, delayRecall, getMaxLoginPerIp, - getMaxJoinPerIp, getMySQLMaxConnections; + getRegistrationTimeout, getMaxNickLength, getMinNickLength, + getPasswordMinLen, getMovementRadius, getmaxRegPerIp, + getNonActivatedGroup, passwordMaxLength, getRecoveryPassLength, + getMailPort, maxLoginTry, captchaLength, saltLength, + getmaxRegPerEmail, bCryptLog2Rounds, getPhpbbGroup, + antiBotSensibility, antiBotDuration, delayRecall, getMaxLoginPerIp, + getMaxJoinPerIp, getMySQLMaxConnections; protected static YamlConfiguration configFile; private static AuthMe plugin; private static Settings instance; @@ -480,7 +480,7 @@ public final class Settings extends YamlConfiguration { changes = true; } if (configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA1") || - configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA256")) { + configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA256")) { set("settings.security.passwordHash", "XENFORO"); changes = true; } @@ -685,7 +685,7 @@ public final class Settings extends YamlConfiguration { /** * Saves current configuration (plus defaults) to disk. - *

+ *

* If defaults and configuration are empty, saves blank file. * * @return True if saved successfully diff --git a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java index 76bd9d8c..21fd8f0d 100644 --- a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java +++ b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java @@ -13,7 +13,7 @@ import java.util.zip.GZIPInputStream; public class GeoLiteAPI { private static final String GEOIP_URL = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry" + - "/GeoIP.dat.gz"; + "/GeoIP.dat.gz"; private static final AuthMe plugin = AuthMe.getInstance(); private static LookupService lookupService; @@ -31,7 +31,7 @@ public class GeoLiteAPI { try { lookupService = new LookupService(data); plugin.getLogger().info("[LICENSE] This product uses data from the GeoLite API created by MaxMind, " + - "available at http://www.maxmind.com"); + "available at http://www.maxmind.com"); return true; } catch (IOException e) { return false; diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java index 3262f2f5..a928f05f 100644 --- a/src/main/java/fr/xephi/authme/util/Utils.java +++ b/src/main/java/fr/xephi/authme/util/Utils.java @@ -58,7 +58,7 @@ public final class Utils { try { lookupService = new LookupService(data); ConsoleLogger.info("[LICENSE] This product uses data from the GeoLite API created by MaxMind, " + - "available at http://www.maxmind.com"); + "available at http://www.maxmind.com"); return true; } catch (IOException e) { return false; @@ -154,7 +154,7 @@ public final class Utils { /** * TODO: This method requires better explanation. - *

+ *

* Set the normal group of a player. * * @param player The player. @@ -200,7 +200,7 @@ public final class Utils { public static boolean isUnrestricted(Player player) { return Settings.isAllowRestrictedIp && !Settings.getUnrestrictedName.isEmpty() - && (Settings.getUnrestrictedName.contains(player.getName())); + && (Settings.getUnrestrictedName.contains(player.getName())); } /** @@ -302,7 +302,7 @@ public final class Utils { } } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { ConsoleLogger.showError("Could not retrieve list of online players: [" - + e.getClass().getName() + "] " + e.getMessage()); + + e.getClass().getName() + "] " + e.getMessage()); } return Collections.emptyList(); } @@ -333,8 +333,8 @@ public final class Utils { if (player.hasMetadata("NPC")) { return true; } else if (plugin.combatTagPlus != null - && player instanceof Player - && plugin.combatTagPlus.getNpcPlayerHelper().isNpc((Player) player)) { + && player instanceof Player + && plugin.combatTagPlus.getNpcPlayerHelper().isNpc((Player) player)) { return true; } return false;