From 3ee6cb2ada52d0dfc3b0aec0e3d8611ef6e2923c Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 23 Oct 2021 10:09:04 +0200 Subject: [PATCH 1/9] Create stub GeyserService The FloodgateService and GeyserService classes are not merged, because Geyser can work without Floodgate. Added Geyser as 'softdepends' in plugin.yml and bungee.yml to make it load before FastLogin. Also made Floodgate a soft dependency in bungee.yml. --- bukkit/pom.xml | 8 ++ .../fastlogin/bukkit/FastLoginBukkit.java | 12 +++ bukkit/src/main/resources/plugin.yml | 2 + bungee/pom.xml | 8 ++ .../fastlogin/bungee/FastLoginBungee.java | 12 +++ bungee/src/main/resources/bungee.yml | 3 + core/pom.xml | 8 ++ .../fastlogin/core/hooks/GeyserService.java | 74 +++++++++++++++++++ .../fastlogin/core/shared/PlatformPlugin.java | 3 + .../fastlogin/velocity/FastLoginVelocity.java | 6 ++ 10 files changed, 136 insertions(+) create mode 100644 core/src/main/java/com/github/games647/fastlogin/core/hooks/GeyserService.java diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 4910e090..a19fc13f 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -209,6 +209,14 @@ provided + + + org.geysermc + connector + 1.4.3-SNAPSHOT + provided + + fr.xephi 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 25e3d00a..15915cc0 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 @@ -36,6 +36,7 @@ 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.FloodgateService; +import com.github.games647.fastlogin.core.hooks.GeyserService; import com.github.games647.fastlogin.core.shared.FastLoginCore; import com.github.games647.fastlogin.core.shared.PlatformPlugin; @@ -53,6 +54,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import org.geysermc.connector.GeyserConnector; import org.geysermc.floodgate.api.FloodgateApi; import org.slf4j.Logger; @@ -71,6 +73,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin core; private FloodgateService floodgateService; + private GeyserService geyserService; private PremiumPlaceholder premiumPlaceholder; @@ -146,6 +149,10 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPluginprovided + + + org.geysermc + connector + 1.4.3-SNAPSHOT + provided + + me.vik1395 diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java index 0dcd99e7..76547e6a 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java @@ -34,6 +34,7 @@ import com.github.games647.fastlogin.core.AsyncScheduler; import com.github.games647.fastlogin.core.CommonUtil; import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.FloodgateService; +import com.github.games647.fastlogin.core.hooks.GeyserService; import com.github.games647.fastlogin.core.message.ChangePremiumMessage; import com.github.games647.fastlogin.core.message.ChannelMessage; import com.github.games647.fastlogin.core.message.NamespaceKey; @@ -60,6 +61,7 @@ import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.PluginManager; import net.md_5.bungee.api.scheduler.GroupedThreadFactory; +import org.geysermc.connector.GeyserConnector; import org.geysermc.floodgate.api.FloodgateApi; import org.slf4j.Logger; @@ -73,6 +75,7 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin core; private AsyncScheduler scheduler; private FloodgateService floodgateService; + private GeyserService geyserService; private Logger logger; @Override @@ -90,6 +93,10 @@ public class FastLoginBungee extends Plugin implements PlatformPluginprovided + + + org.geysermc + connector + 1.4.3-SNAPSHOT + provided + + com.github.games647 diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/GeyserService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/GeyserService.java new file mode 100644 index 00000000..cba87850 --- /dev/null +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/GeyserService.java @@ -0,0 +1,74 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.github.games647.fastlogin.core.hooks; + +import java.util.UUID; + +import com.github.games647.fastlogin.core.shared.FastLoginCore; + +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.network.session.GeyserSession; + +public class GeyserService { + + private final GeyserConnector geyser; + private final FastLoginCore core; + + public GeyserService(GeyserConnector geyser, FastLoginCore core) { + this.geyser = geyser; + this.core = core; + } + + /** + * 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) { + for (GeyserSession gSess : geyser.getSessionManager().getSessions().values()) { + if (gSess.getName().equals(username)) { + return gSess; + } + } + + return null; + } + + public GeyserSession getGeyserPlayer(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/PlatformPlugin.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java index aba983a3..1268a865 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 @@ -27,6 +27,7 @@ package com.github.games647.fastlogin.core.shared; import com.github.games647.fastlogin.core.AsyncScheduler; import com.github.games647.fastlogin.core.hooks.FloodgateService; +import com.github.games647.fastlogin.core.hooks.GeyserService; import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.nio.file.Path; @@ -56,6 +57,8 @@ public interface PlatformPlugin { FloodgateService getFloodgateService(); + GeyserService getGeyserService(); + default ThreadFactory getThreadFactory() { return new ThreadFactoryBuilder() .setNameFormat(getName() + " Pool Thread #%1$d") 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 68edf7a0..69ae0899 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 @@ -27,6 +27,7 @@ package com.github.games647.fastlogin.velocity; import com.github.games647.fastlogin.core.AsyncScheduler; import com.github.games647.fastlogin.core.hooks.FloodgateService; +import com.github.games647.fastlogin.core.hooks.GeyserService; import com.github.games647.fastlogin.core.message.ChangePremiumMessage; import com.github.games647.fastlogin.core.message.ChannelMessage; import com.github.games647.fastlogin.core.message.SuccessMessage; @@ -144,6 +145,11 @@ public class FastLoginVelocity implements PlatformPlugin { return null; } + @Override + public GeyserService getGeyserService() { + return null; + } + public FastLoginCore getCore() { return core; } From f570474fa359a4bdaeff13174e51ebfec0535def Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 24 Oct 2021 10:18:34 +0200 Subject: [PATCH 2/9] Detect Geyser connections at packet level It is possible to use Geyser without Floodgate by configuring Geyser to use auth-type= 'online' or 'offline'. In that scenario, floodgateService will be either unavailable or empty. --- .../bukkit/listener/protocollib/NameCheckTask.java | 2 +- .../protocolsupport/ProtocolSupportListener.java | 3 ++- .../fastlogin/bungee/task/AsyncPremiumCheck.java | 3 ++- .../games647/fastlogin/core/shared/JoinManagement.java | 9 ++++++++- .../fastlogin/velocity/task/AsyncPremiumCheck.java | 3 ++- 5 files changed, 15 insertions(+), 5 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 0114c6a4..289fd358 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 { protected final FastLoginCore core; protected final AuthPlugin

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

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

authHook, FloodgateService floodService, GeyserService geyserService) { this.core = core; this.authHook = authHook; this.floodgateService = floodService; + this.geyserService = geyserService; } public void onLogin(String username, S source) { @@ -63,6 +66,10 @@ public abstract class JoinManagement

{ return; } } + //check if the player is connecting through Geyser (without Floodgate) + else if (geyserService != null && geyserService.isGeyserConnection(username)) { + + } callFastLoginPreLoginEvent(username, source, profile); 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 d219ef46..7a93d8fa 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,7 +50,8 @@ public class AsyncPremiumCheck extends JoinManagement Date: Sun, 24 Oct 2021 14:45:20 +0200 Subject: [PATCH 3/9] Create generalized BedrockService class --- .../fastlogin/bukkit/FastLoginBukkit.java | 4 +- .../bukkit/listener/ConnectionListener.java | 2 +- .../fastlogin/bungee/FastLoginBungee.java | 4 +- .../bungee/listener/ConnectListener.java | 2 +- .../listener/PluginMessageListener.java | 2 +- .../core/hooks/bedrock/BedrockService.java | 82 +++++++++++++++++++ .../hooks/{ => bedrock}/FloodgateService.java | 50 ++--------- .../hooks/{ => bedrock}/GeyserService.java | 16 +++- .../fastlogin/core/shared/JoinManagement.java | 7 +- .../fastlogin/core/shared/PlatformPlugin.java | 4 +- .../fastlogin/velocity/FastLoginVelocity.java | 4 +- 11 files changed, 117 insertions(+), 60 deletions(-) create mode 100644 core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java rename core/src/main/java/com/github/games647/fastlogin/core/hooks/{ => bedrock}/FloodgateService.java (70%) rename core/src/main/java/com/github/games647/fastlogin/core/hooks/{ => bedrock}/GeyserService.java (81%) 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 15915cc0..c08bc0da 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,8 +35,8 @@ 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.FloodgateService; -import com.github.games647.fastlogin.core.hooks.GeyserService; +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; import com.github.games647.fastlogin.core.shared.PlatformPlugin; 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 f41344bc..531d2550 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 @@ -29,7 +29,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 com.github.games647.fastlogin.core.hooks.FloodgateService; +import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java index 76547e6a..83e642b7 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java @@ -33,8 +33,8 @@ import com.github.games647.fastlogin.bungee.listener.PluginMessageListener; import com.github.games647.fastlogin.core.AsyncScheduler; import com.github.games647.fastlogin.core.CommonUtil; import com.github.games647.fastlogin.core.hooks.AuthPlugin; -import com.github.games647.fastlogin.core.hooks.FloodgateService; -import com.github.games647.fastlogin.core.hooks.GeyserService; +import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService; +import com.github.games647.fastlogin.core.hooks.bedrock.GeyserService; import com.github.games647.fastlogin.core.message.ChangePremiumMessage; import com.github.games647.fastlogin.core.message.ChannelMessage; import com.github.games647.fastlogin.core.message.NamespaceKey; 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 53ee4678..9066647b 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 @@ -33,7 +33,7 @@ import com.github.games647.fastlogin.bungee.task.FloodgateAuthTask; import com.github.games647.fastlogin.bungee.task.ForceLoginTask; import com.github.games647.fastlogin.core.RateLimiter; import com.github.games647.fastlogin.core.StoredProfile; -import com.github.games647.fastlogin.core.hooks.FloodgateService; +import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService; import com.github.games647.fastlogin.core.shared.LoginSession; import com.google.common.base.Throwables; 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 84d33678..10f82cac 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 @@ -29,7 +29,7 @@ import com.github.games647.fastlogin.bungee.BungeeLoginSession; import com.github.games647.fastlogin.bungee.FastLoginBungee; import com.github.games647.fastlogin.bungee.task.AsyncToggleMessage; import com.github.games647.fastlogin.core.StoredProfile; -import com.github.games647.fastlogin.core.hooks.FloodgateService; +import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService; import com.github.games647.fastlogin.core.message.ChangePremiumMessage; import com.github.games647.fastlogin.core.message.NamespaceKey; import com.github.games647.fastlogin.core.message.SuccessMessage; diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java new file mode 100644 index 00000000..48e181e0 --- /dev/null +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java @@ -0,0 +1,82 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.github.games647.fastlogin.core.hooks.bedrock; + +import java.io.IOException; +import java.util.Optional; + +import com.github.games647.craftapi.model.Profile; +import com.github.games647.craftapi.resolver.RateLimitException; +import com.github.games647.fastlogin.core.shared.FastLoginCore; +import com.github.games647.fastlogin.core.shared.LoginSource; + +public abstract class BedrockService { + + protected final FastLoginCore core; + protected final String allowConflict; + + public BedrockService(FastLoginCore core) { + this.core = core; + this.allowConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase(); + } + + /** + * Check if the player's name conflicts an existing Java player's name, and kick + * them if it does + * + * @param username the name of the player + * @param source an instance of LoginSource + */ + public void checkNameConflict(String username, LoginSource source) { + // check for conflicting Premium Java name + Optional premiumUUID = Optional.empty(); + try { + premiumUUID = core.getResolver().findProfile(username); + } catch (IOException | RateLimitException e) { + core.getPlugin().getLog().error( + "Could not check whether Bedrock Player {}'s name conflicts a premium Java player's name.", + username); + try { + source.kick("Could not check if your name conflicts an existing premium Java account's name.\n" + + "This is usually a serverside error."); + } catch (Exception ex) { + core.getPlugin().getLog().error("Could not kick Player {}", username, ex); + } + } + + if (premiumUUID.isPresent()) { + core.getPlugin().getLog().info("Bedrock Player {}'s name conflicts an existing premium Java account's name", + username); + try { + source.kick("Your name conflicts an existing premium Java account's name"); + } catch (Exception ex) { + core.getPlugin().getLog().error("Could not kick Player {}", username, ex); + } + } + + } + +} diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/FloodgateService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java similarity index 70% rename from core/src/main/java/com/github/games647/fastlogin/core/hooks/FloodgateService.java rename to core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java index 7677c1b5..f97b952f 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/FloodgateService.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java @@ -23,30 +23,25 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.github.games647.fastlogin.core.hooks; +package com.github.games647.fastlogin.core.hooks.bedrock; -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.shared.FastLoginCore; import com.github.games647.fastlogin.core.shared.LoginSource; -import java.io.IOException; import java.util.Locale; -import java.util.Optional; import java.util.UUID; import org.geysermc.floodgate.api.FloodgateApi; import org.geysermc.floodgate.api.player.FloodgatePlayer; -public class FloodgateService { +public class FloodgateService extends BedrockService { private final FloodgateApi floodgate; - private final FastLoginCore core; public FloodgateService(FloodgateApi floodgate, FastLoginCore core) { + super(core); this.floodgate = floodgate; - this.core = core; } /** @@ -79,48 +74,15 @@ public class FloodgateService { return profile.getName().startsWith(playerPrefix) && !playerPrefix.isEmpty(); } - /** - * Check if the player's name conflicts an existing Java player's name, and - * kick them if it does - * - * @param username the name of the player - * @param source an instance of LoginSource - */ + @Override public void checkNameConflict(String username, LoginSource source) { - String allowConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase(); - // check if the Bedrock player is linked to a Java account FloodgatePlayer floodgatePlayer = getFloodgatePlayer(username); boolean isLinked = floodgatePlayer.getLinkedPlayer() != null; if ("false".equals(allowConflict) - || "linked".equals(allowConflict) && !isLinked) { - - // check for conflicting Premium Java name - Optional premiumUUID = Optional.empty(); - try { - premiumUUID = core.getResolver().findProfile(username); - } catch (IOException | RateLimitException e) { - core.getPlugin().getLog().error( - "Could not check whether Floodgate Player {}'s name conflicts a premium Java player's name.", - username); - try { - source.kick("Could not check if your name conflicts an existing premium Java account's name.\n" - + "This is usually a serverside error."); - } catch (Exception ex) { - core.getPlugin().getLog().error("Could not kick Player {}", username, ex); - } - } - - if (premiumUUID.isPresent()) { - core.getPlugin().getLog().info("Bedrock Player {}'s name conflicts an existing premium Java account's name", - username); - try { - source.kick("Your name conflicts an existing premium Java account's name"); - } catch (Exception ex) { - core.getPlugin().getLog().error("Could not kick Player {}", username, ex); - } - } + || "linked".equals(allowConflict) && !isLinked) { + super.checkNameConflict(username, source); } else { core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/GeyserService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/GeyserService.java similarity index 81% rename from core/src/main/java/com/github/games647/fastlogin/core/hooks/GeyserService.java rename to core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/GeyserService.java index cba87850..bca2314b 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/GeyserService.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/GeyserService.java @@ -23,25 +23,37 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.github.games647.fastlogin.core.hooks; +package com.github.games647.fastlogin.core.hooks.bedrock; import java.util.UUID; import com.github.games647.fastlogin.core.shared.FastLoginCore; +import com.github.games647.fastlogin.core.shared.LoginSource; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; -public class GeyserService { +public class GeyserService extends BedrockService { private final GeyserConnector geyser; private final FastLoginCore core; public GeyserService(GeyserConnector geyser, FastLoginCore core) { + super(core); this.geyser = geyser; this.core = core; } + @Override + public void checkNameConflict(String username, LoginSource source) { + //TODO: Replace stub with Geyser specific code + if ("false".equals(allowConflict)) { + super.checkNameConflict(username, source); + } else { + core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); + } + } + /** * The Geyser API does not support querying players by name, so this function * iterates over every online Geyser Player and checks if the requested 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 edad449c..227dbcff 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,8 @@ 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.FloodgateService; -import com.github.games647.fastlogin.core.hooks.GeyserService; +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.event.FastLoginPreLoginEvent; import java.util.Optional; @@ -44,7 +44,8 @@ public abstract class JoinManagement

{ private final FloodgateService floodgateService; private final GeyserService geyserService; - public JoinManagement(FastLoginCore core, AuthPlugin

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

authHook, FloodgateService floodService, + GeyserService geyserService) { this.core = core; this.authHook = authHook; this.floodgateService = floodService; 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 1268a865..2d53b6c9 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,8 @@ package com.github.games647.fastlogin.core.shared; import com.github.games647.fastlogin.core.AsyncScheduler; -import com.github.games647.fastlogin.core.hooks.FloodgateService; -import com.github.games647.fastlogin.core.hooks.GeyserService; +import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService; +import com.github.games647.fastlogin.core.hooks.bedrock.GeyserService; import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.nio.file.Path; 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 69ae0899..543ef67e 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,8 @@ package com.github.games647.fastlogin.velocity; import com.github.games647.fastlogin.core.AsyncScheduler; -import com.github.games647.fastlogin.core.hooks.FloodgateService; -import com.github.games647.fastlogin.core.hooks.GeyserService; +import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService; +import com.github.games647.fastlogin.core.hooks.bedrock.GeyserService; import com.github.games647.fastlogin.core.message.ChangePremiumMessage; import com.github.games647.fastlogin.core.message.ChannelMessage; import com.github.games647.fastlogin.core.message.SuccessMessage; From fcd2aa95f04ae74e7968cd76110399222110788f Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 24 Oct 2021 15:30:47 +0200 Subject: [PATCH 4/9] Use BedrockService in JoinManagement Since the code only needs to interact with Geyser, if Floodgate is not installed, and perform similar things with both, it's reasonable, to merge their code. This commit breaks premium checking with `auth-type=online` in Geyser --- .../fastlogin/bukkit/FastLoginBukkit.java | 11 ++++- .../bukkit/listener/ConnectionListener.java | 2 +- .../listener/protocollib/NameCheckTask.java | 2 +- .../ProtocolSupportListener.java | 3 +- .../fastlogin/bungee/FastLoginBungee.java | 11 ++++- .../bungee/listener/ConnectListener.java | 2 +- .../listener/PluginMessageListener.java | 2 +- .../bungee/task/AsyncPremiumCheck.java | 3 +- .../core/hooks/bedrock/BedrockService.java | 42 ++++++++++++++++++- .../core/hooks/bedrock/FloodgateService.java | 17 ++++---- .../core/hooks/bedrock/GeyserService.java | 24 +++-------- .../fastlogin/core/shared/JoinManagement.java | 28 +++++-------- .../fastlogin/core/shared/PlatformPlugin.java | 7 +--- .../fastlogin/velocity/FastLoginVelocity.java | 10 +---- .../velocity/task/AsyncPremiumCheck.java | 3 +- 15 files changed, 94 insertions(+), 73 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 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 Date: Sun, 24 Oct 2021 15:32:30 +0200 Subject: [PATCH 5/9] Use local Floodgate instance Shortens code and fixes an unused warning --- .../fastlogin/core/hooks/bedrock/FloodgateService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 a69c896b..b962321a 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 @@ -71,7 +71,7 @@ public class FloodgateService extends BedrockService { @Override public boolean isUsernameForbidden(StoredProfile profile) { - String playerPrefix = FloodgateApi.getInstance().getPlayerPrefix(); + String playerPrefix = floodgate.getPlayerPrefix(); return profile.getName().startsWith(playerPrefix) && !playerPrefix.isEmpty(); } @@ -103,14 +103,14 @@ public class FloodgateService extends BedrockService { //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")) { - for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) { + for (FloodgatePlayer floodgatePlayer : floodgate.getPlayers()) { if (floodgatePlayer.getUsername().equals(prefixedUsername)) { return floodgatePlayer; } } return null; } - for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) { + for (FloodgatePlayer floodgatePlayer : floodgate.getPlayers()) { if (floodgatePlayer.getCorrectUsername().equals(prefixedUsername)) { return floodgatePlayer; } @@ -120,7 +120,7 @@ public class FloodgateService extends BedrockService { } public FloodgatePlayer getBedrockPlayer(UUID uuid) { - return FloodgateApi.getInstance().getPlayer(uuid); + return floodgate.getPlayer(uuid); } public boolean isBedrockPlayer(UUID uuid) { From 2ac638f3f9b3db7d50fb69444da4e277b44dddd3 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 24 Oct 2021 16:23:07 +0200 Subject: [PATCH 6/9] Merge bedrock packet checks into a single function Floodgate and Geyser specific checks can now be modified without changing JoinManagement. Added the ability to resume Java specific checks for Bedrock players. This will be neccessary for Geyser `auth-type=online` players --- .../fastlogin/core/hooks/bedrock/BedrockService.java | 12 ++++++++++-- .../core/hooks/bedrock/FloodgateService.java | 5 ++++- .../fastlogin/core/hooks/bedrock/GeyserService.java | 5 +++-- .../fastlogin/core/shared/JoinManagement.java | 7 +++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java index 1552151f..f51bafb5 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java @@ -48,6 +48,15 @@ public abstract class BedrockService { this.allowConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase(); } + /** + * Perfrom every packet level check needed on a Bedrock player. + * + * @param username the name of the player + * @param source an instance of LoginSource + * @return true if Java specific checks can be skipped + */ + public abstract boolean performChecks(String username, LoginSource source); + /** * Check if the player's name conflicts an existing Java player's name, and kick * them if it does @@ -55,7 +64,7 @@ public abstract class BedrockService { * @param username the name of the player * @param source an instance of LoginSource */ - public void checkNameConflict(String username, LoginSource source) { + protected void checkNameConflict(String username, LoginSource source) { // check for conflicting Premium Java name Optional premiumUUID = Optional.empty(); try { @@ -81,7 +90,6 @@ public abstract class BedrockService { core.getPlugin().getLog().error("Could not kick Player {}", username, ex); } } - } /** 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 b962321a..f88731f9 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 @@ -76,7 +76,7 @@ public class FloodgateService extends BedrockService { } @Override - public void checkNameConflict(String username, LoginSource source) { + public boolean performChecks(String username, LoginSource source) { // check if the Bedrock player is linked to a Java account FloodgatePlayer floodgatePlayer = getBedrockPlayer(username); boolean isLinked = floodgatePlayer.getLinkedPlayer() != null; @@ -87,6 +87,9 @@ public class FloodgateService extends BedrockService { } else { core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); } + + //Floodgate users don't need Java specific checks + return true; } /** 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 9b63c901..0fafddf6 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 @@ -45,13 +45,14 @@ public class GeyserService extends BedrockService { } @Override - public void checkNameConflict(String username, LoginSource source) { - //TODO: Replace stub with Geyser specific code + public boolean performChecks(String username, LoginSource source) { + //TODO: Replace stub with Geyser specific code if ("false".equals(allowConflict)) { super.checkNameConflict(username, source); } else { core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); } + return true; } @Override 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 a9b62a71..3f2835ef 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 @@ -56,10 +56,9 @@ public abstract class JoinManagement

{ } //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 + if (bedrockService != null && bedrockService.isBedrockConnection(username)) { + //perform Bedrock specific checks and skip Java checks, if they are not needed + if (bedrockService.performChecks(username, source)) { return; } } From d0a78329290f7607cb66d41e1214e5a7d7201867 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 24 Oct 2021 16:24:50 +0200 Subject: [PATCH 7/9] Remove unused Floodgate 1.0 dependency --- bungee/pom.xml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/bungee/pom.xml b/bungee/pom.xml index 9670c577..778eb077 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -123,15 +123,6 @@ provided - - - - org.geysermc - floodgate-bungee - 1.0-SNAPSHOT - provided - - From 2f61a8f8adb8495dbe5d104ffc46356777d7481f Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 24 Oct 2021 17:33:34 +0200 Subject: [PATCH 8/9] Add packet level checks for Geyser If AuthType == ONLINE, players will be treated as if they were Java players If AuthType == OFFLINE, name conflicts will be checked the same way it's done with Floodgate Updated config.yml to infrom about the changes. --- .../core/hooks/bedrock/GeyserService.java | 16 ++++++++++++---- core/src/main/resources/config.yml | 15 ++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) 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 0fafddf6..181927e9 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 @@ -31,26 +31,34 @@ import com.github.games647.fastlogin.core.shared.FastLoginCore; import com.github.games647.fastlogin.core.shared.LoginSource; import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.common.AuthType; import org.geysermc.connector.network.session.GeyserSession; public class GeyserService extends BedrockService { private final GeyserConnector geyser; private final FastLoginCore core; + private final AuthType authType; public GeyserService(GeyserConnector geyser, FastLoginCore core) { super(core); this.geyser = geyser; this.core = core; + this.authType = geyser.getConfig().getRemote().getAuthType(); } @Override public boolean performChecks(String username, LoginSource source) { - //TODO: Replace stub with Geyser specific code - if ("false".equals(allowConflict)) { - super.checkNameConflict(username, source); - } else { + // AuthType.FLOODGATE will be handled by FloodgateService + if (authType == AuthType.ONLINE) { + // authenticate everyone, as if they were Java players, since they have signed + // in through Mojang + return false; + } + if ("true".equals(allowConflict)) { core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); + } else { + super.checkNameConflict(username, source); } return true; } diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 1581d4da..8cdcb5d1 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -205,8 +205,8 @@ autoLogin: true # 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 -# Java **PREMIUM** account with the same name +# This enables Floodgate or Offline Geyser players to join the server, even if they are using the name of an +# existing Java **PREMIUM** account (so someone has bought Minecraft with that username) # # 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. @@ -219,12 +219,13 @@ autoLoginFloodgate: false # A solution to this is to replace ProtocolLib with ProtocolSupport # # Possible values: -# false: Check for Premium Java name conflicts as described in 'autoRegister' -# Note: Linked players have the same name as their Java profile, so the Bedrock player will always conflict +# false: Kick Bedrock players, if they are using an existing Premium Java account's name +# Note: Linked Floodgate players have the same name as their Java profile, so the Bedrock player will always conflict # their own Java account's name. Therefore, setting this to false will prevent any linked player from joining. -# true: Bypass 'autoRegister's name conflict checking -# linked: Bedrock accounts linked to a Java account will be allowed to join with conflicting names -# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!! +# true: Bypass name conflict checking. +# linked: Floodgate accounts linked to a Java account will be allowed to join with conflicting names +# For Offline Geyser players, 'linked' works as 'false' +# !!!!!!!! WARNING: FLOODGATE/GEYSER SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!! # Enabling this might lead to people gaining unauthorized access to other's accounts! allowFloodgateNameConflict: false From 909f2631898b5f06bc407c70263f355315c72a34 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Mon, 25 Oct 2021 11:29:40 +0200 Subject: [PATCH 9/9] Update GH Actions to build with Java 16 --- .github/workflows/codeql-analysis.yml | 9 +++++++++ .github/workflows/maven.yml | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 63a77654..d66d04a2 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -35,6 +35,15 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 + # Setup Java + - name: Set up JDK + uses: actions/setup-java@v2.3.0 + with: + distribution: 'adopt' + # Use Java 16, because it's minimum required version by Geyser + java-version: 16 + cache: 'maven' + # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v1 diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 408bfc92..cd0eb076 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -31,8 +31,8 @@ jobs: uses: actions/setup-java@v2.3.0 with: distribution: 'adopt' - # Use Java 11, because it's minimum required version - java-version: 11 + # Use Java 16, because it's minimum required version by Geyser + java-version: 16 cache: 'maven' # Build and test (included in package)