diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/CrackedCommand.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/CrackedCommand.java index 3fd15979..bc8e08c1 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/CrackedCommand.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/CrackedCommand.java @@ -71,7 +71,7 @@ public class CrackedCommand implements CommandExecutor { } //existing player is already cracked - if (profile.getUserId() != -1 && !profile.isPremium()) { + if (profile.isSaved() && !profile.isPremium()) { plugin.getCore().sendLocaleMessage("not-premium-other", sender); } else { plugin.getCore().sendLocaleMessage("remove-premium", sender); diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncToggleMessage.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncToggleMessage.java index 55b3435b..d7a6b37b 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncToggleMessage.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncToggleMessage.java @@ -38,7 +38,7 @@ public class AsyncToggleMessage implements Runnable { private void turnOffPremium() { PlayerProfile playerProfile = core.getStorage().loadProfile(targetPlayer); //existing player is already cracked - if (playerProfile.getUserId() != -1 && !playerProfile.isPremium()) { + if (playerProfile.isSaved() && !playerProfile.isPremium()) { sendMessage("not-premium"); return; } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java b/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java index ff16f999..191ec464 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java @@ -143,8 +143,23 @@ public class AuthStorage { public void save(PlayerProfile playerProfile) { try (Connection con = dataSource.getConnection()) { UUID uuid = playerProfile.getUuid(); - - if (playerProfile.getUserId() == -1) { + + if (playerProfile.isSaved()) { + try (PreparedStatement saveStmt = con.prepareStatement(UPDATE_PROFILE)) { + if (uuid == null) { + saveStmt.setString(1, null); + } else { + saveStmt.setString(1, UUIDTypeAdapter.toMojangId(uuid)); + } + + saveStmt.setString(2, playerProfile.getPlayerName()); + saveStmt.setBoolean(3, playerProfile.isPremium()); + saveStmt.setString(4, playerProfile.getLastIp()); + + saveStmt.setLong(5, playerProfile.getRowId()); + saveStmt.execute(); + } + } else { try (PreparedStatement saveStmt = con.prepareStatement(INSERT_PROFILE, RETURN_GENERATED_KEYS)) { if (uuid == null) { saveStmt.setString(1, null); @@ -160,25 +175,10 @@ public class AuthStorage { try (ResultSet generatedKeys = saveStmt.getGeneratedKeys()) { if (generatedKeys != null && generatedKeys.next()) { - playerProfile.setUserId(generatedKeys.getInt(1)); + playerProfile.setRowId(generatedKeys.getInt(1)); } } } - } else { - try (PreparedStatement saveStmt = con.prepareStatement(UPDATE_PROFILE)) { - if (uuid == null) { - saveStmt.setString(1, null); - } else { - saveStmt.setString(1, UUIDTypeAdapter.toMojangId(uuid)); - } - - saveStmt.setString(2, playerProfile.getPlayerName()); - saveStmt.setBoolean(3, playerProfile.isPremium()); - saveStmt.setString(4, playerProfile.getLastIp()); - - saveStmt.setLong(5, playerProfile.getUserId()); - saveStmt.execute(); - } } } catch (SQLException ex) { diff --git a/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java b/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java index 1da8cd5f..0f1fc0cf 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java @@ -7,15 +7,15 @@ public class PlayerProfile { private String playerName; - private long userId; + private long rowId; private UUID uuid; private boolean premium; private String lastIp; private Instant lastLogin; - public PlayerProfile(long userId, UUID uuid, String playerName, boolean premium, String lastIp, Instant lastLogin) { - this.userId = userId; + public PlayerProfile(long rowId, UUID uuid, String playerName, boolean premium, String lastIp, Instant lastLogin) { + this.rowId = rowId; this.uuid = uuid; this.playerName = playerName; this.premium = premium; @@ -27,6 +27,10 @@ public class PlayerProfile { this(-1, uuid, playerName, premium, lastIp, Instant.now()); } + public synchronized boolean isSaved() { + return rowId >= 0; + } + public synchronized String getPlayerName() { return playerName; } @@ -35,12 +39,12 @@ public class PlayerProfile { this.playerName = playerName; } - public synchronized long getUserId() { - return userId; + public synchronized long getRowId() { + return rowId; } - public synchronized void setUserId(long generatedId) { - this.userId = generatedId; + public synchronized void setRowId(long generatedId) { + this.rowId = generatedId; } //todo: this should be optional @@ -80,7 +84,7 @@ public class PlayerProfile { public String toString() { return this.getClass().getSimpleName() + '{' + "playerName='" + playerName + '\'' + - ", userId=" + userId + + ", rowId=" + rowId + ", uuid=" + uuid + ", premium=" + premium + ", lastIp='" + lastIp + '\'' + diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java index b2f854a5..9338eabc 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java @@ -29,7 +29,13 @@ public abstract class JoinManagement

{ String ip = source.getAddress().getAddress().getHostAddress(); profile.setLastIp(ip); try { - if (profile.getUserId() == -1) { + if (profile.isSaved()) { + if (profile.isPremium()) { + requestPremiumLogin(source, profile, username, true); + } else { + startCrackedSession(source, profile, username); + } + } else { if (core.getPendingLogin().remove(ip + username) != null && config.get("secondAttemptCracked", false)) { core.getPlugin().getLog().info("Second attempt login -> cracked {}", username); @@ -54,10 +60,6 @@ public abstract class JoinManagement

{ startCrackedSession(source, profile, username); } - } else if (profile.isPremium()) { - requestPremiumLogin(source, profile, username, true); - } else { - startCrackedSession(source, profile, username); } } catch (Exception ex) { core.getPlugin().getLog().error("Failed to check premium state", ex);