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 c08bc0da..c3171bc0 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 @@ -35,6 +35,7 @@ import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSup import com.github.games647.fastlogin.bukkit.task.DelayedAuthHook; import com.github.games647.fastlogin.core.CommonUtil; import com.github.games647.fastlogin.core.PremiumStatus; +import com.github.games647.fastlogin.core.hooks.bedrock.BedrockService; import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService; import com.github.games647.fastlogin.core.hooks.bedrock.GeyserService; import com.github.games647.fastlogin.core.shared.FastLoginCore; @@ -283,16 +284,22 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin getBedrockService() { + if (floodgateService != null) { + return floodgateService; + } + return geyserService; + } + /** * Send warning messages to log if incompatible plugins are used */ 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 531d2550..76051780 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 @@ -82,7 +82,7 @@ public class ConnectionListener implements Listener { BukkitLoginSession session = plugin.getSession(player.getAddress()); FloodgateService floodgateService = plugin.getFloodgateService(); if (floodgateService != null) { - FloodgatePlayer floodgatePlayer = floodgateService.getFloodgatePlayer(player.getUniqueId()); + FloodgatePlayer floodgatePlayer = floodgateService.getBedrockPlayer(player.getUniqueId()); if (floodgatePlayer != null) { Runnable floodgateAuthTask = new FloodgateAuthTask(plugin.getCore(), player, floodgatePlayer); Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask); 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 289fd358..76bf5053 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 @@ -54,7 +54,7 @@ public class NameCheckTask extends JoinManagement getBedrockService() { + if (floodgateService != null) { + return floodgateService; + } + return geyserService; + } } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java index 9066647b..58434a90 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java @@ -186,7 +186,7 @@ public class ConnectListener implements Listener { FloodgateService floodgateService = plugin.getFloodgateService(); if (floodgateService != null) { - FloodgatePlayer floodgatePlayer = floodgateService.getFloodgatePlayer(player.getUniqueId()); + FloodgatePlayer floodgatePlayer = floodgateService.getBedrockPlayer(player.getUniqueId()); if (floodgatePlayer != null) { Runnable floodgateAuthTask = new FloodgateAuthTask(plugin.getCore(), player, floodgatePlayer, server); plugin.getScheduler().runAsync(floodgateAuthTask); diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PluginMessageListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PluginMessageListener.java index 10f82cac..ecf4165c 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PluginMessageListener.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PluginMessageListener.java @@ -121,7 +121,7 @@ public class PluginMessageListener implements Listener { FloodgateService floodgateService = plugin.getFloodgateService(); if (!shouldPersist && floodgateService != null) { // always save floodgate players to lock this username - shouldPersist = floodgateService.isFloodgatePlayer(forPlayer.getUniqueId()); + shouldPersist = floodgateService.isBedrockPlayer(forPlayer.getUniqueId()); } if (shouldPersist) { 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 f09f1d5f..3f7419ac 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 @@ -49,8 +49,7 @@ public class AsyncPremiumCheck extends JoinManagement { protected final FastLoginCore core; protected final String allowConflict; @@ -79,4 +84,39 @@ public abstract class BedrockService { } + /** + * The Floodgate / Geyser API does not support querying players by name, so this function + * iterates over every online Bedrock Player and checks if the requested + * username can be found + *
+ * Falls back to non-prefixed name checks, if ProtocolLib is installed + * + * @param prefixedUsername the name of the player with the prefix appended + * @return Bedrock Player if found, null otherwise + */ + public B getBedrockPlayer(String prefixedUsername) { + return null; + } + + public B getBedrockPlayer(UUID uuid) { + return null; + } + + public boolean isBedrockPlayer(UUID uuid) { + return getBedrockPlayer(uuid) != null; + } + + public boolean isBedrockConnection(String username) { + return getBedrockPlayer(username) != null; + } + + /** + * Checks if a profile's name starts with the Floodgate prefix, if it's available + * @param profile profile of the conecting player + * @return true if the username is forbidden + */ + public boolean isUsernameForbidden(StoredProfile profile) { + return false; + } + } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java index f97b952f..a69c896b 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java @@ -35,7 +35,7 @@ import java.util.UUID; import org.geysermc.floodgate.api.FloodgateApi; import org.geysermc.floodgate.api.player.FloodgatePlayer; -public class FloodgateService extends BedrockService { +public class FloodgateService extends BedrockService { private final FloodgateApi floodgate; @@ -69,6 +69,7 @@ public class FloodgateService extends BedrockService { return true; } + @Override public boolean isUsernameForbidden(StoredProfile profile) { String playerPrefix = FloodgateApi.getInstance().getPlayerPrefix(); return profile.getName().startsWith(playerPrefix) && !playerPrefix.isEmpty(); @@ -77,7 +78,7 @@ public class FloodgateService extends BedrockService { @Override public void checkNameConflict(String username, LoginSource source) { // check if the Bedrock player is linked to a Java account - FloodgatePlayer floodgatePlayer = getFloodgatePlayer(username); + FloodgatePlayer floodgatePlayer = getBedrockPlayer(username); boolean isLinked = floodgatePlayer.getLinkedPlayer() != null; if ("false".equals(allowConflict) @@ -98,7 +99,7 @@ public class FloodgateService extends BedrockService { * @param prefixedUsername the name of the player with the prefix appended * @return FloodgatePlayer if found, null otherwise */ - public FloodgatePlayer getFloodgatePlayer(String prefixedUsername) { + public FloodgatePlayer getBedrockPlayer(String prefixedUsername) { //prefixes are broken with ProtocolLib, so fall back to name checks without prefixes //this should be removed if #493 gets fixed if (core.getPlugin().isPluginInstalled("ProtocolLib")) { @@ -118,15 +119,15 @@ public class FloodgateService extends BedrockService { return null; } - public FloodgatePlayer getFloodgatePlayer(UUID uuid) { + public FloodgatePlayer getBedrockPlayer(UUID uuid) { return FloodgateApi.getInstance().getPlayer(uuid); } - public boolean isFloodgatePlayer(UUID uuid) { - return getFloodgatePlayer(uuid) != null; + public boolean isBedrockPlayer(UUID uuid) { + return getBedrockPlayer(uuid) != null; } - public boolean isFloodgateConnection(String username) { - return getFloodgatePlayer(username) != null; + public boolean isBedrockConnection(String username) { + return getBedrockPlayer(username) != null; } } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/GeyserService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/GeyserService.java index bca2314b..9b63c901 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/GeyserService.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/GeyserService.java @@ -33,7 +33,7 @@ import com.github.games647.fastlogin.core.shared.LoginSource; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; -public class GeyserService extends BedrockService { +public class GeyserService extends BedrockService { private final GeyserConnector geyser; private final FastLoginCore core; @@ -54,15 +54,8 @@ public class GeyserService extends BedrockService { } } - /** - * The Geyser API does not support querying players by name, so this function - * iterates over every online Geyser Player and checks if the requested - * username can be found - * - * @param username the name of the player - * @return GeyserSession if found, null otherwise - */ - public GeyserSession getGeyserPlayer(String username) { + @Override + public GeyserSession getBedrockPlayer(String username) { for (GeyserSession gSess : geyser.getSessionManager().getSessions().values()) { if (gSess.getName().equals(username)) { return gSess; @@ -72,15 +65,8 @@ public class GeyserService extends BedrockService { return null; } - public GeyserSession getGeyserPlayer(UUID uuid) { + @Override + public GeyserSession getBedrockPlayer(UUID uuid) { return geyser.getPlayerByUuid(uuid); } - - public boolean isGeyserPlayer(UUID uuid) { - return getGeyserPlayer(uuid) != null; - } - - public boolean isGeyserConnection(String username) { - return getGeyserPlayer(username) != null; - } } 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 227dbcff..a9b62a71 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 @@ -29,8 +29,7 @@ import com.github.games647.craftapi.model.Profile; import com.github.games647.craftapi.resolver.RateLimitException; import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.hooks.AuthPlugin; -import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService; -import com.github.games647.fastlogin.core.hooks.bedrock.GeyserService; +import com.github.games647.fastlogin.core.hooks.bedrock.BedrockService; import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; import java.util.Optional; @@ -41,15 +40,12 @@ public abstract class JoinManagement

{ protected final FastLoginCore core; protected final AuthPlugin

authHook; - private final FloodgateService floodgateService; - private final GeyserService geyserService; + private final BedrockService bedrockService; - public JoinManagement(FastLoginCore core, AuthPlugin

authHook, FloodgateService floodService, - GeyserService geyserService) { + public JoinManagement(FastLoginCore core, AuthPlugin

authHook, BedrockService bedrockService) { this.core = core; this.authHook = authHook; - this.floodgateService = floodService; - this.geyserService = geyserService; + this.bedrockService = bedrockService; } public void onLogin(String username, S source) { @@ -59,18 +55,14 @@ public abstract class JoinManagement

{ return; } - //check if the player is connecting through Floodgate - if (floodgateService != null) { - if (floodgateService.isFloodgateConnection(username)) { - floodgateService.checkNameConflict(username, source); - // skip flow for any floodgate player + //check if the player is connecting through Bedrock Edition + if (bedrockService != null) { + if (bedrockService.isBedrockConnection(username)) { + bedrockService.checkNameConflict(username, source); + // skip flow for any Bedrock player return; } } - //check if the player is connecting through Geyser (without Floodgate) - else if (geyserService != null && geyserService.isGeyserConnection(username)) { - - } callFastLoginPreLoginEvent(username, source, profile); @@ -125,7 +117,7 @@ public abstract class JoinManagement

{ } protected boolean isValidUsername(LoginSource source, StoredProfile profile) throws Exception { - if (floodgateService != null && floodgateService.isUsernameForbidden(profile)) { + if (bedrockService != null && bedrockService.isUsernameForbidden(profile)) { core.getPlugin().getLog().info("Floodgate Prefix detected on cracked player"); source.kick("Your username contains illegal characters"); return false; diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java index 2d53b6c9..1c4eccf2 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java @@ -26,8 +26,7 @@ package com.github.games647.fastlogin.core.shared; import com.github.games647.fastlogin.core.AsyncScheduler; -import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService; -import com.github.games647.fastlogin.core.hooks.bedrock.GeyserService; +import com.github.games647.fastlogin.core.hooks.bedrock.BedrockService; import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.nio.file.Path; @@ -55,9 +54,7 @@ public interface PlatformPlugin { } } - FloodgateService getFloodgateService(); - - GeyserService getGeyserService(); + BedrockService getBedrockService(); default ThreadFactory getThreadFactory() { return new ThreadFactoryBuilder() diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index 543ef67e..a9641459 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -26,8 +26,7 @@ package com.github.games647.fastlogin.velocity; import com.github.games647.fastlogin.core.AsyncScheduler; -import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService; -import com.github.games647.fastlogin.core.hooks.bedrock.GeyserService; +import com.github.games647.fastlogin.core.hooks.bedrock.BedrockService; import com.github.games647.fastlogin.core.message.ChangePremiumMessage; import com.github.games647.fastlogin.core.message.ChannelMessage; import com.github.games647.fastlogin.core.message.SuccessMessage; @@ -141,12 +140,7 @@ public class FastLoginVelocity implements PlatformPlugin { } @Override - public FloodgateService getFloodgateService() { - return null; - } - - @Override - public GeyserService getGeyserService() { + public BedrockService getBedrockService() { return null; } diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java index 7a93d8fa..3828e2b6 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java @@ -50,8 +50,7 @@ public class AsyncPremiumCheck extends JoinManagement