diff --git a/CHANGELOG.md b/CHANGELOG.md index db7ee059..228df86b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ######1.5.2 * Fixed BungeeCord force logins if there is a lobby server +* Removed cache expire in BungeeCord ######1.5.1 diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeLoginSession.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeLoginSession.java new file mode 100644 index 00000000..b830b377 --- /dev/null +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeLoginSession.java @@ -0,0 +1,25 @@ +package com.github.games647.fastlogin.bungee; + +import com.github.games647.fastlogin.core.LoginSession; +import com.github.games647.fastlogin.core.PlayerProfile; + +public class BungeeLoginSession extends LoginSession { + + private boolean alreadySaved; + + public BungeeLoginSession(String username, boolean registered, PlayerProfile profile) { + super(username, registered, profile); + } + + public void setRegistered(boolean registered) { + this.registered = registered; + } + + public boolean isAlreadySaved() { + return alreadySaved; + } + + public void setAlreadySaved(boolean alreadySaved) { + this.alreadySaved = alreadySaved; + } +} diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java index 70b6c873..0a09f6cb 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java @@ -5,14 +5,12 @@ import com.github.games647.fastlogin.bungee.hooks.BungeeAuthPlugin; import com.github.games647.fastlogin.bungee.listener.PlayerConnectionListener; import com.github.games647.fastlogin.bungee.listener.PluginMessageListener; import com.github.games647.fastlogin.core.FastLoginCore; -import com.github.games647.fastlogin.core.LoginSession; -import com.google.common.cache.CacheBuilder; +import com.google.common.collect.Maps; import java.io.File; import java.io.IOException; import java.util.Random; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.TimeUnit; import java.util.logging.Level; import net.md_5.bungee.api.connection.PendingConnection; @@ -35,10 +33,7 @@ public class FastLoginBungee extends Plugin { private final Random random = new Random(); - private final ConcurrentMap session = CacheBuilder - .newBuilder() - .expireAfterWrite(5, TimeUnit.MINUTES) - .build().asMap(); + private final ConcurrentMap session = Maps.newConcurrentMap(); @Override public void onEnable() { @@ -102,7 +97,7 @@ public class FastLoginBungee extends Plugin { return configuration; } - public ConcurrentMap getSession() { + public ConcurrentMap getSession() { return session; } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PluginMessageListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PluginMessageListener.java index 3c24111e..15c87d75 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PluginMessageListener.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PluginMessageListener.java @@ -1,5 +1,6 @@ package com.github.games647.fastlogin.bungee.listener; +import com.github.games647.fastlogin.bungee.BungeeLoginSession; import com.github.games647.fastlogin.bungee.FastLoginBungee; import com.github.games647.fastlogin.bungee.tasks.AsyncToggleMessage; import com.github.games647.fastlogin.core.PlayerProfile; @@ -59,9 +60,15 @@ public class PluginMessageListener implements Listener { //bukkit module successfully received and force logged in the user //update only on success to prevent corrupt data PlayerProfile playerProfile = plugin.getCore().getStorage().loadProfile(fromPlayer.getName()); - playerProfile.setPremium(true); - //we override this in the loginevent - plugin.getCore().getStorage().save(playerProfile); + BungeeLoginSession loginSession = plugin.getSession().get(fromPlayer.getPendingConnection()); + loginSession.setRegistered(true); + + if (!loginSession.isAlreadySaved()) { + playerProfile.setPremium(true); + //we override this in the loginevent + plugin.getCore().getStorage().save(playerProfile); + loginSession.setAlreadySaved(true); + } } } } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncPremiumCheck.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncPremiumCheck.java index 66036563..d1961c22 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncPremiumCheck.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncPremiumCheck.java @@ -1,8 +1,8 @@ package com.github.games647.fastlogin.bungee.tasks; +import com.github.games647.fastlogin.bungee.BungeeLoginSession; import com.github.games647.fastlogin.bungee.FastLoginBungee; import com.github.games647.fastlogin.bungee.hooks.BungeeAuthPlugin; -import com.github.games647.fastlogin.core.LoginSession; import com.github.games647.fastlogin.core.PlayerProfile; import java.util.UUID; @@ -43,12 +43,12 @@ public class AsyncPremiumCheck implements Runnable { || checkNameChange(premiumUUID, connection, username) || checkPremiumName(username, connection, profile)) { //nothing detected the player as premium -> start a cracked session - plugin.getSession().put(connection, new LoginSession(username, false, profile)); + plugin.getSession().put(connection, new BungeeLoginSession(username, false, profile)); } } else if (profile.isPremium()) { requestPremiumLogin(connection, profile, username, true); } else { - plugin.getSession().put(connection, new LoginSession(username, false, profile)); + plugin.getSession().put(connection, new BungeeLoginSession(username, false, profile)); } } catch (Exception ex) { plugin.getLogger().log(Level.SEVERE, "Failed to check premium state", ex); @@ -87,6 +87,6 @@ public class AsyncPremiumCheck implements Runnable { private void requestPremiumLogin(PendingConnection con, PlayerProfile profile, String username, boolean register) { con.setOnlineMode(true); - plugin.getSession().put(con, new LoginSession(username, register, profile)); + plugin.getSession().put(con, new BungeeLoginSession(username, register, profile)); } } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/ForceLoginTask.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/ForceLoginTask.java index e92be210..9f02f9ee 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/ForceLoginTask.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/ForceLoginTask.java @@ -1,8 +1,8 @@ package com.github.games647.fastlogin.bungee.tasks; +import com.github.games647.fastlogin.bungee.BungeeLoginSession; import com.github.games647.fastlogin.bungee.FastLoginBungee; import com.github.games647.fastlogin.bungee.hooks.BungeeAuthPlugin; -import com.github.games647.fastlogin.core.LoginSession; import com.github.games647.fastlogin.core.PlayerProfile; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; @@ -28,30 +28,38 @@ public class ForceLoginTask implements Runnable { @Override public void run() { PendingConnection pendingConnection = player.getPendingConnection(); - LoginSession session = plugin.getSession().get(pendingConnection); + BungeeLoginSession session = plugin.getSession().get(pendingConnection); PlayerProfile playerProfile = session.getProfile(); + if (player.isConnected()) { + return; + } + //force login only on success if (pendingConnection.isOnlineMode()) { boolean autoRegister = session.needsRegistration(); BungeeAuthPlugin authPlugin = plugin.getBungeeAuthPlugin(); if (authPlugin == null) { + //save will happen on success message from bukkit sendBukkitLoginNotification(autoRegister); - } else if (player.isConnected()) { - if (session.needsRegistration()) { - String password = plugin.generateStringPassword(); - if (authPlugin.forceRegister(player, password)) { - sendBukkitLoginNotification(autoRegister); - } - } else if (authPlugin.forceLogin(player)) { + } else if (session.needsRegistration()) { + String password = plugin.generateStringPassword(); + if (authPlugin.forceRegister(player, password)) { + //save will happen on success message from bukkit sendBukkitLoginNotification(autoRegister); } + } else if (authPlugin.forceLogin(player)) { + //save will happen on success message from bukkit + sendBukkitLoginNotification(autoRegister); } } else { //cracked player - playerProfile.setPremium(false); - plugin.getCore().getStorage().save(playerProfile); + if (!session.isAlreadySaved()) { + playerProfile.setPremium(false); + plugin.getCore().getStorage().save(playerProfile); + session.setAlreadySaved(true); + } } } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/LoginSession.java b/core/src/main/java/com/github/games647/fastlogin/core/LoginSession.java index 25ea447c..47b07518 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/LoginSession.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/LoginSession.java @@ -3,8 +3,8 @@ package com.github.games647.fastlogin.core; public class LoginSession { private final String username; - private final boolean registered; private final PlayerProfile profile; + protected boolean registered; public LoginSession(String username, boolean registered, PlayerProfile profile) { this.username = username;