From cedafe52a829a051e5366617117b9435487bf41e Mon Sep 17 00:00:00 2001 From: Xephi Date: Wed, 13 Mar 2013 23:11:00 +0100 Subject: [PATCH] fix SessionExpireOnIpChange Note for myself : Refresh Code T.T --- pom.xml | 2 +- .../authme/listener/AuthMePlayerListener.java | 42 +++++++------------ src/main/resources/plugin.yml | 2 +- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/pom.xml b/pom.xml index b90eea6fe..04b9995bb 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ - 2.7.11b2 + 2.7.11b3 org.bukkit diff --git a/src/main/java/uk/org/whoami/authme/listener/AuthMePlayerListener.java b/src/main/java/uk/org/whoami/authme/listener/AuthMePlayerListener.java index c491ba204..66a5e8a67 100644 --- a/src/main/java/uk/org/whoami/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/uk/org/whoami/authme/listener/AuthMePlayerListener.java @@ -29,7 +29,6 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.PlayerBedEnterEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerDropItemEvent; @@ -78,7 +77,6 @@ public class AuthMePlayerListener implements Listener { public static int gm = 0; public static HashMap gameMode = new HashMap(); - public HashMap sessions = new HashMap(); private Utils utils = Utils.getInstance(); private Messages m = Messages.getInstance(); public AuthMe plugin; @@ -566,22 +564,6 @@ public class AuthMePlayerListener implements Listener { } - @EventHandler(priority = EventPriority.LOWEST) - public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event) { - if (event == null || event.getName() == null || event.getName().isEmpty()) return; - - if (!Settings.isSessionsEnabled && !Settings.sessionExpireOnIpChange) return; - - PlayerAuth auth = data.getAuth(event.getName().toLowerCase()); - if (event.getAddress().getHostAddress() == auth.getIp()) { - return; - } else { - if (!plugin.getServer().getPlayer(event.getName()).isOnline()) { - this.sessions.put(event.getName().toLowerCase(), true); - } - } - } - @EventHandler(priority = EventPriority.LOWEST) public void onPlayerLogin(PlayerLoginEvent event) { @@ -602,7 +584,8 @@ public class AuthMePlayerListener implements Listener { if(!Settings.isSessionsEnabled) { LimboCache.getInstance().addLimboPlayer(player , utils.removeAll(player)); } else if(PlayerCache.getInstance().isAuthenticated(name)) { - if(LimboCache.getInstance().hasLimboPlayer(player.getName().toLowerCase())) { + if(!Settings.sessionExpireOnIpChange) + if(LimboCache.getInstance().hasLimboPlayer(player.getName().toLowerCase())) { LimboCache.getInstance().deleteLimboPlayer(name); } LimboCache.getInstance().addLimboPlayer(player , utils.removeAll(player)); @@ -617,6 +600,7 @@ public class AuthMePlayerListener implements Listener { if(!Settings.isSessionsEnabled) { LimboCache.getInstance().addLimboPlayer(player , utils.removeAll(player)); } else if(PlayerCache.getInstance().isAuthenticated(name)) { + if(!Settings.sessionExpireOnIpChange) if(LimboCache.getInstance().hasLimboPlayer(player.getName().toLowerCase())) { LimboCache.getInstance().deleteLimboPlayer(name); } @@ -717,7 +701,6 @@ public class AuthMePlayerListener implements Listener { if((cur - lastLogin < timeout || timeout == 0) && !auth.getIp().equals("198.18.0.1") ) { - if (!this.sessions.containsKey(name)) { if (auth.getNickname().equalsIgnoreCase(name) && auth.getIp().equals(ip) ) { plugin.getServer().getPluginManager().callEvent(new SessionEvent(auth, true)); if(PlayerCache.getInstance().getAuth(name) != null) { @@ -727,18 +710,21 @@ public class AuthMePlayerListener implements Listener { } player.sendMessage(m._("valid_session")); return; - } else { + } else if (!Settings.sessionExpireOnIpChange){ int gM = gameMode.get(name); player.setGameMode(GameMode.getByValue(gM)); player.kickPlayer(m._("unvalid_session")); return; - } - } else { - //Player change his IP between 2 relog-in - PlayerCache.getInstance().removePlayer(name); - LimboCache.getInstance().addLimboPlayer(player , utils.removeAll(player)); - this.sessions.remove(name); - } + } else if (auth.getNickname().equalsIgnoreCase(name)){ + //Player change his IP between 2 relog-in + PlayerCache.getInstance().removePlayer(name); + LimboCache.getInstance().addLimboPlayer(player , utils.removeAll(player)); + } else { + int gM = gameMode.get(name); + player.setGameMode(GameMode.getByValue(gM)); + player.kickPlayer(m._("unvalid_session")); + return; + } } else { //Session is ended correctly PlayerCache.getInstance().removePlayer(name); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 61d43af8c..d203ce4be 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ author: darkwarriros,Xephi website: http://www.multiplayer-italia.com/ description: AuthMe prevents people, which aren't logged in, from doing stuff like placing blocks, moving, typing commands or seeing the inventory of the current player. main: uk.org.whoami.authme.AuthMe -version: 2.7.11b2 +version: 2.7.11b3 softdepend: [Vault, ChestShop, Spout, Multiverse-Core, Notifications, Citizens, CombatTag] commands: register: