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

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

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

authHook, FloodgateService floodService, + GeyserService geyserService) { this.core = core; this.authHook = authHook; this.floodgateService = floodService; diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java index 1268a865..2d53b6c9 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java @@ -26,8 +26,8 @@ package com.github.games647.fastlogin.core.shared; import com.github.games647.fastlogin.core.AsyncScheduler; -import com.github.games647.fastlogin.core.hooks.FloodgateService; -import com.github.games647.fastlogin.core.hooks.GeyserService; +import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService; +import com.github.games647.fastlogin.core.hooks.bedrock.GeyserService; import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.nio.file.Path; diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index 69ae0899..543ef67e 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -26,8 +26,8 @@ package com.github.games647.fastlogin.velocity; import com.github.games647.fastlogin.core.AsyncScheduler; -import com.github.games647.fastlogin.core.hooks.FloodgateService; -import com.github.games647.fastlogin.core.hooks.GeyserService; +import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService; +import com.github.games647.fastlogin.core.hooks.bedrock.GeyserService; import com.github.games647.fastlogin.core.message.ChangePremiumMessage; import com.github.games647.fastlogin.core.message.ChannelMessage; import com.github.games647.fastlogin.core.message.SuccessMessage;