From b53f71706a55ab3083cf2a9a84aeecdee8444458 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 15 Nov 2016 18:41:27 +0100 Subject: [PATCH] Join process cleanup, change some default settings (should improve performance and security with default settings) --- .../xephi/authme/listener/PlayerListener.java | 8 +++++--- .../authme/process/join/AsynchronousJoin.java | 18 +----------------- .../process/login/ProcessSyncPlayerLogin.java | 10 ---------- .../fr/xephi/authme/service/GeoIpService.java | 4 +++- .../settings/properties/HooksSettings.java | 2 +- .../settings/properties/PluginSettings.java | 7 ------- .../properties/RegistrationSettings.java | 2 +- .../properties/RestrictionSettings.java | 4 ++-- 8 files changed, 13 insertions(+), 42 deletions(-) diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index 73a552f03..92cf6a841 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -208,9 +208,11 @@ public class PlayerListener implements Listener { final String name = player.getName(); if (validationService.isUnrestricted(name)) { return; - } else if (onJoinVerifier.refusePlayerForFullServer(event)) { + } + if (onJoinVerifier.refusePlayerForFullServer(event)) { return; - } else if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) { + } + if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) { return; } @@ -223,8 +225,8 @@ public class PlayerListener implements Listener { // Slow stuff final PlayerAuth auth = dataSource.getAuth(name); final boolean isAuthAvailable = (auth != null); - onJoinVerifier.checkAntibot(player, isAuthAvailable); onJoinVerifier.checkKickNonRegistered(isAuthAvailable); + onJoinVerifier.checkAntibot(player, isAuthAvailable); onJoinVerifier.checkNameCasing(player, auth); onJoinVerifier.checkPlayerCountry(isAuthAvailable, event.getAddress().getHostAddress()); } catch (FailedVerificationException e) { diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index 89e7a671e..490bc9ba7 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -22,9 +22,7 @@ import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.task.LimboPlayerTaskManager; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.util.PlayerUtils; -import org.apache.commons.lang.reflect.MethodUtils; import org.bukkit.GameMode; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -39,9 +37,6 @@ import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND; */ public class AsynchronousJoin implements AsynchronousProcess { - private static final boolean DISABLE_COLLISIONS = MethodUtils - .getAccessibleMethod(LivingEntity.class, "setCollidable", new Class[]{}) != null; - @Inject private AuthMe plugin; @@ -75,20 +70,14 @@ public class AsynchronousJoin implements AsynchronousProcess { AsynchronousJoin() { } - public void processJoin(final Player player) { final String name = player.getName().toLowerCase(); final String ip = PlayerUtils.getPlayerIp(player); - if (isPlayerUnrestricted(name)) { + if (service.getProperty(RestrictionSettings.UNRESTRICTED_NAMES).contains(name)) { return; } - // Prevent player collisions in 1.9 - if (DISABLE_COLLISIONS) { - player.setCollidable(false); - } - if (service.getProperty(RestrictionSettings.FORCE_SURVIVAL_MODE) && !service.hasPermission(player, PlayerStatePermission.BYPASS_FORCE_SURVIVAL)) { bukkitService.runTask(() -> player.setGameMode(GameMode.SURVIVAL)); @@ -115,7 +104,6 @@ public class AsynchronousJoin implements AsynchronousProcess { return; } - final boolean isAuthAvailable = database.isAuthAvailable(name); if (isAuthAvailable) { @@ -189,10 +177,6 @@ public class AsynchronousJoin implements AsynchronousProcess { limboPlayerTaskManager.registerMessageTask(name, isAuthAvailable); } - private boolean isPlayerUnrestricted(String name) { - return service.getProperty(RestrictionSettings.UNRESTRICTED_NAMES).contains(name); - } - /** * Returns whether the name is restricted based on the restriction settings. * diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java index a31f4d28f..2488be8a1 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java @@ -14,23 +14,17 @@ import fr.xephi.authme.service.BungeeService; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.service.TeleportationService; -import org.apache.commons.lang.reflect.MethodUtils; import org.bukkit.Bukkit; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.potion.PotionEffectType; import javax.inject.Inject; -import static fr.xephi.authme.settings.properties.PluginSettings.KEEP_COLLISIONS_DISABLED; import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN; public class ProcessSyncPlayerLogin implements SynchronousProcess { - private static final boolean RESTORE_COLLISIONS = MethodUtils - .getAccessibleMethod(LivingEntity.class, "setCollidable", new Class[]{}) != null; - @Inject private AuthMe plugin; @@ -88,10 +82,6 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess { // because LimboCache#restoreData teleport player to last location. } - if (RESTORE_COLLISIONS && !service.getProperty(KEEP_COLLISIONS_DISABLED)) { - player.setCollidable(true); - } - if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) { restoreInventory(player); } diff --git a/src/main/java/fr/xephi/authme/service/GeoIpService.java b/src/main/java/fr/xephi/authme/service/GeoIpService.java index f1335c7df..22e9af2ca 100644 --- a/src/main/java/fr/xephi/authme/service/GeoIpService.java +++ b/src/main/java/fr/xephi/authme/service/GeoIpService.java @@ -17,6 +17,8 @@ import java.net.URLConnection; import java.util.concurrent.TimeUnit; import java.util.zip.GZIPInputStream; +import static com.maxmind.geoip.LookupService.GEOIP_MEMORY_CACHE; + public class GeoIpService { private static final String LICENSE = "[LICENSE] This product uses data from the GeoLite API created by MaxMind, available at http://www.maxmind.com"; @@ -57,7 +59,7 @@ public class GeoIpService { boolean dataIsOld = (System.currentTimeMillis() - dataFile.lastModified()) > TimeUnit.DAYS.toMillis(30); if (!dataIsOld) { try { - lookupService = new LookupService(dataFile); + lookupService = new LookupService(dataFile, GEOIP_MEMORY_CACHE); ConsoleLogger.info(LICENSE); return true; } catch (IOException e) { diff --git a/src/main/java/fr/xephi/authme/settings/properties/HooksSettings.java b/src/main/java/fr/xephi/authme/settings/properties/HooksSettings.java index 77b1767ed..68d2ad73d 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/HooksSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/HooksSettings.java @@ -25,7 +25,7 @@ public class HooksSettings implements SettingsHolder { @Comment("Do we need to disable Essentials SocialSpy on join?") public static final Property DISABLE_SOCIAL_SPY = - newProperty("Hooks.disableSocialSpy", true); + newProperty("Hooks.disableSocialSpy", false); @Comment("Do we need to force /motd Essentials command on join?") public static final Property USE_ESSENTIALS_MOTD = diff --git a/src/main/java/fr/xephi/authme/settings/properties/PluginSettings.java b/src/main/java/fr/xephi/authme/settings/properties/PluginSettings.java index 094a3d5b9..91d71d7ff 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/PluginSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/PluginSettings.java @@ -52,13 +52,6 @@ public class PluginSettings implements SettingsHolder { public static final Property ENABLE_PERMISSION_CHECK = newProperty("permission.EnablePermissionCheck", false); - @Comment({ - "Keeps collisions disabled for logged players", - "Works only with MC 1.9" - }) - public static final Property KEEP_COLLISIONS_DISABLED = - newProperty("settings.restrictions.keepCollisionsDisabled", false); - @Comment({ "Log level: INFO, FINE, DEBUG. Use INFO for general messages,", "FINE for some additional detailed ones (like password failed),", diff --git a/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java b/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java index 487039ba7..bf250e1f4 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java @@ -108,7 +108,7 @@ public class RegistrationSettings implements SettingsHolder { "Do we need to prevent people to login with another case?", "If Xephi is registered, then Xephi can login, but not XEPHI/xephi/XePhI"}) public static final Property PREVENT_OTHER_CASE = - newProperty("settings.preventOtherCase", false); + newProperty("settings.preventOtherCase", true); private RegistrationSettings() { diff --git a/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java b/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java index 7f426b1d6..c62b93e3b 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java @@ -90,7 +90,7 @@ public class RestrictionSettings implements SettingsHolder { @Comment("Should players be kicked on wrong password?") public static final Property KICK_ON_WRONG_PASSWORD = - newProperty("settings.restrictions.kickOnWrongPassword", false); + newProperty("settings.restrictions.kickOnWrongPassword", true); @Comment({ "Should not logged in players be teleported to the spawn?", @@ -139,7 +139,7 @@ public class RestrictionSettings implements SettingsHolder { @Comment("Should we deny the tabcomplete feature before logging in? Requires ProtocolLib.") public static final Property DENY_TABCOMPLETE_BEFORE_LOGIN = - newProperty("settings.restrictions.DenyTabCompleteBeforeLogin", true); + newProperty("settings.restrictions.DenyTabCompleteBeforeLogin", false); @Comment({ "Should we display all other accounts from a player when he joins?",