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) 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..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,7 +35,9 @@ 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.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; import com.github.games647.fastlogin.core.shared.PlatformPlugin; @@ -53,6 +55,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 +74,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin core; private FloodgateService floodgateService; + private GeyserService geyserService; private PremiumPlaceholder premiumPlaceholder; @@ -146,6 +150,10 @@ 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 f41344bc..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 @@ -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; @@ -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 0114c6a4..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 JoinManagementprovided - - - - org.geysermc - floodgate-bungee - 1.0-SNAPSHOT - provided - - @@ -141,6 +132,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 0dcd99e7..b2a8648f 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,7 +33,9 @@ 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.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.message.ChangePremiumMessage; import com.github.games647.fastlogin.core.message.ChannelMessage; import com.github.games647.fastlogin.core.message.NamespaceKey; @@ -60,6 +62,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 +76,7 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin core; private AsyncScheduler scheduler; private FloodgateService floodgateService; + private GeyserService geyserService; private Logger logger; @Override @@ -90,6 +94,10 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin 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 53ee4678..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 @@ -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; @@ -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 84d33678..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 @@ -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; @@ -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 0c2095fd..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,7 +49,7 @@ public class AsyncPremiumCheck extends JoinManagementprovided + + + org.geysermc + connector + 1.4.3-SNAPSHOT + provided + + com.github.games647 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..f51bafb5 --- /dev/null +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java @@ -0,0 +1,130 @@ +/* + * 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 java.util.UUID; + +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; + +/** + * @param B is an instance of either FloodgatePlayer or GeyserSession + */ +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(); + } + + /** + * 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 + * + * @param username the name of the player + * @param source an instance of LoginSource + */ + protected 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); + } + } + } + + /** + * 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/FloodgateService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java similarity index 58% 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..f88731f9 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; } /** @@ -74,56 +69,27 @@ public class FloodgateService { return true; } + @Override public boolean isUsernameForbidden(StoredProfile profile) { - String playerPrefix = FloodgateApi.getInstance().getPlayerPrefix(); + String playerPrefix = floodgate.getPlayerPrefix(); 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 - */ - public void checkNameConflict(String username, LoginSource source) { - String allowConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase(); - + @Override + public boolean performChecks(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) - || "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); } + + //Floodgate users don't need Java specific checks + return true; } /** @@ -136,18 +102,18 @@ public class FloodgateService { * @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")) { - 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; } @@ -156,15 +122,15 @@ public class FloodgateService { return null; } - public FloodgatePlayer getFloodgatePlayer(UUID uuid) { - return FloodgateApi.getInstance().getPlayer(uuid); + public FloodgatePlayer getBedrockPlayer(UUID uuid) { + return floodgate.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 new file mode 100644 index 00000000..181927e9 --- /dev/null +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/GeyserService.java @@ -0,0 +1,81 @@ +/* + * 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.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.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) { + // 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; + } + + @Override + public GeyserSession getBedrockPlayer(String username) { + for (GeyserSession gSess : geyser.getSessionManager().getSessions().values()) { + if (gSess.getName().equals(username)) { + return gSess; + } + } + + return null; + } + + @Override + public GeyserSession getBedrockPlayer(UUID uuid) { + return geyser.getPlayerByUuid(uuid); + } +} 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 1df6ef71..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 @@ -29,7 +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.FloodgateService; +import com.github.games647.fastlogin.core.hooks.bedrock.BedrockService; import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; import java.util.Optional; @@ -40,12 +40,12 @@ public abstract class JoinManagement

{ protected final FastLoginCore core; protected final AuthPlugin

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

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

authHook, BedrockService bedrockService) { this.core = core; this.authHook = authHook; - this.floodgateService = floodService; + this.bedrockService = bedrockService; } public void onLogin(String username, S source) { @@ -55,11 +55,10 @@ 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 && bedrockService.isBedrockConnection(username)) { + //perform Bedrock specific checks and skip Java checks, if they are not needed + if (bedrockService.performChecks(username, source)) { return; } } @@ -117,7 +116,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 aba983a3..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,7 +26,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.bedrock.BedrockService; import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.nio.file.Path; @@ -54,7 +54,7 @@ public interface PlatformPlugin { } } - FloodgateService getFloodgateService(); + BedrockService getBedrockService(); default ThreadFactory getThreadFactory() { return new ThreadFactoryBuilder() 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 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..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,7 +26,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.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; @@ -140,7 +140,7 @@ public class FastLoginVelocity implements PlatformPlugin { } @Override - public FloodgateService getFloodgateService() { + 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 d219ef46..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,7 +50,7 @@ public class AsyncPremiumCheck extends JoinManagement