From 2683ec0f9c53bd5e03a4a5aa3c6f8caf3fd2dd77 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 4910e090c..a19fc13f3 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 25e3d00a0..15915cc0a 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.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.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 void onEnable() { } private boolean initializeFloodgate() { + if (getServer().getPluginManager().getPlugin("Geyser-Spigot") != null) { + geyserService = new GeyserService(GeyserConnector.getInstance(), core); + } + if (getServer().getPluginManager().getPlugin("floodgate") != null) { floodgateService = new FloodgateService(FloodgateApi.getInstance(), core); @@ -281,6 +288,11 @@ public FloodgateService getFloodgateService() { return floodgateService; } + @Override + public GeyserService getGeyserService() { + return geyserService; + } + /** * Send warning messages to log if incompatible plugins are used */ diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index 146565bd8..ebe3728d0 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -20,6 +20,8 @@ softdepend: - ProtocolLib # Premium variable - PlaceholderAPI + # Bedrock Player Bridge + - Geyser-Spigot - floodgate # Auth plugins - AuthMe diff --git a/bungee/pom.xml b/bungee/pom.xml index 814d7609c..9670c577e 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -141,6 +141,14 @@ provided + + + 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 0dcd99e73..76547e6a3 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.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.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 void onEnable() { floodgateService = new FloodgateService(FloodgateApi.getInstance(), core); } + if (isPluginInstalled("Geyser-BungeeCord")) { + geyserService = new GeyserService(GeyserConnector.getInstance(), core); + } + //events PluginManager pluginManager = getProxy().getPluginManager(); @@ -197,4 +204,9 @@ public boolean isPluginInstalled(String name) { public FloodgateService getFloodgateService() { return floodgateService; } + + @Override + public GeyserService getGeyserService() { + return geyserService; + } } diff --git a/bungee/src/main/resources/bungee.yml b/bungee/src/main/resources/bungee.yml index c52f41a14..08dcaa631 100644 --- a/bungee/src/main/resources/bungee.yml +++ b/bungee/src/main/resources/bungee.yml @@ -13,6 +13,9 @@ softDepends: - BungeeAuth - BungeeCordAuthenticatorBungee - SodionAuth + # Bedrock Player Bridge + - Geyser-BungeeCord + - floodgate description: | ${project.description} diff --git a/core/pom.xml b/core/pom.xml index fa443e0ca..ee13b0902 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -98,6 +98,14 @@ provided + + + 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 000000000..cba878501 --- /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 aba983a3c..1268a865f 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 @@ 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 @@ default void sendMultiLineMessage(C receiver, String message) { 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 68edf7a05..69ae08991 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 @@ 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 FloodgateService getFloodgateService() { return null; } + @Override + public GeyserService getGeyserService() { + return null; + } + public FastLoginCore getCore() { return core; } From 25bca1c02139020002831a3ac54b85e76818e07d 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 0114c6a48..289fd3582 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 void onLogin(String username, S source) { 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 d219ef46d..7a93d8fa9 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 15915cc0a..c08bc0da2 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.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 f41344bc4..531d2550c 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.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 76547e6a3..83e642b73 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.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 53ee46781..9066647bb 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.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 84d336783..10f82cac8 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.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 000000000..48e181e07 --- /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 7677c1b56..f97b952f7 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 boolean isUsernameForbidden(StoredProfile profile) { 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 cba878501..bca2314b1 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 edad449cd..227dbcff5 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.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 1268a865f..2d53b6c9d 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 69ae08991..543ef67e1 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 bc5e62d9a7037b18cf95952ec8b656e332e4a2c8 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 c08bc0da2..c3171bc0c 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.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 boolean isPluginInstalled(String name) { return Bukkit.getServer().getPluginManager().getPlugin(name) != null; } - @Override public FloodgateService getFloodgateService() { return floodgateService; } - @Override public GeyserService getGeyserService() { return geyserService; } + @Override + public BedrockService 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 531d2550c..760517804 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 @@ private void delayForceLogin(Player player) { 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 289fd3582..76bf5053c 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 9066647bb..58434a90f 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 void onServerConnected(ServerConnectedEvent serverConnectedEvent) { 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 10f82cac8..ecf4165c3 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 @@ private void onSuccessMessage(ProxiedPlayer forPlayer) { 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 f09f1d5f1..3f7419ac6 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 void checkNameConflict(String username, LoginSource source) { } + /** + * 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 f97b952f7..a69c896b3 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 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 boolean isValidFloodgateConfigString(String key) { 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 boolean isUsernameForbidden(StoredProfile profile) { @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 void checkNameConflict(String username, LoginSource source) { * @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 FloodgatePlayer getFloodgatePlayer(String prefixedUsername) { 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 bca2314b1..9b63c9013 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 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 void checkNameConflict(String username, LoginSource source) { } } - /** - * 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 GeyserSession getGeyserPlayer(String username) { 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 227dbcff5..a9b62a719 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.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 void onLogin(String username, S source) { 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 @@ else if (geyserService != null && geyserService.isGeyserConnection(username)) { } 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 2d53b6c9d..1c4eccf21 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 @@ default void sendMultiLineMessage(C receiver, String message) { } } - 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 543ef67e1..a96414599 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 boolean isPluginInstalled(String name) { } @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 7a93d8fa9..3828e2b6f 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 a69c896b3..b962321a9 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 boolean isValidFloodgateConfigString(String key) { @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 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")) { - 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 FloodgatePlayer getBedrockPlayer(String prefixedUsername) { } public FloodgatePlayer getBedrockPlayer(UUID uuid) { - return FloodgateApi.getInstance().getPlayer(uuid); + return floodgate.getPlayer(uuid); } public boolean isBedrockPlayer(UUID uuid) { From ed654548486e35399a07e743995b68f07a850cd5 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 1552151f2..f51bafb55 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 BedrockService(FastLoginCore core) { 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 BedrockService(FastLoginCore core) { * @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 void checkNameConflict(String username, LoginSource source) { 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 b962321a9..f88731f92 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 boolean isUsernameForbidden(StoredProfile profile) { } @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 void checkNameConflict(String username, LoginSource source) { } 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 9b63c9013..0fafddf6f 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 GeyserService(GeyserConnector geyser, FastLoginCore core) { } @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 a9b62a719..3f2835ef8 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 void onLogin(String username, S source) { } //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 d3be15992461a40c3e38fdddd99c98ceb581c401 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 9670c577e..778eb0777 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -123,15 +123,6 @@ provided - - - - org.geysermc - floodgate-bungee - 1.0-SNAPSHOT - provided - - From e4821a324628b130d7763b83159ca794ffa0d20c 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 0fafddf6f..181927e95 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.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 d7cbc5023..94d2b5e77 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 2c933a9c9541f25495849e535c4b083e1f93a1cb 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 63a776546..d66d04a24 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 408bfc92d..cd0eb0765 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)