From acdd5f3faad4aad38a0438e6009d30df0baf118c Mon Sep 17 00:00:00 2001 From: Luck Date: Mon, 25 Nov 2019 22:51:11 +0000 Subject: [PATCH] Don't attempt to load permissions data for login events cancelled at the lowest priority Makes LuckPerms more compatible with "anti-bot" plugins. --- .../bukkit/listeners/BukkitConnectionListener.java | 10 +++++++++- .../bungee/listeners/BungeeConnectionListener.java | 6 ++++++ .../nukkit/listeners/NukkitConnectionListener.java | 10 +++++++++- .../sponge/listeners/SpongeConnectionListener.java | 10 +++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java index f18b7fb09..c40ca0cc5 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java @@ -81,7 +81,8 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme @EventHandler(priority = EventPriority.LOW) public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) { /* Called when the player first attempts a connection with the server. - Listening on LOW priority to allow plugins to modify username / UUID data here. (auth plugins) */ + Listening on LOW priority to allow plugins to modify username / UUID data here. (auth plugins) + Also, give other plugins a chance to cancel the event. */ /* wait for the plugin to enable. because these events are fired async, they can be called before the plugin has enabled. */ @@ -95,6 +96,13 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme this.plugin.getLogger().info("Processing pre-login for " + e.getUniqueId() + " - " + e.getName()); } + if (e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) { + // another plugin has disallowed the login. + this.plugin.getLogger().info("Another plugin has cancelled the connection for " + e.getUniqueId() + " - " + e.getName() + ". No permissions data will be loaded."); + this.deniedAsyncLogin.add(e.getUniqueId()); + return; + } + /* Actually process the login for the connection. We do this here to delay the login until the data is ready. If the login gets cancelled later on, then this will be cleaned up. diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeeConnectionListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeeConnectionListener.java index 60d9d1223..6be44432b 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeeConnectionListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeeConnectionListener.java @@ -70,6 +70,12 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme this.plugin.getLogger().info("Processing pre-login for " + c.getUniqueId() + " - " + c.getName()); } + if (e.isCancelled()) { + // another plugin has disallowed the login. + this.plugin.getLogger().info("Another plugin has cancelled the connection for " + c.getUniqueId() + " - " + c.getName() + ". No permissions data will be loaded."); + return; + } + this.plugin.getBootstrap().getScheduler().executeAsync(() -> { /* Actually process the login for the connection. We do this here to delay the login until the data is ready. diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/listeners/NukkitConnectionListener.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/listeners/NukkitConnectionListener.java index 0333253d7..f4a3ad5ef 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/listeners/NukkitConnectionListener.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/listeners/NukkitConnectionListener.java @@ -60,12 +60,20 @@ public class NukkitConnectionListener extends AbstractConnectionListener impleme @EventHandler(priority = EventPriority.LOW) public void onPlayerPreLogin(PlayerAsyncPreLoginEvent e) { /* Called when the player first attempts a connection with the server. - Listening on LOW priority to allow plugins to modify username / UUID data here. (auth plugins) */ + Listening on LOW priority to allow plugins to modify username / UUID data here. (auth plugins) + Also, give other plugins a chance to cancel the event. */ if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) { this.plugin.getLogger().info("Processing pre-login for " + e.getUuid() + " - " + e.getName()); } + if (e.getLoginResult() != PlayerAsyncPreLoginEvent.LoginResult.SUCCESS) { + // another plugin has disallowed the login. + this.plugin.getLogger().info("Another plugin has cancelled the connection for " + e.getUuid() + " - " + e.getName() + ". No permissions data will be loaded."); + this.deniedAsyncLogin.add(e.getUuid()); + return; + } + /* Actually process the login for the connection. We do this here to delay the login until the data is ready. If the login gets cancelled later on, then this will be cleaned up. diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongeConnectionListener.java b/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongeConnectionListener.java index 56040bef5..b47546363 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongeConnectionListener.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongeConnectionListener.java @@ -59,7 +59,8 @@ public class SpongeConnectionListener extends AbstractConnectionListener { @IsCancelled(Tristate.UNDEFINED) public void onClientAuth(ClientConnectionEvent.Auth e) { /* Called when the player first attempts a connection with the server. - Listening on AFTER_PRE priority to allow plugins to modify username / UUID data here. (auth plugins) */ + Listening on AFTER_PRE priority to allow plugins to modify username / UUID data here. (auth plugins) + Also, give other plugins a chance to cancel the event. */ final GameProfile profile = e.getProfile(); final String username = profile.getName().orElseThrow(() -> new RuntimeException("No username present for user " + profile.getUniqueId())); @@ -68,6 +69,13 @@ public class SpongeConnectionListener extends AbstractConnectionListener { this.plugin.getLogger().info("Processing auth event for " + profile.getUniqueId() + " - " + profile.getName()); } + if (e.isCancelled()) { + // another plugin has disallowed the login. + this.plugin.getLogger().info("Another plugin has cancelled the connection for " + profile.getUniqueId() + " - " + username + ". No permissions data will be loaded."); + this.deniedAsyncLogin.add(profile.getUniqueId()); + return; + } + /* Actually process the login for the connection. We do this here to delay the login until the data is ready. If the login gets cancelled later on, then this will be cleaned up.