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 4e0a008c..02cf0862 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 @@ -276,7 +276,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin implements Runnable { @@ -55,6 +52,7 @@ public class NameCheckTask extends JoinManagement authPlugin = plugin.getCore().getAuthPluginHook(); String autoLoginFloodgate = plugin.getCore().getConfig().get("autoLoginFloodgate").toString().toLowerCase(); 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 19c6c56a..e26b2710 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 @@ -50,6 +50,7 @@ import java.util.List; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ThreadFactory; +import net.md_5.bungee.BungeeServerInfo; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.PendingConnection; @@ -187,4 +188,9 @@ public class FastLoginBungee extends Plugin implements PlatformPlugincodemc-repo https://repo.codemc.io/repository/maven-public/ + + + nukkitx-snapshot + https://repo.nukkitx.com/maven-snapshots/ + @@ -85,6 +90,14 @@ + + + org.geysermc.floodgate + api + 2.0-SNAPSHOT + provided + + com.github.games647 diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/FloodgateHook.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/FloodgateHook.java new file mode 100644 index 00000000..fc030325 --- /dev/null +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/FloodgateHook.java @@ -0,0 +1,111 @@ +/* + * 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.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; + +import org.geysermc.floodgate.api.FloodgateApi; +import org.geysermc.floodgate.api.player.FloodgatePlayer; + +public class FloodgateHook

{ + + private final FastLoginCore core; + + public FloodgateHook(FastLoginCore core) { + this.core = core; + } + + /** + * 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 checkFloodgateNameConflict(String username, LoginSource source, FloodgatePlayer floodgatePlayer) { + String allowConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase(); + + // check if the Bedrock player is linked to a Java account + boolean isLinked = ((FloodgatePlayer) floodgatePlayer).getLinkedPlayer() != null; + + if (allowConflict.equals("false") + || allowConflict.equals("linked") && !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 wether Floodgate Player {}'s name conflicts a premium Java player's name.", + username); + try { + source.kick("Could not check if your name conflicts an existing Java Premium Player's name"); + } catch (Exception e1) { + core.getPlugin().getLog().error("Could not kick Player {}", username); + } + } + + if (premiumUUID.isPresent()) { + core.getPlugin().getLog().info("Bedrock Player {}'s name conflicts an existing Java Premium Player's name", + username); + try { + source.kick("Your name conflicts an existing Java Premium Player's name"); + } catch (Exception e) { + core.getPlugin().getLog().error("Could not kick Player {}", username); + } + } + } else { + core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); + } + } + + /** + * The FloodgateApi does not support querying players by name, so this function + * iterates over every online FloodgatePlayer and checks if the requested + * username can be found + * + * @param username the name of the player + * @return FloodgatePlayer if found, null otherwise + */ + public FloodgatePlayer getFloodgatePlayer(String username) { + if (core.getPlugin().isPluginInstalled("floodgate")) { + for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) { + if (floodgatePlayer.getUsername().equals(username)) { + return floodgatePlayer; + } + } + } + return 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 e337462c..ec129a8d 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,20 +29,25 @@ 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.FloodgateHook; import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; import java.util.Optional; +import org.geysermc.floodgate.api.player.FloodgatePlayer; + import net.md_5.bungee.config.Configuration; public abstract class JoinManagement

{ protected final FastLoginCore core; protected final AuthPlugin

authHook; + private final FloodgateHook floodgateHook; public JoinManagement(FastLoginCore core, AuthPlugin

authHook) { this.core = core; this.authHook = authHook; + this.floodgateHook = new FloodgateHook<>(core); } public void onLogin(String username, S source) { @@ -52,6 +57,13 @@ public abstract class JoinManagement

{ return; } + //check if the player is connecting through Floodgate + FloodgatePlayer floodgatePlayer = floodgateHook.getFloodgatePlayer(username); + + if (floodgatePlayer != null) { + floodgateHook.checkFloodgateNameConflict(username, source, floodgatePlayer); + return; + } callFastLoginPreLoginEvent(username, source, profile); Configuration config = core.getConfig(); 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 5761359e..11971e45 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 @@ -45,6 +45,8 @@ public interface PlatformPlugin { AsyncScheduler getScheduler(); + boolean isPluginInstalled(String name); + default void sendMultiLineMessage(C receiver, String message) { for (String line : message.split("%nl%")) { sendMessage(receiver, line);