From e03e67b8fa2808099b28687e0c71f4438a5c07e6 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Fri, 19 Mar 2021 08:58:29 +0100 Subject: [PATCH 01/36] Detect if a player is connecting through Floodgate The Floodgate API requires UUID which is inaccessible at the level FastLogion operates on. A workaround for this is to check if the currently connecting player is also a part of the Geyser server's online players list. *TODO: Check for Java and Bedrock name conflicts with multiple configurations.* --- bukkit/pom.xml | 13 +++++++++++++ .../protocollib/ProtocolLibListener.java | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 94ce764d..6b4d4aa8 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -98,6 +98,12 @@ false + + + + nukkitx-snapshot + https://repo.nukkitx.com/maven-snapshots/ + @@ -213,6 +219,13 @@ + + + org.geysermc + connector + 1.2.0-SNAPSHOT + provided + diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java index fbc3fda6..2abf273c 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java @@ -12,6 +12,9 @@ import java.security.KeyPair; import java.security.SecureRandom; import org.bukkit.entity.Player; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.common.AuthType; +import org.geysermc.connector.network.session.GeyserSession; import static com.comphenix.protocol.PacketType.Login.Client.ENCRYPTION_BEGIN; import static com.comphenix.protocol.PacketType.Login.Client.START; @@ -87,6 +90,21 @@ public class ProtocolLibListener extends PacketAdapter { String username = packet.getGameProfiles().read(0).getName(); plugin.getLog().trace("GameProfile {} with {} connecting", sessionKey, username); + // check if the player is connecting through Geyser + if (GeyserConnector.getInstance().getDefaultAuthType() == AuthType.FLOODGATE) { + // the Floodgate API requires UUID, which is inaccessible at this state + // workaround: iterate over Geyser's player's usernames + for (GeyserSession geyserPlayer : GeyserConnector.getInstance().getPlayers()) { + if (geyserPlayer.getName().equals(username)) { + plugin.getLog().info( + "Player {} is connecting throught Geyser Floodgate. FastLogin will not check this player.", + username); + // TODO: auto login (WHEN?) + return; + } + } + } + packetEvent.getAsyncMarker().incrementProcessingDelay(); Runnable nameCheckTask = new NameCheckTask(plugin, packetEvent, random, player, username, keyPair.getPublic()); plugin.getScheduler().runAsync(nameCheckTask); From 57e797f1be0995a7636143023bbca6126ea82dae Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 20 Mar 2021 12:22:41 +0100 Subject: [PATCH 02/36] Implement auto login for Floodgate players This is buggy in most cases. --- bukkit/pom.xml | 7 +++++++ .../bukkit/listener/ConnectionListener.java | 18 +++++++++++++++++- .../listener/protocollib/NameCheckTask.java | 16 ++++++++++++++++ .../protocollib/ProtocolLibListener.java | 15 --------------- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 6b4d4aa8..53d1f470 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -226,6 +226,13 @@ 1.2.0-SNAPSHOT provided + + + org.geysermc + floodgate-bukkit + 1.0-SNAPSHOT + provided + diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index dc76a34a..546e0d80 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -3,6 +3,7 @@ package com.github.games647.fastlogin.bukkit.listener; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.task.ForceLoginTask; +import com.github.games647.fastlogin.core.StoredProfile; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -13,6 +14,8 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.PlayerQuitEvent; +import org.geysermc.floodgate.FloodgateAPI; +import org.geysermc.floodgate.FloodgatePlayer; /** * This listener tells authentication plugins if the player has a premium account and we checked it successfully. So the @@ -45,7 +48,20 @@ public class ConnectionListener implements Listener { // cases: Paper (firing BungeeCord message before PlayerJoinEvent) or not running BungeeCord and already // having the login session from the login process BukkitLoginSession session = plugin.getSession(player.getAddress()); - if (session == null) { + FloodgatePlayer floodgatePlayer = FloodgateAPI.getPlayer(player.getUniqueId()); + if (floodgatePlayer != null) { + StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName()); + + //create fake session to make auto login work + session = new BukkitLoginSession(player.getName(), profile.isSaved()); + session.setVerified(true); + + //start auto login + //TODO: configurate auto login for floodgate players + //TODO: fix bug: registering as bedrock player breaks java auto login + Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); + Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); + } else if (session == null) { String sessionId = plugin.getSessionId(player.getAddress()); plugin.getLog().info("No on-going login session for player: {} with ID {}", player, sessionId); } else { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index 67249722..2413dfb3 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -14,6 +14,9 @@ import java.util.Random; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.common.AuthType; +import org.geysermc.connector.network.session.GeyserSession; public class NameCheckTask extends JoinManagement implements Runnable { @@ -42,6 +45,19 @@ public class NameCheckTask extends JoinManagement Date: Sat, 20 Mar 2021 13:38:41 +0100 Subject: [PATCH 03/36] Check if Geyser and Floodgate are installed before accessing them --- .../bukkit/listener/ConnectionListener.java | 29 ++++++++++--------- .../listener/protocollib/NameCheckTask.java | 21 ++++++++------ bukkit/src/main/resources/plugin.yml | 3 ++ 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index 546e0d80..5ddad9bc 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -48,20 +48,23 @@ public class ConnectionListener implements Listener { // cases: Paper (firing BungeeCord message before PlayerJoinEvent) or not running BungeeCord and already // having the login session from the login process BukkitLoginSession session = plugin.getSession(player.getAddress()); - FloodgatePlayer floodgatePlayer = FloodgateAPI.getPlayer(player.getUniqueId()); - if (floodgatePlayer != null) { - StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName()); + + if(Bukkit.getServer().getPluginManager().getPlugin("Geyser-Spigot") != null && + Bukkit.getServer().getPluginManager().getPlugin("floodgate-bukkit") != null) { + //TODO: Does this return null if a player is connected through Geyser Online mode? + FloodgatePlayer floodgatePlayer = FloodgateAPI.getPlayer(player.getUniqueId()); + if (floodgatePlayer != null) { + StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName()); - //create fake session to make auto login work - session = new BukkitLoginSession(player.getName(), profile.isSaved()); - session.setVerified(true); - - //start auto login - //TODO: configurate auto login for floodgate players - //TODO: fix bug: registering as bedrock player breaks java auto login - Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); - Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); - } else if (session == null) { + //create fake session to make auto login work + session = new BukkitLoginSession(player.getName(), profile.isSaved()); + session.setVerified(true); + + //TODO: configurate auto login for floodgate players + //TODO: fix bug: registering as bedrock player breaks java auto login + } + } + if (session == null) { String sessionId = plugin.getSessionId(player.getAddress()); plugin.getLog().info("No on-going login session for player: {} with ID {}", player, sessionId); } else { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index 2413dfb3..48e7cf87 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -12,6 +12,7 @@ import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; import java.security.PublicKey; import java.util.Random; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.geysermc.connector.GeyserConnector; @@ -46,15 +47,17 @@ public class NameCheckTask extends JoinManagement Date: Sat, 20 Mar 2021 14:41:21 +0100 Subject: [PATCH 04/36] Code cleanup --- .../games647/fastlogin/bukkit/listener/ConnectionListener.java | 2 +- .../bukkit/listener/protocollib/ProtocolLibListener.java | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index 5ddad9bc..545284a4 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -51,7 +51,7 @@ public class ConnectionListener implements Listener { if(Bukkit.getServer().getPluginManager().getPlugin("Geyser-Spigot") != null && Bukkit.getServer().getPluginManager().getPlugin("floodgate-bukkit") != null) { - //TODO: Does this return null if a player is connected through Geyser Online mode? + //TODO: Does this return null if a player is connected through Geyser Offline mode? FloodgatePlayer floodgatePlayer = FloodgateAPI.getPlayer(player.getUniqueId()); if (floodgatePlayer != null) { StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName()); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java index 165da38f..fbc3fda6 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java @@ -12,9 +12,6 @@ import java.security.KeyPair; import java.security.SecureRandom; import org.bukkit.entity.Player; -import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.common.AuthType; -import org.geysermc.connector.network.session.GeyserSession; import static com.comphenix.protocol.PacketType.Login.Client.ENCRYPTION_BEGIN; import static com.comphenix.protocol.PacketType.Login.Client.START; From 0206a6c5a4af5f9abe433459674b88d5b2dc0808 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 20 Mar 2021 15:37:37 +0100 Subject: [PATCH 05/36] Added new config options (not yet implemented) --- core/src/main/resources/config.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 19c4d6cf..15ad8724 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -186,6 +186,31 @@ auto-register-unknown: false # The password of your Minecraft and the password to login in with your auth plugin autoLogin: true +# Floodgate configuration +# Connecing through Floodgate requires player's to sign in via their Xbox Live account +# Requires https://github.com/GeyserMC/Floodgate/ and https://github.com/GeyserMC/Geyser/ +# These settings only work in Bukkit/Spigot/Paper mode + +# This enables auto login for every player connecting through Floodgate. +# Possible values: false, true, linked +# Linked means that only Bedrock accounts linked to a Java account will be logged in automatically +autoLoginFloodgate: false + +# This enables Floodgate players to join the server, even if autoRegister is true and there's an existing Java Premium +# account with the same name +# Possible values: +# false: Check for Premium Java name conflicts as described in 'autoRegister' +# true: Bypass 'autoRegister's name conflict checking +# linked: Bedrock accounts linked to a Java account will be allowed to join with conflicting names +# Note: Linking a new account requires players to log in with a non-linked Bedrock account first +# Enabling this will make linking new Bedrock players impossible +# More information on linking accounts: https://github.com/GeyserMC/Geyser/wiki/Floodgate#account-linking +# Releated Floodgate issue: https://github.com/GeyserMC/Floodgate/issues/37 +allowFloodgateNameConflict: false + +# This enables auto registering every player connecting through Floodgate. +autoRegisterFloodgate: false + # Database configuration # Recommended is the use of MariaDB (a better version of MySQL) From a23f846146358860accdd7514285306e25692517 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 20 Mar 2021 17:16:55 +0100 Subject: [PATCH 06/36] Implement allowFloodgateNameConflict Check config.yml for details. --- .../bukkit/listener/ConnectionListener.java | 49 ++++++++++++++++--- .../listener/protocollib/NameCheckTask.java | 22 ++++----- core/src/main/resources/config.yml | 7 ++- 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index 545284a4..ab066866 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -14,6 +14,8 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.PlayerQuitEvent; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.floodgate.FloodgateAPI; import org.geysermc.floodgate.FloodgatePlayer; @@ -50,18 +52,49 @@ public class ConnectionListener implements Listener { BukkitLoginSession session = plugin.getSession(player.getAddress()); if(Bukkit.getServer().getPluginManager().getPlugin("Geyser-Spigot") != null && - Bukkit.getServer().getPluginManager().getPlugin("floodgate-bukkit") != null) { - //TODO: Does this return null if a player is connected through Geyser Offline mode? - FloodgatePlayer floodgatePlayer = FloodgateAPI.getPlayer(player.getUniqueId()); - if (floodgatePlayer != null) { - StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName()); + Bukkit.getServer().getPluginManager().getPlugin("floodgate-bukkit") != null) { + FloodgatePlayer floodgatePlayer = null; - //create fake session to make auto login work + // check if the player is really connected through Geyser + for (GeyserSession geyserPlayer : GeyserConnector.getInstance().getPlayers()) { + if (geyserPlayer.getName().equals(player.getName())) { + // this also returns a floodgatePlayer for linked Java accounts + // that's why the Geyser Server's player list also has to be checked + //TODO: does this return null if a player is connected through Geyser Offline mode? + floodgatePlayer = FloodgateAPI.getPlayer(player.getUniqueId()); + break; + } + } + + if (floodgatePlayer != null) { + plugin.getLog().info( + "Player {} is connecting through Geyser Floodgate.", + player.getName()); + String allowNameConflict = plugin.getCore().getConfig().getString("allowFloodgateNameConflict"); + if (allowNameConflict.equalsIgnoreCase("linked") && + floodgatePlayer.fetchLinkedPlayer() == null) { + plugin.getLog().info( + "Bedrock Player {}'s name conflits an existing Java Premium Player's name", + player.getName()); + player.kickPlayer("This name is allready in use by a Premium Java Player"); + + } + if (!allowNameConflict.equalsIgnoreCase("true") && !allowNameConflict.equalsIgnoreCase("linked")) { + plugin.getLog().error( + "Invalid value detected for 'allowNameConflict' in FasttLogin/config.yml. Aborting login of Player {}", + player.getName()); + return; + } + + StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName()); + + // create fake session to make auto login work session = new BukkitLoginSession(player.getName(), profile.isSaved()); session.setVerified(true); - //TODO: configurate auto login for floodgate players - //TODO: fix bug: registering as bedrock player breaks java auto login + // TODO: configurate auto login for floodgate players + // TODO: fix bug: registering as bedrock player breaks java auto login + } } if (session == null) { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index 48e7cf87..acdf82a9 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -47,17 +47,17 @@ public class NameCheckTask extends JoinManagement Date: Sat, 20 Mar 2021 18:28:32 +0100 Subject: [PATCH 07/36] Implement autoLoginFloodgate & autoRegisterFloodgate config options Knwon Bug: Profile.isSaved() is 'false' when logging in from Bedrock after auto registering through Bedrock so FastLogin will try to register for a second time, insted of logging in --- .../bukkit/listener/ConnectionListener.java | 20 +++++++++++-------- core/src/main/resources/config.yml | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index ab066866..838e8710 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -71,8 +71,9 @@ public class ConnectionListener implements Listener { "Player {} is connecting through Geyser Floodgate.", player.getName()); String allowNameConflict = plugin.getCore().getConfig().getString("allowFloodgateNameConflict"); - if (allowNameConflict.equalsIgnoreCase("linked") && - floodgatePlayer.fetchLinkedPlayer() == null) { + // check if the Bedrock player is linked to a Java account + boolean isLinked = floodgatePlayer.fetchLinkedPlayer() != null; + if (allowNameConflict.equalsIgnoreCase("linked") && !isLinked) { plugin.getLog().info( "Bedrock Player {}'s name conflits an existing Java Premium Player's name", player.getName()); @@ -88,13 +89,16 @@ public class ConnectionListener implements Listener { StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName()); + String autoLoginFloodgate = plugin.getCore().getConfig().getString("autoLoginFloodgate"); + boolean autoRegisterFloodgate = plugin.getCore().getConfig().getBoolean("autoRegisterFloodgate"); + // create fake session to make auto login work - session = new BukkitLoginSession(player.getName(), profile.isSaved()); - session.setVerified(true); - - // TODO: configurate auto login for floodgate players - // TODO: fix bug: registering as bedrock player breaks java auto login - + // the player should only be registered (=> parm. registered = false) if + // the player is not registered and autoRegister is enabled in the config + session = new BukkitLoginSession(player.getName(), profile.isSaved() || !autoRegisterFloodgate); + // enable auto login based on the value of 'autoLoginFloodgate' in config.yml + session.setVerified(autoLoginFloodgate.equalsIgnoreCase("true") + || (autoLoginFloodgate.equalsIgnoreCase("linked") && isLinked)); } } if (session == null) { diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 6b7bb6f3..3d0f12eb 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -212,6 +212,7 @@ autoLoginFloodgate: 'false' allowFloodgateNameConflict: 'false' # This enables auto registering every player connecting through Floodgate. +# autoLoginFloodgate must be 'true' for this to work autoRegisterFloodgate: false # Database configuration From 78f897a490b8a1a2c800293d5680e2d703b86f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Tombor?= <28480228+Smart123s@users.noreply.github.com> Date: Sun, 21 Mar 2021 10:59:58 +0100 Subject: [PATCH 08/36] Use isPluginEnabled() in ConnectionListener.java Co-authored-by: games647 --- .../fastlogin/bukkit/listener/ConnectionListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index 838e8710..e33e716f 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -51,8 +51,8 @@ public class ConnectionListener implements Listener { // having the login session from the login process BukkitLoginSession session = plugin.getSession(player.getAddress()); - if(Bukkit.getServer().getPluginManager().getPlugin("Geyser-Spigot") != null && - Bukkit.getServer().getPluginManager().getPlugin("floodgate-bukkit") != null) { + if (Bukkit.getServer().getPluginManager().isPluginEnabled("Geyser-Spigot") && + Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate-bukkit")) { FloodgatePlayer floodgatePlayer = null; // check if the player is really connected through Geyser From c41896e5f2598734820e29fce92e5347a57302a7 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 21 Mar 2021 11:02:29 +0100 Subject: [PATCH 09/36] Use isPluginEnabled() in NameCheckTask.java --- .../fastlogin/bukkit/listener/protocollib/NameCheckTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index acdf82a9..140cb705 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -48,7 +48,7 @@ public class NameCheckTask extends JoinManagement Date: Sun, 21 Mar 2021 11:07:18 +0100 Subject: [PATCH 10/36] Move dependencies --- bukkit/pom.xml | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 53d1f470..47a5b254 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -162,6 +162,22 @@ + + + org.geysermc + connector + 1.2.0-SNAPSHOT + provided + + + + + org.geysermc + floodgate-bukkit + 1.0-SNAPSHOT + provided + + fr.xephi @@ -219,20 +235,6 @@ - - - org.geysermc - connector - 1.2.0-SNAPSHOT - provided - - - - org.geysermc - floodgate-bukkit - 1.0-SNAPSHOT - provided - From ee2ae7f9fd9d97280a91651bba2b2809602033ee Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 21 Mar 2021 19:21:49 +0100 Subject: [PATCH 11/36] Use authPlugin.isRegistered() instead of profile.isSaved() --- .../bukkit/listener/ConnectionListener.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index e33e716f..98693da5 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -3,7 +3,7 @@ package com.github.games647.fastlogin.bukkit.listener; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.task.ForceLoginTask; -import com.github.games647.fastlogin.core.StoredProfile; +import com.github.games647.fastlogin.core.hooks.AuthPlugin; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -87,7 +87,7 @@ public class ConnectionListener implements Listener { return; } - StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName()); + AuthPlugin authPlugin = plugin.getCore().getAuthPluginHook(); String autoLoginFloodgate = plugin.getCore().getConfig().getString("autoLoginFloodgate"); boolean autoRegisterFloodgate = plugin.getCore().getConfig().getBoolean("autoRegisterFloodgate"); @@ -95,10 +95,17 @@ public class ConnectionListener implements Listener { // create fake session to make auto login work // the player should only be registered (=> parm. registered = false) if // the player is not registered and autoRegister is enabled in the config - session = new BukkitLoginSession(player.getName(), profile.isSaved() || !autoRegisterFloodgate); - // enable auto login based on the value of 'autoLoginFloodgate' in config.yml - session.setVerified(autoLoginFloodgate.equalsIgnoreCase("true") - || (autoLoginFloodgate.equalsIgnoreCase("linked") && isLinked)); + try { + session = new BukkitLoginSession(player.getName(), authPlugin.isRegistered(player.getName()) || !autoRegisterFloodgate); + // enable auto login based on the value of 'autoLoginFloodgate' in config.yml + session.setVerified(autoLoginFloodgate.equalsIgnoreCase("true") + || (autoLoginFloodgate.equalsIgnoreCase("linked") && isLinked)); + } catch (Exception e) { + plugin.getLog().error( + "An error has occured while checking if player {} is registered", + player.getName()); + return; + } } } if (session == null) { From 8c8ed0b6391b058bed8622864afdb6f48c61fe15 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Mon, 22 Mar 2021 10:16:23 +0100 Subject: [PATCH 12/36] Made FloodgateAuth async --- .../bukkit/listener/ConnectionListener.java | 69 ++------------ .../listener/protocollib/NameCheckTask.java | 22 ++--- .../bukkit/task/FloodgateAuthTask.java | 90 +++++++++++++++++++ 3 files changed, 100 insertions(+), 81 deletions(-) create mode 100644 bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index 98693da5..e31cedf9 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -2,9 +2,8 @@ package com.github.games647.fastlogin.bukkit.listener; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; +import com.github.games647.fastlogin.bukkit.task.FloodgateAuthTask; import com.github.games647.fastlogin.bukkit.task.ForceLoginTask; -import com.github.games647.fastlogin.core.hooks.AuthPlugin; - import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -14,10 +13,6 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.PlayerQuitEvent; -import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.floodgate.FloodgateAPI; -import org.geysermc.floodgate.FloodgatePlayer; /** * This listener tells authentication plugins if the player has a premium account and we checked it successfully. So the @@ -51,64 +46,10 @@ public class ConnectionListener implements Listener { // having the login session from the login process BukkitLoginSession session = plugin.getSession(player.getAddress()); - if (Bukkit.getServer().getPluginManager().isPluginEnabled("Geyser-Spigot") && - Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate-bukkit")) { - FloodgatePlayer floodgatePlayer = null; - - // check if the player is really connected through Geyser - for (GeyserSession geyserPlayer : GeyserConnector.getInstance().getPlayers()) { - if (geyserPlayer.getName().equals(player.getName())) { - // this also returns a floodgatePlayer for linked Java accounts - // that's why the Geyser Server's player list also has to be checked - //TODO: does this return null if a player is connected through Geyser Offline mode? - floodgatePlayer = FloodgateAPI.getPlayer(player.getUniqueId()); - break; - } - } - - if (floodgatePlayer != null) { - plugin.getLog().info( - "Player {} is connecting through Geyser Floodgate.", - player.getName()); - String allowNameConflict = plugin.getCore().getConfig().getString("allowFloodgateNameConflict"); - // check if the Bedrock player is linked to a Java account - boolean isLinked = floodgatePlayer.fetchLinkedPlayer() != null; - if (allowNameConflict.equalsIgnoreCase("linked") && !isLinked) { - plugin.getLog().info( - "Bedrock Player {}'s name conflits an existing Java Premium Player's name", - player.getName()); - player.kickPlayer("This name is allready in use by a Premium Java Player"); - - } - if (!allowNameConflict.equalsIgnoreCase("true") && !allowNameConflict.equalsIgnoreCase("linked")) { - plugin.getLog().error( - "Invalid value detected for 'allowNameConflict' in FasttLogin/config.yml. Aborting login of Player {}", - player.getName()); - return; - } - - AuthPlugin authPlugin = plugin.getCore().getAuthPluginHook(); - - String autoLoginFloodgate = plugin.getCore().getConfig().getString("autoLoginFloodgate"); - boolean autoRegisterFloodgate = plugin.getCore().getConfig().getBoolean("autoRegisterFloodgate"); - - // create fake session to make auto login work - // the player should only be registered (=> parm. registered = false) if - // the player is not registered and autoRegister is enabled in the config - try { - session = new BukkitLoginSession(player.getName(), authPlugin.isRegistered(player.getName()) || !autoRegisterFloodgate); - // enable auto login based on the value of 'autoLoginFloodgate' in config.yml - session.setVerified(autoLoginFloodgate.equalsIgnoreCase("true") - || (autoLoginFloodgate.equalsIgnoreCase("linked") && isLinked)); - } catch (Exception e) { - plugin.getLog().error( - "An error has occured while checking if player {} is registered", - player.getName()); - return; - } - } - } - if (session == null) { + if (FloodgateAuthTask.getGeyserPlayer(player.getName()) != null) { + Runnable floodgateAuthTask = new FloodgateAuthTask(plugin, player); + Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask); + } else if (session == null) { String sessionId = plugin.getSessionId(player.getAddress()); plugin.getLog().info("No on-going login session for player: {} with ID {}", player, sessionId); } else { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index 140cb705..4508501e 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -5,6 +5,7 @@ import com.comphenix.protocol.events.PacketEvent; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent; +import com.github.games647.fastlogin.bukkit.task.FloodgateAuthTask; import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.shared.JoinManagement; import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; @@ -12,12 +13,8 @@ import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; import java.security.PublicKey; import java.util.Random; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.common.AuthType; -import org.geysermc.connector.network.session.GeyserSession; public class NameCheckTask extends JoinManagement implements Runnable { @@ -47,19 +44,10 @@ public class NameCheckTask extends JoinManagement authPlugin = plugin.getCore().getAuthPluginHook(); + + String autoLoginFloodgate = plugin.getCore().getConfig().getString("autoLoginFloodgate"); + boolean autoRegisterFloodgate = plugin.getCore().getConfig().getBoolean("autoRegisterFloodgate"); + + // create fake session to make auto login work + // the player should only be registered (=> parm. registered = false) if + // the player is not registered and autoRegister is enabled in the config + try { + BukkitLoginSession session = new BukkitLoginSession(player.getName(), authPlugin.isRegistered(player.getName()) || !autoRegisterFloodgate); + // enable auto login based on the value of 'autoLoginFloodgate' in config.yml + session.setVerified(autoLoginFloodgate.equalsIgnoreCase("true") + || (autoLoginFloodgate.equalsIgnoreCase("linked") && isLinked)); + + //run login task + Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); + Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); + } catch (Exception e) { + plugin.getLog().error( + "An error has occured while checking if player {} is registered", + player.getName()); + return; + } + } + + public static GeyserSession getGeyserPlayer(String username) { + if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate-bukkit") && + Bukkit.getServer().getPluginManager().isPluginEnabled("Geyser-Spigot") && + GeyserConnector.getInstance().getDefaultAuthType() == AuthType.FLOODGATE) { + // the Floodgate API requires UUID, which is inaccessible at NameCheckTask.java + // the Floodgate API has a return value for Java (non-bedrock) players, if they + // are linked to a Bedrock account + // workaround: iterate over Geyser's player's usernames + for (GeyserSession geyserPlayer : GeyserConnector.getInstance().getPlayers()) { + if (geyserPlayer.getName().equals(username)) { + return geyserPlayer; + } + } + } + return null; + } + +} From 305700497ecb22a1e379fa5a9b10e3dffeaca883 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Mon, 22 Mar 2021 11:43:30 +0100 Subject: [PATCH 13/36] Re-added an empty line (deleted by mistake) --- .../games647/fastlogin/bukkit/listener/ConnectionListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index e31cedf9..c578663f 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -4,6 +4,7 @@ import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.task.FloodgateAuthTask; import com.github.games647.fastlogin.bukkit.task.ForceLoginTask; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; From 07da8fc76ae7990e529d46e3d33133a97600240b Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Mon, 22 Mar 2021 17:22:51 +0100 Subject: [PATCH 14/36] autoRegisterFloodgate will no longer try to log in unregistered BE users previously if autoRegisterFloodgate was set to false and the player was not registered, the plugin tried to auto-login the user, which has led to misleading "Failed to login" messages --- .../bukkit/task/FloodgateAuthTask.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java index e8d838dc..1d6a3a78 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java @@ -50,26 +50,33 @@ public class FloodgateAuthTask implements Runnable { String autoLoginFloodgate = plugin.getCore().getConfig().getString("autoLoginFloodgate"); boolean autoRegisterFloodgate = plugin.getCore().getConfig().getBoolean("autoRegisterFloodgate"); - // create fake session to make auto login work - // the player should only be registered (=> parm. registered = false) if - // the player is not registered and autoRegister is enabled in the config + boolean isRegistered; try { - BukkitLoginSession session = new BukkitLoginSession(player.getName(), authPlugin.isRegistered(player.getName()) || !autoRegisterFloodgate); - // enable auto login based on the value of 'autoLoginFloodgate' in config.yml - session.setVerified(autoLoginFloodgate.equalsIgnoreCase("true") - || (autoLoginFloodgate.equalsIgnoreCase("linked") && isLinked)); - - //run login task - Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); - Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); + isRegistered = authPlugin.isRegistered(player.getName()); } catch (Exception e) { plugin.getLog().error( "An error has occured while checking if player {} is registered", player.getName()); return; } + + if (!isRegistered && !autoRegisterFloodgate) { + plugin.getLog().info( + "Auto registration is disabled for Floodgate players in config.yml"); + return; + } + + BukkitLoginSession session = new BukkitLoginSession(player.getName(), isRegistered); + + // enable auto login based on the value of 'autoLoginFloodgate' in config.yml + session.setVerified(autoLoginFloodgate.equalsIgnoreCase("true") + || (autoLoginFloodgate.equalsIgnoreCase("linked") && isLinked)); + + // run login task + Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); + Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); } - + public static GeyserSession getGeyserPlayer(String username) { if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate-bukkit") && Bukkit.getServer().getPluginManager().isPluginEnabled("Geyser-Spigot") && From 9abc99ebc21190a6c7f74c9dec854a55147aa006 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Mon, 22 Mar 2021 18:37:12 +0100 Subject: [PATCH 15/36] Use UUID instead of name when checking for Geyser player --- .../games647/fastlogin/bukkit/listener/ConnectionListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index c578663f..358776d2 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -13,6 +13,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent.Result; +import org.geysermc.connector.GeyserConnector; import org.bukkit.event.player.PlayerQuitEvent; /** @@ -47,7 +48,7 @@ public class ConnectionListener implements Listener { // having the login session from the login process BukkitLoginSession session = plugin.getSession(player.getAddress()); - if (FloodgateAuthTask.getGeyserPlayer(player.getName()) != null) { + if (GeyserConnector.getInstance().getPlayerByUuid(player.getUniqueId()) != null) { Runnable floodgateAuthTask = new FloodgateAuthTask(plugin, player); Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask); } else if (session == null) { From 5d94e610ff0a42ccea5245c4ceff0087ba33dc38 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Mon, 22 Mar 2021 19:51:46 +0100 Subject: [PATCH 16/36] Create a profile for Bedrock players when registering --- .../fastlogin/bukkit/task/FloodgateAuthTask.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java index 1d6a3a78..3d39d252 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java @@ -10,6 +10,7 @@ import org.geysermc.floodgate.FloodgatePlayer; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; +import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.hooks.AuthPlugin; public class FloodgateAuthTask implements Runnable { @@ -40,7 +41,7 @@ public class FloodgateAuthTask implements Runnable { } if (!allowNameConflict.equalsIgnoreCase("true") && !allowNameConflict.equalsIgnoreCase("linked")) { plugin.getLog().error( - "Invalid value detected for 'allowNameConflict' in FasttLogin/config.yml. Aborting login of Player {}", + "Invalid value detected for 'allowFloodgateNameConflict' in FasttLogin/config.yml. Aborting login of Player {}", player.getName()); return; } @@ -65,8 +66,14 @@ public class FloodgateAuthTask implements Runnable { "Auto registration is disabled for Floodgate players in config.yml"); return; } + + // logging in from bedrock for a second time threw an error with UUID + StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName()); + if (profile == null) { + profile = new StoredProfile(player.getUniqueId(), player.getName(), true, player.getAddress().toString()); + } - BukkitLoginSession session = new BukkitLoginSession(player.getName(), isRegistered); + BukkitLoginSession session = new BukkitLoginSession(player.getName(), isRegistered, profile); // enable auto login based on the value of 'autoLoginFloodgate' in config.yml session.setVerified(autoLoginFloodgate.equalsIgnoreCase("true") From f9992f144792723cf23000d8d032bb30833b0730 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Mon, 22 Mar 2021 19:57:13 +0100 Subject: [PATCH 17/36] Fixed 'allowFloodgateNameConflict' for 'false' value. --- .../games647/fastlogin/bukkit/task/FloodgateAuthTask.java | 4 +++- core/src/main/resources/config.yml | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java index 3d39d252..c20d2ada 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java @@ -39,7 +39,9 @@ public class FloodgateAuthTask implements Runnable { player.kickPlayer("This name is allready in use by a Premium Java Player"); } - if (!allowNameConflict.equalsIgnoreCase("true") && !allowNameConflict.equalsIgnoreCase("linked")) { + if (!allowNameConflict.equalsIgnoreCase("true") + && !allowNameConflict.equalsIgnoreCase("linked") + && !allowNameConflict.equalsIgnoreCase("false")) { plugin.getLog().error( "Invalid value detected for 'allowFloodgateNameConflict' in FasttLogin/config.yml. Aborting login of Player {}", player.getName()); diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 3d0f12eb..dfc8dc65 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -197,8 +197,8 @@ autoLogin: true # !!! DO NOT REMOVE THE APOSTROPHE !!! autoLoginFloodgate: 'false' -# This enables Floodgate players to join the server, even if autoRegister is true and there's an existing Java Premium -# account with the same name +# This enables Floodgate players to join the server, even if autoRegister is true and there's an existing +# Java **PREMIUM** account with the same name # Possible values: # false: Check for Premium Java name conflicts as described in 'autoRegister' # 'autoRegister' must be 'true' for this to work From e2e4e76fd9cebd374926c9d9badea6cad125fde0 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Mon, 22 Mar 2021 20:35:22 +0100 Subject: [PATCH 18/36] Moved getGeyserPlayer() to the only class it's used in --- .../listener/protocollib/NameCheckTask.java | 24 +++++++++++++++++-- .../bukkit/task/FloodgateAuthTask.java | 20 ---------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index 4508501e..d8da3d3c 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -5,7 +5,6 @@ import com.comphenix.protocol.events.PacketEvent; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent; -import com.github.games647.fastlogin.bukkit.task.FloodgateAuthTask; import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.shared.JoinManagement; import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; @@ -13,8 +12,12 @@ import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; import java.security.PublicKey; import java.util.Random; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.common.AuthType; +import org.geysermc.connector.network.session.GeyserSession; public class NameCheckTask extends JoinManagement implements Runnable { @@ -45,7 +48,7 @@ public class NameCheckTask extends JoinManagement Date: Mon, 22 Mar 2021 20:46:49 +0100 Subject: [PATCH 19/36] Fix "Asynchronous player kick" --- .../fastlogin/bukkit/task/FloodgateAuthTask.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java index b056b1f8..465c5d78 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java @@ -33,7 +33,14 @@ public class FloodgateAuthTask implements Runnable { plugin.getLog().info( "Bedrock Player {}'s name conflits an existing Java Premium Player's name", player.getName()); - player.kickPlayer("This name is allready in use by a Premium Java Player"); + + // kicking must be synchronous + // https://www.spigotmc.org/threads/asynchronous-player-kick-problem.168580/ + Bukkit.getScheduler().runTask(plugin, new Runnable() { + public void run() { + player.kickPlayer("This name is allready in use by a Premium Java Player"); + } + }); } if (!allowNameConflict.equalsIgnoreCase("true") From f7fd94e983996c26a6c00342d07ea653a2b34442 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Mon, 22 Mar 2021 21:25:27 +0100 Subject: [PATCH 20/36] Update config comments --- core/src/main/resources/config.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index dfc8dc65..5e80280d 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -190,11 +190,15 @@ autoLogin: true # Connecing through Floodgate requires player's to sign in via their Xbox Live account # Requires https://github.com/GeyserMC/Floodgate/ and https://github.com/GeyserMC/Geyser/ # These settings only work in Bukkit/Spigot/Paper mode +# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!! +# Enabling any of these settings might lead to people gaining unauthorized access to other's accounts! # This enables auto login for every player connecting through Floodgate. # Possible values: false, true, linked # Linked means that only Bedrock accounts linked to a Java account will be logged in automatically # !!! DO NOT REMOVE THE APOSTROPHE !!! +# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!! +# Enabling this might lead to people gaining unauthorized access to other's accounts! autoLoginFloodgate: 'false' # This enables Floodgate players to join the server, even if autoRegister is true and there's an existing @@ -205,14 +209,18 @@ autoLoginFloodgate: 'false' # true: Bypass 'autoRegister's name conflict checking # linked: Bedrock accounts linked to a Java account will be allowed to join with conflicting names # Note: Linking a new account requires players to log in with a non-linked Bedrock account first -# Enabling this will make linking new Bedrock players impossible +# Enabling this without using Floodgate prefixes will make linking new Bedrock players impossible # More information on linking accounts: https://github.com/GeyserMC/Geyser/wiki/Floodgate#account-linking # Releated Floodgate issue: https://github.com/GeyserMC/Floodgate/issues/37 # !!! DO NOT REMOVE THE APOSTROPHE !!! +# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!! +# Enabling this might lead to people gaining unauthorized access to other's accounts! allowFloodgateNameConflict: 'false' # This enables auto registering every player connecting through Floodgate. # autoLoginFloodgate must be 'true' for this to work +# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!! +# Enabling this might lead to people gaining unauthorized access to other's accounts! autoRegisterFloodgate: false # Database configuration From 870d1ee281f5f6369c7c1bda9fca639887d03f02 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Mon, 29 Mar 2021 14:49:33 +0200 Subject: [PATCH 21/36] Migrate to Floodgate v2.0 This removes support for Floodgate 1.x --- bukkit/pom.xml | 14 +++--------- .../bukkit/listener/ConnectionListener.java | 5 +++-- .../listener/protocollib/NameCheckTask.java | 22 +++++++------------ .../bukkit/task/FloodgateAuthTask.java | 8 +++---- 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 47a5b254..df81f519 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -162,19 +162,11 @@ - - - org.geysermc - connector - 1.2.0-SNAPSHOT - provided - - - org.geysermc - floodgate-bukkit - 1.0-SNAPSHOT + org.geysermc.floodgate + api + 2.0-SNAPSHOT provided diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index 358776d2..cc333449 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -13,7 +13,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent.Result; -import org.geysermc.connector.GeyserConnector; +import org.geysermc.floodgate.api.FloodgateApi; import org.bukkit.event.player.PlayerQuitEvent; /** @@ -48,7 +48,8 @@ public class ConnectionListener implements Listener { // having the login session from the login process BukkitLoginSession session = plugin.getSession(player.getAddress()); - if (GeyserConnector.getInstance().getPlayerByUuid(player.getUniqueId()) != null) { + if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate") && + FloodgateApi.getInstance().getPlayer(player.getUniqueId()) != null) { Runnable floodgateAuthTask = new FloodgateAuthTask(plugin, player); Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask); } else if (session == null) { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index d8da3d3c..e2b04a76 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -15,9 +15,8 @@ import java.util.Random; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.common.AuthType; -import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.floodgate.api.FloodgateApi; +import org.geysermc.floodgate.api.player.FloodgatePlayer; public class NameCheckTask extends JoinManagement implements Runnable { @@ -48,7 +47,7 @@ public class NameCheckTask extends JoinManagement Date: Mon, 29 Mar 2021 17:15:45 +0200 Subject: [PATCH 22/36] Update config.yml Added Floodgate 2.0 as a requirement Removed warning about linking accounts with "allowFloodgateNameConflict: 'false'" as it's no longer a problem with Global Linking API enabled --- core/src/main/resources/config.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 5e80280d..5f085e25 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -188,7 +188,7 @@ autoLogin: true # Floodgate configuration # Connecing through Floodgate requires player's to sign in via their Xbox Live account -# Requires https://github.com/GeyserMC/Floodgate/ and https://github.com/GeyserMC/Geyser/ +# Requires Floodgate 2.0 https://github.com/GeyserMC/Floodgate/tree/dev/2.0 # These settings only work in Bukkit/Spigot/Paper mode # !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!! # Enabling any of these settings might lead to people gaining unauthorized access to other's accounts! @@ -208,10 +208,6 @@ autoLoginFloodgate: 'false' # 'autoRegister' must be 'true' for this to work # true: Bypass 'autoRegister's name conflict checking # linked: Bedrock accounts linked to a Java account will be allowed to join with conflicting names -# Note: Linking a new account requires players to log in with a non-linked Bedrock account first -# Enabling this without using Floodgate prefixes will make linking new Bedrock players impossible -# More information on linking accounts: https://github.com/GeyserMC/Geyser/wiki/Floodgate#account-linking -# Releated Floodgate issue: https://github.com/GeyserMC/Floodgate/issues/37 # !!! DO NOT REMOVE THE APOSTROPHE !!! # !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!! # Enabling this might lead to people gaining unauthorized access to other's accounts! From 600f4849630582b1b416783ccb7604ea4a891058 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Tue, 30 Mar 2021 20:00:21 +0200 Subject: [PATCH 23/36] Added function isValidConfigValue() --- .../fastlogin/bukkit/task/FloodgateAuthTask.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java index ae8a85e9..03031c0b 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java @@ -43,9 +43,7 @@ public class FloodgateAuthTask implements Runnable { }); } - if (!allowNameConflict.equalsIgnoreCase("true") - && !allowNameConflict.equalsIgnoreCase("linked") - && !allowNameConflict.equalsIgnoreCase("false")) { + if (!isValidConfigValue(allowNameConflict)) { plugin.getLog().error( "Invalid value detected for 'allowFloodgateNameConflict' in FasttLogin/config.yml. Aborting login of Player {}", player.getName()); @@ -89,5 +87,17 @@ public class FloodgateAuthTask implements Runnable { Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); } + + /** + * Check if a string is a valid configuration option for + * 'allowFloodgateNameConflict' or 'autoLoginFloodgate' + * + * @param value The value of 'allowFloodgateNameConflict' or + * 'autoLoginFloodgate' from config.yml + * @return true if value is "true", "false", or "linked" + */ + boolean isValidConfigValue(String value) { + return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("linked") || value.equalsIgnoreCase("false"); + } } From 9e8a9508d7df512106c337fdc41e674ba4659df4 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Tue, 30 Mar 2021 20:03:09 +0200 Subject: [PATCH 24/36] Re-use FloodgatePlayer in FloodgateAuthTask --- .../fastlogin/bukkit/listener/ConnectionListener.java | 11 +++++++---- .../fastlogin/bukkit/task/FloodgateAuthTask.java | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index cc333449..c1961af7 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -14,6 +14,7 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent.Result; import org.geysermc.floodgate.api.FloodgateApi; +import org.geysermc.floodgate.api.player.FloodgatePlayer; import org.bukkit.event.player.PlayerQuitEvent; /** @@ -48,10 +49,12 @@ public class ConnectionListener implements Listener { // having the login session from the login process BukkitLoginSession session = plugin.getSession(player.getAddress()); - if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate") && - FloodgateApi.getInstance().getPlayer(player.getUniqueId()) != null) { - Runnable floodgateAuthTask = new FloodgateAuthTask(plugin, player); - Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask); + if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate")) { + FloodgatePlayer floodgatePlayer = FloodgateApi.getInstance().getPlayer(player.getUniqueId()); + if (floodgatePlayer != null) { + Runnable floodgateAuthTask = new FloodgateAuthTask(plugin, player, floodgatePlayer); + Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask); + } } else if (session == null) { String sessionId = plugin.getSessionId(player.getAddress()); plugin.getLog().info("No on-going login session for player: {} with ID {}", player, sessionId); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java index 03031c0b..65296f63 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java @@ -2,7 +2,6 @@ package com.github.games647.fastlogin.bukkit.task; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.geysermc.floodgate.api.FloodgateApi; import org.geysermc.floodgate.api.player.FloodgatePlayer; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; @@ -14,15 +13,16 @@ public class FloodgateAuthTask implements Runnable { private final FastLoginBukkit plugin; private final Player player; + private final FloodgatePlayer floodgatePlayer; - public FloodgateAuthTask(FastLoginBukkit plugin, Player player) { + public FloodgateAuthTask(FastLoginBukkit plugin, Player player, FloodgatePlayer floodgatePlayer) { this.plugin = plugin; this.player = player; + this.floodgatePlayer = floodgatePlayer; } @Override public void run() { - FloodgatePlayer floodgatePlayer = FloodgateApi.getInstance().getPlayer(player.getUniqueId()); plugin.getLog().info( "Player {} is connecting through Geyser Floodgate.", player.getName()); From a078bb821456e72dd96a66f76afd26e653bce437 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 11 Apr 2021 10:13:43 +0200 Subject: [PATCH 25/36] Add missing return --- .../github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java | 1 + 1 file changed, 1 insertion(+) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java index 65296f63..163c32f7 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java @@ -41,6 +41,7 @@ public class FloodgateAuthTask implements Runnable { player.kickPlayer("This name is allready in use by a Premium Java Player"); } }); + return; } if (!isValidConfigValue(allowNameConflict)) { From 0d598ad390640394c638e9708475bdfd18dc2daa Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 11 Apr 2021 11:47:56 +0200 Subject: [PATCH 26/36] Moved config value checking Previously the value for "autoLoginFloodgate" and "autoRegisterFloodgate" was checked every time a player joined. Now they are checked at startup. --- .../fastlogin/bukkit/FastLoginBukkit.java | 31 +++++++++++++++++++ .../bukkit/task/FloodgateAuthTask.java | 18 ----------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index eacfdfed..1aa964b7 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -59,6 +59,13 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin + * Writes to Log if the value is invalid. + *

+ * This should be used for: + *

    + *
  • allowFloodgateNameConflict + *
  • autoLoginFloodgate + *
+ *

+ * + * @param key the key of the entry in config.yml + * @return true if the entry's value is "true", "false", or "linked" + */ + private boolean isValidFloodgateConfigString(String key) { + String value = core.getConfig().getString(key); + if (!value.equalsIgnoreCase("true") && !value.equalsIgnoreCase("linked") && !value.equalsIgnoreCase("false")) { + logger.error("Invalid value detected for {} in FastLogin/config.yml.", key); + return false; + } + return true; + + } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java index 163c32f7..73741a52 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java @@ -44,12 +44,6 @@ public class FloodgateAuthTask implements Runnable { return; } - if (!isValidConfigValue(allowNameConflict)) { - plugin.getLog().error( - "Invalid value detected for 'allowFloodgateNameConflict' in FasttLogin/config.yml. Aborting login of Player {}", - player.getName()); - return; - } AuthPlugin authPlugin = plugin.getCore().getAuthPluginHook(); @@ -88,17 +82,5 @@ public class FloodgateAuthTask implements Runnable { Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); } - - /** - * Check if a string is a valid configuration option for - * 'allowFloodgateNameConflict' or 'autoLoginFloodgate' - * - * @param value The value of 'allowFloodgateNameConflict' or - * 'autoLoginFloodgate' from config.yml - * @return true if value is "true", "false", or "linked" - */ - boolean isValidConfigValue(String value) { - return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("linked") || value.equalsIgnoreCase("false"); - } } From 5a263956fe55ddd46fbcef1028a06fda92b6ff96 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Thu, 6 May 2021 11:56:24 +0200 Subject: [PATCH 27/36] Fixed Java auto login/register --- .../bukkit/listener/ConnectionListener.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index c1961af7..facf3469 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -49,19 +49,25 @@ public class ConnectionListener implements Listener { // having the login session from the login process BukkitLoginSession session = plugin.getSession(player.getAddress()); + boolean isFloodgateLogin = false; if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate")) { FloodgatePlayer floodgatePlayer = FloodgateApi.getInstance().getPlayer(player.getUniqueId()); if (floodgatePlayer != null) { + isFloodgateLogin = true; Runnable floodgateAuthTask = new FloodgateAuthTask(plugin, player, floodgatePlayer); Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask); } - } else if (session == null) { - String sessionId = plugin.getSessionId(player.getAddress()); - plugin.getLog().info("No on-going login session for player: {} with ID {}", player, sessionId); - } else { - Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); - Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); - } + } + + if (!isFloodgateLogin) { + if (session == null) { + String sessionId = plugin.getSessionId(player.getAddress()); + plugin.getLog().info("No on-going login session for player: {} with ID {}", player, sessionId); + } else { + Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); + Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); + } + } plugin.getBungeeManager().markJoinEventFired(player); // delay the login process to let auth plugins initialize the player From 85a1abfaac12dbe06eea4700e61189e5e3e60818 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 8 May 2021 13:38:38 +0200 Subject: [PATCH 28/36] Describe how UUIDs work for 'allowFloodgateNameConflict' in config.yml --- core/src/main/resources/config.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 5f085e25..48412665 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -203,6 +203,17 @@ autoLoginFloodgate: 'false' # This enables Floodgate players to join the server, even if autoRegister is true and there's an existing # Java **PREMIUM** account with the same name +# +# Java and Bedrock players will get different UUIDs, so their inventories, location, etc. will be different. +# However, some plugins (such as AuthMe) rely on names instead of UUIDs to identify a player which might cause issues. +# In the case of AuthMe (and other auth plugins), both the Java and the Bedrock player will have the same password. +# +# To prevent conflits from two different players having the same name, it is highly recommended to use a 'username-prefix' +# in floodgate/config.yml +# Note: 'username-prefix' is currently broken when used with FastLogin and ProtocolLib. For more information visit: +# https://github.com/games647/FastLogin/issues/493 +# A solution to this is to replace ProtocolLib with ProtocolSupport +# # Possible values: # false: Check for Premium Java name conflicts as described in 'autoRegister' # 'autoRegister' must be 'true' for this to work From 75750f8417f51270cf995c040c624d944be5305e Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 8 May 2021 14:20:56 +0200 Subject: [PATCH 29/36] Apostrophes are no longer necessary in config.yml --- .../games647/fastlogin/bukkit/FastLoginBukkit.java | 4 ++-- .../bukkit/listener/protocollib/NameCheckTask.java | 2 +- .../fastlogin/bukkit/task/FloodgateAuthTask.java | 10 +++++----- core/src/main/resources/config.yml | 6 ++---- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index 1aa964b7..8ab87493 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -229,8 +229,8 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugintrue if the entry's value is "true", "false", or "linked" */ private boolean isValidFloodgateConfigString(String key) { - String value = core.getConfig().getString(key); - if (!value.equalsIgnoreCase("true") && !value.equalsIgnoreCase("linked") && !value.equalsIgnoreCase("false")) { + String value = core.getConfig().get(key).toString().toLowerCase(); + if (!value.equals("true") && !value.equals("linked") && !value.equals("false")) { logger.error("Invalid value detected for {} in FastLogin/config.yml.", key); return false; } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index e2b04a76..8e66d150 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -46,7 +46,7 @@ public class NameCheckTask extends JoinManagement authPlugin = plugin.getCore().getAuthPluginHook(); - String autoLoginFloodgate = plugin.getCore().getConfig().getString("autoLoginFloodgate"); + String autoLoginFloodgate = plugin.getCore().getConfig().get("autoLoginFloodgate").toString().toLowerCase(); boolean autoRegisterFloodgate = plugin.getCore().getConfig().getBoolean("autoRegisterFloodgate"); boolean isRegistered; @@ -75,8 +75,8 @@ public class FloodgateAuthTask implements Runnable { BukkitLoginSession session = new BukkitLoginSession(player.getName(), isRegistered, profile); // enable auto login based on the value of 'autoLoginFloodgate' in config.yml - session.setVerified(autoLoginFloodgate.equalsIgnoreCase("true") - || (autoLoginFloodgate.equalsIgnoreCase("linked") && isLinked)); + session.setVerified(autoLoginFloodgate.equals("true") + || (autoLoginFloodgate.equals("linked") && isLinked)); // run login task Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 48412665..5b4667d1 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -196,10 +196,9 @@ autoLogin: true # This enables auto login for every player connecting through Floodgate. # Possible values: false, true, linked # Linked means that only Bedrock accounts linked to a Java account will be logged in automatically -# !!! DO NOT REMOVE THE APOSTROPHE !!! # !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!! # Enabling this might lead to people gaining unauthorized access to other's accounts! -autoLoginFloodgate: 'false' +autoLoginFloodgate: false # This enables Floodgate players to join the server, even if autoRegister is true and there's an existing # Java **PREMIUM** account with the same name @@ -219,10 +218,9 @@ autoLoginFloodgate: 'false' # 'autoRegister' must be 'true' for this to work # true: Bypass 'autoRegister's name conflict checking # linked: Bedrock accounts linked to a Java account will be allowed to join with conflicting names -# !!! DO NOT REMOVE THE APOSTROPHE !!! # !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!! # Enabling this might lead to people gaining unauthorized access to other's accounts! -allowFloodgateNameConflict: 'false' +allowFloodgateNameConflict: false # This enables auto registering every player connecting through Floodgate. # autoLoginFloodgate must be 'true' for this to work From d01c368cdbb1cdee16992fb286720813671a56af Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 8 May 2021 14:46:00 +0200 Subject: [PATCH 30/36] Fix identation in bukkit/pom.xml --- bukkit/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bukkit/pom.xml b/bukkit/pom.xml index df81f519..d8c0a69b 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -162,7 +162,7 @@ - + org.geysermc.floodgate api From 25254b2393f79137f9fe119457d1d366beca50f8 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 9 May 2021 09:09:52 +0200 Subject: [PATCH 31/36] Add vscode to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index a67d3fae..29365516 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,9 @@ nb-configuration.xml *.iws .idea/ +# VSCode +.vscode/ + # Maven target/ pom.xml.versionsBackup From b0ef1a59acd37ab44486c9b8640045b24b37c96c Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 9 May 2021 11:01:36 +0200 Subject: [PATCH 32/36] Move Floodgate conflict chechking to core The FloodgateApi is the same for Bukkit and Bungee, so the Floodgate related code could be used in a future Bungee implementation too. Currently, Bungee will report Floodgate disabled to core, so the upstream Floodgate implementation will be used there. If enough code will be moved to core, I might consider enabling these features to BungeeCord too. --- .../listener/protocollib/NameCheckTask.java | 22 +--------- .../ProtocolSupportListener.java | 2 +- bungee/pom.xml | 2 +- .../bungee/task/AsyncPremiumCheck.java | 2 +- core/pom.xml | 14 ++++++ .../fastlogin/core/shared/JoinManagement.java | 43 ++++++++++++++++++- 6 files changed, 61 insertions(+), 24 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index ee6ba69b..4b6c5a21 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -40,8 +40,6 @@ import java.util.Random; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.geysermc.floodgate.api.FloodgateApi; -import org.geysermc.floodgate.api.player.FloodgatePlayer; public class NameCheckTask extends JoinManagement implements Runnable { @@ -70,13 +68,8 @@ public class NameCheckTask extends JoinManagement org.geysermc.floodgate - bungee + api 2.0-SNAPSHOT provided diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/task/AsyncPremiumCheck.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/task/AsyncPremiumCheck.java index 410b1e44..9427ee51 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/task/AsyncPremiumCheck.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/task/AsyncPremiumCheck.java @@ -62,7 +62,7 @@ public class AsyncPremiumCheck extends JoinManagementcodemc-repo https://repo.codemc.io/repository/maven-public/ + + + + nukkitx-snapshot + https://repo.nukkitx.com/maven-snapshots/ + @@ -92,6 +98,14 @@ 0.4 + + + org.geysermc.floodgate + api + 2.0-SNAPSHOT + provided + + com.google.guava 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 e337462c..63b3e4be 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 @@ -33,6 +33,9 @@ import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; import java.util.Optional; +import org.geysermc.floodgate.api.FloodgateApi; +import org.geysermc.floodgate.api.player.FloodgatePlayer; + import net.md_5.bungee.config.Configuration; public abstract class JoinManagement

{ @@ -45,8 +48,28 @@ public abstract class JoinManagement

{ this.authHook = authHook; } - public void onLogin(String username, S source) { + public void onLogin(String username, S source, boolean floodgateAvailable) { core.getPlugin().getLog().info("Handling player {}", username); + + // check if the player is connecting through Geyser + if (floodgateAvailable && getFloodgatePlayer(username) != null) { + if (core.getConfig().get("allowFloodgateNameConflict").toString().equalsIgnoreCase("false")) { + core.getPlugin().getLog().info( + "Bedrock Player {}'s name conflits an existing Java Premium Player's name", + username); + try { + source.kick("Your name conflits an existing Java Premium Player's name"); + } catch (Exception e) { + e.printStackTrace(); + core.getPlugin().getLog().error("Could not kick Player {}", username); + } + } else { + core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); + return; + } + + } + StoredProfile profile = core.getStorage().loadProfile(username); if (profile == null) { return; @@ -130,6 +153,24 @@ public abstract class JoinManagement

{ return false; } + + /** + * Get a FloodgatePlayyer by their name. + * This is not supported by FloodgateApi. + *
+ * WARNING: This method does not check if the floodgate plugin is actually installed on the server! + * @param username the name of the player + * @return FloodgatePlayer if found, null if the player is not online + */ + protected static FloodgatePlayer getFloodgatePlayer(String username) { + // the Floodgate API requires UUID, which is inaccessible at NameCheckTask.java + for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) { + if (floodgatePlayer.getUsername().equals(username)) { + return floodgatePlayer; + } + } + return null; + } public abstract FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, S source, StoredProfile profile); From 5858bfb443edf8b6da00aaccdafbb4c9bca24368 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 9 May 2021 11:10:10 +0200 Subject: [PATCH 33/36] Add Floodgate name conflict check to ProtocolSupport --- .../listener/protocolsupport/ProtocolSupportListener.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java index 3f5a0135..2ee40b8c 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java @@ -37,6 +37,7 @@ import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; import java.net.InetSocketAddress; import java.util.Optional; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -75,7 +76,9 @@ public class ProtocolSupportListener extends JoinManagement Date: Sun, 9 May 2021 11:15:34 +0200 Subject: [PATCH 34/36] Change plugin.yml to softepend on Floodgate 2.0 Rebased to remove Bungee related changes --- bukkit/src/main/resources/plugin.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index 12df4141..146565bd 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -20,9 +20,7 @@ softdepend: - ProtocolLib # Premium variable - PlaceholderAPI - # Floodgate - - floodgate-bukkit - - Geyser-Spigot + - floodgate # Auth plugins - AuthMe - LoginSecurity From b2b61539e13cdc6d2e695bd2519d1171e9e86bdd Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 15 May 2021 11:55:54 +0200 Subject: [PATCH 35/36] Revert "Move Floodgate conflict chechking to core" This reverts commit b0ef1a59acd37ab44486c9b8640045b24b37c96c. --- .../listener/protocollib/NameCheckTask.java | 22 +++++++++- .../ProtocolSupportListener.java | 4 +- bungee/pom.xml | 2 +- .../bungee/task/AsyncPremiumCheck.java | 2 +- core/pom.xml | 14 ------ .../fastlogin/core/shared/JoinManagement.java | 43 +------------------ 6 files changed, 24 insertions(+), 63 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index 4b6c5a21..ee6ba69b 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -40,6 +40,8 @@ import java.util.Random; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.geysermc.floodgate.api.FloodgateApi; +import org.geysermc.floodgate.api.player.FloodgatePlayer; public class NameCheckTask extends JoinManagement implements Runnable { @@ -68,8 +70,13 @@ public class NameCheckTask extends JoinManagement org.geysermc.floodgate - api + bungee 2.0-SNAPSHOT provided diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/task/AsyncPremiumCheck.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/task/AsyncPremiumCheck.java index 9427ee51..410b1e44 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/task/AsyncPremiumCheck.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/task/AsyncPremiumCheck.java @@ -62,7 +62,7 @@ public class AsyncPremiumCheck extends JoinManagementcodemc-repo https://repo.codemc.io/repository/maven-public/ - - - - nukkitx-snapshot - https://repo.nukkitx.com/maven-snapshots/ - @@ -98,14 +92,6 @@ 0.4 - - - org.geysermc.floodgate - api - 2.0-SNAPSHOT - provided - - com.google.guava 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 63b3e4be..e337462c 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 @@ -33,9 +33,6 @@ import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; import java.util.Optional; -import org.geysermc.floodgate.api.FloodgateApi; -import org.geysermc.floodgate.api.player.FloodgatePlayer; - import net.md_5.bungee.config.Configuration; public abstract class JoinManagement

{ @@ -48,28 +45,8 @@ public abstract class JoinManagement

{ this.authHook = authHook; } - public void onLogin(String username, S source, boolean floodgateAvailable) { + public void onLogin(String username, S source) { core.getPlugin().getLog().info("Handling player {}", username); - - // check if the player is connecting through Geyser - if (floodgateAvailable && getFloodgatePlayer(username) != null) { - if (core.getConfig().get("allowFloodgateNameConflict").toString().equalsIgnoreCase("false")) { - core.getPlugin().getLog().info( - "Bedrock Player {}'s name conflits an existing Java Premium Player's name", - username); - try { - source.kick("Your name conflits an existing Java Premium Player's name"); - } catch (Exception e) { - e.printStackTrace(); - core.getPlugin().getLog().error("Could not kick Player {}", username); - } - } else { - core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); - return; - } - - } - StoredProfile profile = core.getStorage().loadProfile(username); if (profile == null) { return; @@ -153,24 +130,6 @@ public abstract class JoinManagement

{ return false; } - - /** - * Get a FloodgatePlayyer by their name. - * This is not supported by FloodgateApi. - *
- * WARNING: This method does not check if the floodgate plugin is actually installed on the server! - * @param username the name of the player - * @return FloodgatePlayer if found, null if the player is not online - */ - protected static FloodgatePlayer getFloodgatePlayer(String username) { - // the Floodgate API requires UUID, which is inaccessible at NameCheckTask.java - for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) { - if (floodgatePlayer.getUsername().equals(username)) { - return floodgatePlayer; - } - } - return null; - } public abstract FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, S source, StoredProfile profile); From d44ab4e634068f1559560af2ee07c2905cdde8fe Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 15 May 2021 14:11:50 +0200 Subject: [PATCH 36/36] Warn when unsupported plugins are detected Floodgate 1.0 does not work with the current Bukkit implementation. ProtocolLib and Floodgate don' play along nicely when used with FastLogin Related issue: #493 --- .../fastlogin/bukkit/FastLoginBukkit.java | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index 32294704..067bd9b6 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -47,10 +47,13 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import org.bukkit.Bukkit; +import org.bukkit.Server.Spigot; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import org.geysermc.floodgate.api.FloodgateApi; import org.slf4j.Logger; /** @@ -138,6 +141,8 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin