From b956f28fc079583b03d0fedeccbd1154d43ae78a Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Wed, 22 Jul 2015 21:45:53 +0200 Subject: [PATCH 1/5] Maybe an NPE ? :/ --- src/main/java/fr/xephi/authme/AuthMe.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index d8a550bef..56c813fdc 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -428,7 +428,10 @@ public class AuthMe extends JavaPlugin { } if (database != null) { - database.close(); + try { + database.close(); + } catch (Exception e) { + } } if (Settings.isBackupActivated && Settings.isBackupOnStop) { @@ -444,8 +447,7 @@ public class AuthMe extends JavaPlugin { return authme; } - public void savePlayer(Player player) - throws IllegalStateException, NullPointerException { + public void savePlayer(Player player) { try { if ((citizens.isNPC(player)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) { return; From 38f4cb0231a3706621ae0e01ed7dd7567f2c26a5 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Wed, 22 Jul 2015 21:47:08 +0200 Subject: [PATCH 2/5] Push a model for module type - DEV --- .../java/fr/xephi/authme/modules/Module.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/fr/xephi/authme/modules/Module.java diff --git a/src/main/java/fr/xephi/authme/modules/Module.java b/src/main/java/fr/xephi/authme/modules/Module.java new file mode 100644 index 000000000..779beb65e --- /dev/null +++ b/src/main/java/fr/xephi/authme/modules/Module.java @@ -0,0 +1,27 @@ +package fr.xephi.authme.modules; + +import fr.xephi.authme.AuthMe; + +public interface Module { + + public String getName(); + + public AuthMe getInstanceOfAuthMe(); + + public Module getInstance(); + + public enum ModuleType { + MANAGER, + MYSQL, + ACTIONS, + CONVERTERS, + EMAILS, + CUSTOM; + } + + public ModuleType getType(); + + public boolean load(); + + public boolean unload(); +} From bcd31c5844d4273457c954754c40acb017d283c0 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Thu, 23 Jul 2015 13:01:47 +0200 Subject: [PATCH 3/5] Change how SQLite store logged --- .../fr/xephi/authme/datasource/SQLite.java | 81 +++++++++++++++++-- 1 file changed, 75 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 0ea0a547b..5c75d2694 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -12,9 +12,7 @@ import java.util.List; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException; -import fr.xephi.authme.settings.PlayersLogs; import fr.xephi.authme.settings.Settings; public class SQLite implements DataSource { @@ -34,6 +32,7 @@ public class SQLite implements DataSource { private String columnEmail; private String columnID; private Connection con; + private String columnLogged; public SQLite() { this.database = Settings.getMySQLDatabase; @@ -50,6 +49,7 @@ public class SQLite implements DataSource { this.lastlocWorld = Settings.getMySQLlastlocWorld; this.columnEmail = Settings.getMySQLColumnEmail; this.columnID = Settings.getMySQLColumnId; + this.columnLogged = Settings.getMySQLColumnLogged; try { this.connect(); @@ -120,6 +120,11 @@ public class SQLite implements DataSource { if (!rs.next()) { st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';"); } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnLogged); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLogged + " BIGINT DEFAULT '0';"); + } } finally { close(rs); close(st); @@ -509,22 +514,86 @@ public class SQLite implements DataSource { @Override public boolean isLogged(String user) { - return PlayerCache.getInstance().isAuthenticated(user); + PreparedStatement pst = null; + ResultSet rs = null; + try { + 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 (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(rs); + close(pst); + } + return false; } @Override public void setLogged(String user) { - PlayersLogs.getInstance().savePlayerLogs(); + PreparedStatement pst = null; + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); + pst.setInt(1, 1); + pst.setString(2, user); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return; + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return; + } finally { + close(pst); + } + return; } @Override public void setUnlogged(String user) { - PlayersLogs.getInstance().savePlayerLogs(); + PreparedStatement pst = null; + if (user != null) + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); + pst.setInt(1, 0); + pst.setString(2, user); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return; + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return; + } finally { + close(pst); + } + return; } @Override public void purgeLogged() { - PlayersLogs.getInstance().clear(); + PreparedStatement pst = null; + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;"); + pst.setInt(1, 0); + pst.setInt(2, 1); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return; + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return; + } finally { + close(pst); + } + return; } @Override From a9dcf1575934c129f54f4913ccbc378d45b9e625 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Thu, 23 Jul 2015 13:06:56 +0200 Subject: [PATCH 4/5] Remove PlayerLogs, so buggy --- src/main/java/fr/xephi/authme/AuthMe.java | 7 +- .../fr/xephi/authme/datasource/FlatFile.java | 4 -- .../process/register/AsyncronousRegister.java | 6 +- .../ProcessSyncronousPasswordRegister.java | 2 - .../fr/xephi/authme/settings/PlayersLogs.java | 64 ------------------- 5 files changed, 5 insertions(+), 78 deletions(-) delete mode 100644 src/main/java/fr/xephi/authme/settings/PlayersLogs.java diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 56c813fdc..5886f52ba 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -71,7 +71,6 @@ import fr.xephi.authme.plugin.manager.EssSpawn; import fr.xephi.authme.process.Management; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.OtherAccounts; -import fr.xephi.authme.settings.PlayersLogs; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Spawn; import net.milkbowl.vault.permission.Permission; @@ -253,8 +252,6 @@ public class AuthMe extends JavaPlugin { ConsoleLogger.showError("WARNING!!! By disabling ForceSingleSession, your server protection is inadequate!"); } - PlayersLogs.getInstance(); - if (Settings.reloadSupport) try { int playersOnline = 0; @@ -269,7 +266,9 @@ public class AuthMe extends JavaPlugin { database.purgeLogged(); } catch (NullPointerException npe) { } - } else PlayersLogs.getInstance().loadPlayers(); + } else { + // TODO: load logged players ! + } } catch (Exception ex) { } diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index a6801dc74..5de3f8b85 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -14,7 +14,6 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.settings.PlayersLogs; import fr.xephi.authme.settings.Settings; public class FlatFile implements DataSource { @@ -662,17 +661,14 @@ public class FlatFile implements DataSource { @Override public void setLogged(String user) { - PlayersLogs.getInstance().savePlayerLogs(); } @Override public void setUnlogged(String user) { - PlayersLogs.getInstance().savePlayerLogs(); } @Override public void purgeLogged() { - PlayersLogs.getInstance().clear(); } @Override diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java index 6bb6f9b3f..53f3c3bef 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java @@ -12,7 +12,6 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.settings.Messages; -import fr.xephi.authme.settings.PlayersLogs; import fr.xephi.authme.settings.Settings; public class AsyncronousRegister { @@ -62,12 +61,12 @@ public class AsyncronousRegister { m.send(player, "password_error_nick"); allowRegister = false; } - + else if (password.length() < Settings.getPasswordMinLen || password.length() > Settings.passwordMaxLength) { m.send(player, "pass_len"); allowRegister = false; } - + else if (!Settings.unsafePasswords.isEmpty()) { if (Settings.unsafePasswords.contains(password.toLowerCase())) { m.send(player, "password_error_unsafe"); @@ -77,7 +76,6 @@ public class AsyncronousRegister { else if (database.isAuthAvailable(name)) { m.send(player, "user_regged"); - PlayersLogs.getInstance().savePlayerLogs(); allowRegister = false; } diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java index 7a7b41e1b..c8b64ed60 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java @@ -18,7 +18,6 @@ import fr.xephi.authme.events.LoginEvent; import fr.xephi.authme.events.RegisterTeleportEvent; import fr.xephi.authme.events.RestoreInventoryEvent; import fr.xephi.authme.settings.Messages; -import fr.xephi.authme.settings.PlayersLogs; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.task.TimeoutTask; @@ -73,7 +72,6 @@ public class ProcessSyncronousPasswordRegister implements Runnable { BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval)); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); try { - PlayersLogs.getInstance().save(); if (player.isInsideVehicle()) player.getVehicle().eject(); } catch (NullPointerException npe) { diff --git a/src/main/java/fr/xephi/authme/settings/PlayersLogs.java b/src/main/java/fr/xephi/authme/settings/PlayersLogs.java deleted file mode 100644 index 7e827fa54..000000000 --- a/src/main/java/fr/xephi/authme/settings/PlayersLogs.java +++ /dev/null @@ -1,64 +0,0 @@ -package fr.xephi.authme.settings; - -import java.io.File; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import fr.xephi.authme.AuthMe; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.datasource.DataSource; - -/** - * - * @author Xephi59 - */ -public class PlayersLogs extends CustomConfiguration { - - private static PlayersLogs pllog = null; - - public PlayersLogs() { - super(new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "players.yml")); - pllog = this; - load(); - save(); - } - - public void loadPlayers() { - DataSource database = AuthMe.getInstance().database; - List list = this.getStringList("players"); - if (list == null || list.isEmpty()) - return; - for (String s : list) { - PlayerAuth auth = database.getAuth(s); - if (auth == null) - continue; - auth.setLastLogin(new Date().getTime()); - database.updateSession(auth); - PlayerCache.getInstance().addPlayer(auth); - } - } - - public static PlayersLogs getInstance() { - if (pllog == null) { - pllog = new PlayersLogs(); - } - return pllog; - } - - public void savePlayerLogs() { - List players = new ArrayList(); - for (String s : PlayerCache.getInstance().getCache().keySet()) { - players.add(s); - } - this.set("players", players); - this.save(); - } - - public void clear() { - this.set("players", new ArrayList()); - this.save(); - } - -} From 4c2fad3643803fe2cdc74c9101f7e4644a5d686b Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Thu, 23 Jul 2015 16:23:25 +0200 Subject: [PATCH 5/5] Fix LowerCase issue --- src/main/java/fr/xephi/authme/AuthMe.java | 11 +- src/main/java/fr/xephi/authme/Utils.java | 6 +- .../xephi/authme/cache/auth/PlayerAuth.java | 49 +++++--- .../authme/converter/CrazyLoginConverter.java | 2 +- .../authme/converter/RakamakConverter.java | 2 +- .../authme/datasource/CacheDataSource.java | 5 + .../xephi/authme/datasource/DataSource.java | 2 + .../authme/datasource/DatabaseCalls.java | 21 ++++ .../fr/xephi/authme/datasource/FlatFile.java | 53 +++++---- .../fr/xephi/authme/datasource/MySQL.java | 112 +++++++++++++++--- .../fr/xephi/authme/datasource/SQLite.java | 70 +++++++++-- .../authme/listener/AuthMePlayerListener.java | 2 +- .../authme/process/join/AsyncronousJoin.java | 20 ++++ .../process/login/AsyncronousLogin.java | 10 +- .../authme/process/quit/AsyncronousQuit.java | 4 +- .../process/register/AsyncronousRegister.java | 6 +- .../fr/xephi/authme/settings/Settings.java | 9 +- src/main/resources/config.yml | 2 + 18 files changed, 297 insertions(+), 89 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 5886f52ba..ca7ae7404 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -12,6 +12,7 @@ import java.net.URL; import java.net.URLConnection; import java.util.Calendar; import java.util.Collection; +import java.util.Date; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; @@ -267,7 +268,13 @@ public class AuthMe extends JavaPlugin { } catch (NullPointerException npe) { } } else { - // TODO: load logged players ! + for (PlayerAuth auth : database.getLoggedPlayers()) { + if (auth == null) + continue; + auth.setLastLogin(new Date().getTime()); + database.updateSession(auth); + PlayerCache.getInstance().addPlayer(auth); + } } } catch (Exception ex) { } @@ -456,7 +463,7 @@ public class AuthMe extends JavaPlugin { try { String name = player.getName().toLowerCase(); if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead() && Settings.isSaveQuitLocationEnabled) { - final PlayerAuth auth = new PlayerAuth(player.getName().toLowerCase(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), player.getWorld().getName()); + final PlayerAuth auth = new PlayerAuth(player.getName().toLowerCase(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), player.getWorld().getName(), player.getName()); database.updateQuitLoc(auth); } if (LimboCache.getInstance().hasLimboPlayer(name)) { diff --git a/src/main/java/fr/xephi/authme/Utils.java b/src/main/java/fr/xephi/authme/Utils.java index 3844a44d4..15e01fe22 100644 --- a/src/main/java/fr/xephi/authme/Utils.java +++ b/src/main/java/fr/xephi/authme/Utils.java @@ -116,11 +116,9 @@ public class Utils { public boolean isUnrestricted(Player player) { if (!Settings.isAllowRestrictedIp) return false; - if (Settings.getUnrestrictedName.isEmpty() || Settings.getUnrestrictedName == null) + if (Settings.getUnrestrictedName == null || Settings.getUnrestrictedName.isEmpty()) return false; - if (Settings.getUnrestrictedName.contains(player.getName())) - return true; - return false; + return (Settings.getUnrestrictedName.contains(player.getName())); } public static Utils getInstance() { 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 62a5d4e3f..de9224e41 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java @@ -17,30 +17,33 @@ public class PlayerAuth { private String vBhash = null; private int groupId = -1; private String email = "your@email.com"; + private String realName; public PlayerAuth(String nickname, String hash, String ip, long lastLogin, - String email) { + String email, String realName) { this.nickname = nickname; this.hash = hash; this.ip = ip; this.lastLogin = lastLogin; this.email = email; - + this.realName = realName; } public PlayerAuth(String nickname, double x, double y, double z, - String world) { + String world, String realName) { this.nickname = nickname; this.x = x; this.y = y; this.z = z; this.world = world; + this.realName = realName; this.lastLogin = System.currentTimeMillis(); } public PlayerAuth(String nickname, String hash, String ip, long lastLogin, - double x, double y, double z, String world, String email) { + double x, double y, double z, String world, String email, + String realName) { this.nickname = nickname; this.hash = hash; this.ip = ip; @@ -50,12 +53,12 @@ public class PlayerAuth { this.z = z; this.world = world; this.email = email; - + this.realName = realName; } public PlayerAuth(String nickname, String hash, String salt, int groupId, String ip, long lastLogin, double x, double y, double z, - String world, String email) { + String world, String email, String realName) { this.nickname = nickname; this.hash = hash; this.ip = ip; @@ -67,33 +70,33 @@ public class PlayerAuth { this.salt = salt; this.groupId = groupId; this.email = email; - + this.realName = realName; } public PlayerAuth(String nickname, String hash, String salt, int groupId, - String ip, long lastLogin) { + String ip, long lastLogin, String realName) { this.nickname = nickname; this.hash = hash; this.ip = ip; this.lastLogin = lastLogin; this.salt = salt; this.groupId = groupId; - + this.realName = realName; } public PlayerAuth(String nickname, String hash, String salt, String ip, - long lastLogin) { + long lastLogin, String realName) { this.nickname = nickname; this.hash = hash; this.ip = ip; this.lastLogin = lastLogin; this.salt = salt; - + this.realName = realName; } public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, double x, double y, double z, String world, - String email) { + String email, String realName) { this.nickname = nickname; this.hash = hash; this.ip = ip; @@ -104,21 +107,24 @@ public class PlayerAuth { this.world = world; this.salt = salt; this.email = email; - + this.realName = realName; } - public PlayerAuth(String nickname, String ip, long lastLogin) { + public PlayerAuth(String nickname, String ip, long lastLogin, + String realName) { this.nickname = nickname; this.ip = ip; this.lastLogin = lastLogin; - + this.realName = realName; } - public PlayerAuth(String nickname, String hash, String ip, long lastLogin) { + public PlayerAuth(String nickname, String hash, String ip, long lastLogin, + String realName) { this.nickname = nickname; this.ip = ip; this.lastLogin = lastLogin; this.hash = hash; + this.realName = realName; } public String getIp() { @@ -234,7 +240,7 @@ public class PlayerAuth { @Override public String toString() { - String s = "Player : " + nickname + " ! IP : " + ip + " ! LastLogin : " + lastLogin + " ! LastPosition : " + x + "," + y + "," + z + "," + world + " ! Email : " + email + " ! Hash : " + hash + " ! Salt : " + salt; + String s = "Player : " + nickname + " | " + realName + " ! IP : " + ip + " ! LastLogin : " + lastLogin + " ! LastPosition : " + x + "," + y + "," + z + "," + world + " ! Email : " + email + " ! Hash : " + hash + " ! Salt : " + salt; return s; } @@ -254,6 +260,15 @@ public class PlayerAuth { this.setQuitLocZ(auth.getQuitLocZ()); this.setSalt(auth.getSalt()); this.setWorld(auth.getWorld()); + this.setRealName(auth.getRealName()); + } + + public String getRealName() { + return realName; + } + + public void setRealName(String realName) { + this.realName = realName; } } diff --git a/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java b/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java index d4577bcd7..0ffae7db6 100644 --- a/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java +++ b/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java @@ -61,7 +61,7 @@ public class CrazyLoginConverter implements Converter { String psw = args[1]; try { if (player != null && psw != null) { - PlayerAuth auth = new PlayerAuth(player, psw, "127.0.0.1", System.currentTimeMillis()); + PlayerAuth auth = new PlayerAuth(player, psw, "127.0.0.1", System.currentTimeMillis(), player); database.saveAuth(auth); } } catch (Exception e) { diff --git a/src/main/java/fr/xephi/authme/converter/RakamakConverter.java b/src/main/java/fr/xephi/authme/converter/RakamakConverter.java index 712207673..333b6bdef 100644 --- a/src/main/java/fr/xephi/authme/converter/RakamakConverter.java +++ b/src/main/java/fr/xephi/authme/converter/RakamakConverter.java @@ -93,7 +93,7 @@ public class RakamakConverter implements Converter { } else { ip = "127.0.0.1"; } - PlayerAuth auth = new PlayerAuth(player, psw, ip, System.currentTimeMillis()); + PlayerAuth auth = new PlayerAuth(player, psw, ip, System.currentTimeMillis(), player); if (PasswordSecurity.userSalt.containsKey(player)) auth.setSalt(PasswordSecurity.userSalt.get(player)); database.saveAuth(auth); diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index 585a60b39..fb96bc7cb 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -240,4 +240,9 @@ public class CacheDataSource implements DataSource { public List getAllAuths() { return source.getAllAuths(); } + + @Override + public List getLoggedPlayers() { + return source.getLoggedPlayers(); + } } diff --git a/src/main/java/fr/xephi/authme/datasource/DataSource.java b/src/main/java/fr/xephi/authme/datasource/DataSource.java index 4c9400512..ef445dc4c 100644 --- a/src/main/java/fr/xephi/authme/datasource/DataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSource.java @@ -65,4 +65,6 @@ public interface DataSource { List getAllAuths(); + List getLoggedPlayers(); + } diff --git a/src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java b/src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java index a783c1f6c..1b3e0993e 100644 --- a/src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java +++ b/src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java @@ -534,4 +534,25 @@ public class DatabaseCalls implements DataSource { return result; } + @Override + public List getLoggedPlayers() { + ExecutorService executor = Executors.newSingleThreadExecutor(); + List result; + try { + result = executor.submit(new Callable>() { + + public List call() throws Exception { + return database.getLoggedPlayers(); + } + }).get(); + } catch (InterruptedException e1) { + return (new ArrayList()); + } catch (ExecutionException e1) { + return (new ArrayList()); + } finally { + executor.shutdown(); + } + return result; + } + } diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index 5de3f8b85..198b1cd54 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -114,23 +114,23 @@ public class FlatFile implements DataSource { if (args[0].equals(auth.getNickname())) { switch (args.length) { case 4: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), 0, 0, 0, "world", "your@email.com"); + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), 0, 0, 0, "world", "your@email.com", args[0]); break; } case 7: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com"); + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com", args[0]); break; } case 8: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com"); + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]); break; } case 9: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8]); + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]); break; } default: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], 0, 0, 0, 0, "world", "your@email.com"); + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], 0, 0, 0, 0, "world", "your@email.com", args[0]); break; } } @@ -173,23 +173,23 @@ public class FlatFile implements DataSource { if (args[0].equalsIgnoreCase(auth.getNickname())) { switch (args.length) { case 4: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com"); + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com", args[0]); break; } case 7: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com"); + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com", args[0]); break; } case 8: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com"); + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]); break; } case 9: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8]); + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]); break; } default: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com"); + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com", args[0]); break; } } @@ -230,7 +230,7 @@ public class FlatFile implements DataSource { while ((line = br.readLine()) != null) { String[] args = line.split(":"); if (args[0].equalsIgnoreCase(auth.getNickname())) { - newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), auth.getEmail()); + newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), auth.getEmail(), args[0]); break; } } @@ -432,17 +432,17 @@ public class FlatFile implements DataSource { if (args[0].equalsIgnoreCase(user)) { switch (args.length) { case 2: - return new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com"); + return new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com", args[0]); case 3: - return new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com"); + return new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com", args[0]); case 4: - return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com"); + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0]); case 7: - return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com"); + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com", args[0]); case 8: - return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com"); + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]); case 9: - return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8]); + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]); } } } @@ -484,7 +484,7 @@ public class FlatFile implements DataSource { while ((line = br.readLine()) != null) { String[] args = line.split(":"); if (args[0].equals(auth.getNickname())) { - newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], auth.getEmail()); + newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], auth.getEmail(), args[0]); break; } } @@ -713,17 +713,17 @@ public class FlatFile implements DataSource { String[] args = line.split(":"); switch (args.length) { case 2: - auths.add(new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com")); + auths.add(new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com", args[0])); case 3: - auths.add(new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com")); + auths.add(new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com", args[0])); case 4: - auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com")); + auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0])); case 7: - auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com")); + auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com", args[0])); case 8: - auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com")); + auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0])); case 9: - auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8])); + auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0])); } } } catch (FileNotFoundException ex) { @@ -742,4 +742,9 @@ public class FlatFile implements DataSource { } return auths; } + + @Override + public List getLoggedPlayers() { + return new ArrayList(); + } } diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 36bd86c25..8a93aa89c 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -41,6 +41,7 @@ public class MySQL implements DataSource { private String columnLogged; private List columnOthers; private MiniConnectionPoolManager conPool; + private String columnRealName; public MySQL() { this.host = Settings.getMySQLHost; @@ -63,6 +64,7 @@ public class MySQL implements DataSource { this.columnOthers = Settings.getMySQLOtherUsernameColumn; this.columnID = Settings.getMySQLColumnId; this.columnLogged = Settings.getMySQLColumnLogged; + this.columnRealName = Settings.getMySQLColumnRealName; try { this.connect(); this.setup(); @@ -157,6 +159,11 @@ public class MySQL implements DataSource { 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) DEFAULT 'Player' AFTER " + columnLogged + ";"); + } } finally { close(rs); close(st); @@ -204,14 +211,14 @@ public class MySQL implements DataSource { 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)); + 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)); - 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)); + 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)); + 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) { @@ -249,27 +256,29 @@ public class MySQL implements DataSource { try { con = makeSureConnectionIsReady(); if ((columnSalt == null || columnSalt.isEmpty()) || (auth.getSalt() == null || auth.getSalt().isEmpty())) { - pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + ") VALUES (?,?,?,?);"); + 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 + ") VALUES (?,?,?,?,?);"); + 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.getNickname()); + pst.setString(1, auth.getRealName()); pst.setString(2, auth.getNickname()); pst.executeUpdate(); pst.close(); @@ -338,72 +347,84 @@ public class MySQL implements DataSource { 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(); } } if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { @@ -424,6 +445,8 @@ public class MySQL implements DataSource { pst.setBlob(3, blob); pst.executeUpdate(); } + if (rs != null && !rs.isClosed()) + rs.close(); } } catch (SQLException ex) { ConsoleLogger.showError(ex.getMessage()); @@ -470,6 +493,8 @@ public class MySQL implements DataSource { pst.setInt(2, id); pst.executeUpdate(); } + if (rs != null && !rs.isClosed()) + rs.close(); } } catch (SQLException ex) { ConsoleLogger.showError(ex.getMessage()); @@ -1079,26 +1104,28 @@ public class MySQL implements DataSource { PlayerAuth pAuth = null; 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)); + 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)); - 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)); + 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)); + 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) { - rs.close(); + ResultSet rsid = null; 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"); + rsid = pst.executeQuery(); + if (rsid.next()) { + Blob blob = rsid.getBlob("data"); byte[] bytes = blob.getBytes(1, (int) blob.length()); pAuth.setHash(new String(bytes)); } + if (rsid != null) + rsid.close(); } if (pAuth != null) auths.add(pAuth); @@ -1112,6 +1139,61 @@ public class MySQL implements DataSource { } finally { close(pst); close(con); + close(rs); + } + return auths; + } + + @Override + public List getLoggedPlayers() { + List auths = new ArrayList(); + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + try { + con = makeSureConnectionIsReady(); + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;"); + rs = pst.executeQuery(); + while (rs.next()) { + PlayerAuth pAuth = null; + 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 = null; + 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)); + } + if (rsid != null) + rsid.close(); + } + if (pAuth != null) + auths.add(pAuth); + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return auths; + } catch (TimeoutException 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/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 5c75d2694..7bac1491d 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -33,6 +33,7 @@ public class SQLite implements DataSource { private String columnID; private Connection con; private String columnLogged; + private String columnRealName; public SQLite() { this.database = Settings.getMySQLDatabase; @@ -50,6 +51,7 @@ public class SQLite implements DataSource { this.columnEmail = Settings.getMySQLColumnEmail; this.columnID = Settings.getMySQLColumnId; this.columnLogged = Settings.getMySQLColumnLogged; + this.columnRealName = Settings.getMySQLColumnRealName; try { this.connect(); @@ -101,7 +103,7 @@ public class SQLite implements DataSource { rs.close(); rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin); if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " BIGINT;"); + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " BIGINT DEFAULT '0';"); } rs.close(); rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); @@ -118,12 +120,17 @@ public class SQLite implements DataSource { 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';"); + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';"); } rs.close(); rs = con.getMetaData().getColumns(null, null, tableName, columnLogged); if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLogged + " BIGINT DEFAULT '0';"); + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLogged + " BIGINT DEFAULT '0';"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnRealName); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnRealName + " VARCHAR(255) DEFAULT 'Player';"); } } finally { close(rs); @@ -160,12 +167,12 @@ public class SQLite implements DataSource { rs = pst.executeQuery(); if (rs.next()) { if (rs.getString(columnIp).isEmpty()) { - return 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)); + return 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()) { - return 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)); + return 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 { - return 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)); + return 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)); } } } else { @@ -185,19 +192,21 @@ public class SQLite implements DataSource { PreparedStatement pst = null; try { if (columnSalt.isEmpty() && auth.getSalt().isEmpty()) { - pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + ") VALUES (?,?,?,?);"); + 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(); } else { - pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnSalt + ") VALUES (?,?,?,?,?);"); + 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(); } } catch (SQLException ex) { @@ -230,10 +239,11 @@ public class SQLite implements DataSource { public boolean updateSession(PlayerAuth auth) { PreparedStatement pst = null; try { - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=? WHERE " + columnName + "=?;"); + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE " + columnName + "=?;"); pst.setString(1, auth.getIp()); pst.setLong(2, auth.getLastLogin()); - pst.setString(3, auth.getNickname()); + pst.setString(3, auth.getRealName()); + pst.setString(4, auth.getNickname()); pst.executeUpdate(); } catch (SQLException ex) { ConsoleLogger.showError(ex.getMessage()); @@ -650,12 +660,46 @@ public class SQLite implements DataSource { while (rs.next()) { PlayerAuth pAuth = null; if (rs.getString(columnIp).isEmpty()) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.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()) { - 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)); + 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(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); + 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 (pAuth != null) + auths.add(pAuth); + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return auths; + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return auths; + } finally { + close(pst); + } + return auths; + } + + @Override + public List getLoggedPlayers() { + List auths = new ArrayList(); + PreparedStatement pst = null; + ResultSet rs = null; + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;"); + rs = pst.executeQuery(); + while (rs.next()) { + PlayerAuth pAuth = null; + if (rs.getString(columnIp).isEmpty()) { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.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()) { + 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(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } } if (pAuth != null) diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 6b42f2e29..d9a53966c 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -827,7 +827,7 @@ public class AuthMePlayerListener implements Listener { Location spawn = plugin.getSpawnLocation(player); if (Settings.isSaveQuitLocationEnabled && plugin.database.isAuthAvailable(name)) { - final PlayerAuth auth = new PlayerAuth(name, spawn.getX(), spawn.getY(), spawn.getZ(), spawn.getWorld().getName()); + final PlayerAuth auth = new PlayerAuth(name, spawn.getX(), spawn.getY(), spawn.getZ(), spawn.getWorld().getName(), player.getName()); try { plugin.database.updateQuitLoc(auth); } catch (NullPointerException npe) { 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 6243a6272..5bd857efa 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java @@ -100,6 +100,26 @@ public class AsyncronousJoin { } final Location spawnLoc = plugin.getSpawnLocation(player); if (database.isAuthAvailable(name)) { + PlayerAuth auth = database.getAuth(name); + if (!auth.getRealName().equals("Player") && !auth.getRealName().equals(player.getName())) { + final GameMode gM = AuthMePlayerListener.gameMode.get(name); + sched.scheduleSyncDelayedTask(plugin, new Runnable() { + + @Override + public void run() { + if (gM != null) { + AuthMePlayerListener.causeByAuthMe.put(name, true); + player.setGameMode(gM); + AuthMePlayerListener.causeByAuthMe.put(name, false); + } + player.kickPlayer("You are not the Owner of this account, please try another name!"); + if (Settings.banUnsafeIp) + plugin.getServer().banIP(ip); + } + + }, 1); + return; + } if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) { sched.scheduleSyncDelayedTask(plugin, new Runnable() { diff --git a/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java index 15fafaa68..e7c49af87 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java @@ -50,11 +50,11 @@ public class AsyncronousLogin { protected boolean needsCaptcha() { if (Settings.useCaptcha) { if (!plugin.captcha.containsKey(name)) { - plugin.captcha.put(name, 1); + plugin.captcha.putIfAbsent(name, 1); } else { int i = plugin.captcha.get(name) + 1; plugin.captcha.remove(name); - plugin.captcha.put(name, i); + plugin.captcha.putIfAbsent(name, i); } if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) { plugin.cap.put(name, rdm.nextString()); @@ -133,7 +133,7 @@ public class AsyncronousLogin { return; } if (passwordVerified && player.isOnline()) { - PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email); + PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email, realName); database.updateSession(auth); if (Settings.useCaptcha) { @@ -157,7 +157,7 @@ public class AsyncronousLogin { } if (!Settings.noConsoleSpam) - ConsoleLogger.info(player.getName() + " logged in!"); + ConsoleLogger.info(realName + " logged in!"); // makes player isLoggedin via API PlayerCache.getInstance().addPlayer(auth); @@ -178,7 +178,7 @@ public class AsyncronousLogin { Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin); } else if (player.isOnline()) { if (!Settings.noConsoleSpam) - ConsoleLogger.info(player.getName() + " used the wrong password"); + ConsoleLogger.info(realName + " used the wrong password"); if (Settings.isKickOnWrongPasswordEnabled) { Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { diff --git a/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java b/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java index 0bd001185..4c833d66b 100644 --- a/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java +++ b/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java @@ -51,13 +51,13 @@ public class AsyncronousQuit { if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead()) { if (Settings.isSaveQuitLocationEnabled && database.isAuthAvailable(name)) { - final PlayerAuth auth = new PlayerAuth(name, loc.getX(), loc.getY(), loc.getZ(), loc.getWorld().getName()); + final PlayerAuth auth = new PlayerAuth(name, loc.getX(), loc.getY(), loc.getZ(), loc.getWorld().getName(), player.getName()); try { database.updateQuitLoc(auth); } catch (NullPointerException npe) { } } - PlayerAuth auth = new PlayerAuth(name, ip, System.currentTimeMillis()); + PlayerAuth auth = new PlayerAuth(name, ip, System.currentTimeMillis(), player.getName()); database.updateSession(auth); } diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java index 53f3c3bef..72f14459c 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java @@ -115,7 +115,7 @@ public class AsyncronousRegister { PlayerAuth auth = null; try { final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); - auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email); + auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email, player.getName()); } catch (NoSuchAlgorithmException e) { ConsoleLogger.showError(e.getMessage()); m.send(player, "error"); @@ -144,9 +144,9 @@ public class AsyncronousRegister { return; } if (Settings.getMySQLColumnSalt.isEmpty() && !PasswordSecurity.userSalt.containsKey(name)) { - auth = new PlayerAuth(name, hash, getIp(), new Date().getTime(), "your@email.com"); + auth = new PlayerAuth(name, hash, getIp(), new Date().getTime(), "your@email.com", player.getName()); } else { - auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), getIp(), new Date().getTime()); + auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), getIp(), new Date().getTime(), player.getName()); } if (!database.saveAuth(auth)) { m.send(player, "error"); diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index fe1f34eae..ecb06d8de 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -82,7 +82,8 @@ public final class Settings extends YamlConfiguration { getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName, getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld, getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged, - spawnPriority, crazyloginFileName, getPassRegex; + spawnPriority, crazyloginFileName, getPassRegex, + getMySQLColumnRealName; public static int getWarnMessageInterval, getSessionTimeout, getRegistrationTimeout, getMaxNickLength, getMinNickLength, @@ -161,6 +162,7 @@ public final class Settings extends YamlConfiguration { getMySQLlastlocY = configFile.getString("DataSource.mySQLlastlocY", "y"); getMySQLlastlocZ = configFile.getString("DataSource.mySQLlastlocZ", "z"); getMySQLlastlocWorld = configFile.getString("DataSource.mySQLlastlocWorld", "world"); + getMySQLColumnRealName = configFile.getString("DataSource.mySQLRealName", "realname"); getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1); unRegisteredGroup = configFile.getString("GroupOptions.UnregisteredPlayerGroup", ""); getUnrestrictedName = configFile.getStringList("settings.unrestrictions.UnrestrictedName"); @@ -328,6 +330,7 @@ public final class Settings extends YamlConfiguration { getMySQLlastlocY = configFile.getString("DataSource.mySQLlastlocY", "y"); getMySQLlastlocZ = configFile.getString("DataSource.mySQLlastlocZ", "z"); getMySQLlastlocWorld = configFile.getString("DataSource.mySQLlastlocWorld", "world"); + getMySQLColumnRealName = configFile.getString("DataSource.mySQLRealName", "realname"); getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1); unRegisteredGroup = configFile.getString("GroupOptions.UnregisteredPlayerGroup", ""); getUnrestrictedName = configFile.getStringList("settings.unrestrictions.UnrestrictedName"); @@ -592,6 +595,10 @@ public final class Settings extends YamlConfiguration { set("Email.generateImage", true); changes = true; } + if (!contains("DataSource.mySQLRealName")) { + set("DataSource.mySQLRealName", "realname"); + changes = true; + } if (changes) { plugin.getLogger().warning("Merge new Config Options - I'm not an error, please don't report me"); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2399cf1e9..91e2c2f9f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -37,6 +37,8 @@ DataSource: mySQLlastlocZ: z # Column for SaveQuitLocation - World name mySQLlastlocWorld: world + # Column for RealName + mySQLRealName: realname GroupOptions: # if you want to set up a particulary Permission Group for # users that arent registered yet. Pay attention this option