Merge pull request #533 from Smart123s/fg-bk-nonconfict

Add 'no-conflict' option to some Floodgate config entries
This commit is contained in:
games647
2021-06-15 11:30:06 +02:00
committed by GitHub
4 changed files with 55 additions and 13 deletions

View File

@ -256,6 +256,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
* <ul>
* <li>allowFloodgateNameConflict
* <li>autoLoginFloodgate
* <li>autoRegisterFloodgate
* </ul>
* </p>
*
@ -264,7 +265,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
*/
private boolean isValidFloodgateConfigString(String key) {
String value = core.getConfig().get(key).toString().toLowerCase();
if (!value.equals("true") && !value.equals("linked") && !value.equals("false")) {
if (!value.equals("true") && !value.equals("linked") && !value.equals("false") && !value.equals("no-conflict")) {
logger.error("Invalid value detected for {} in FastLogin/config.yml.", key);
return false;
}

View File

@ -25,10 +25,15 @@
*/
package com.github.games647.fastlogin.bukkit.task;
import java.io.IOException;
import java.util.Optional;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
import com.github.games647.craftapi.model.Profile;
import com.github.games647.craftapi.resolver.RateLimitException;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.StoredProfile;
@ -54,11 +59,11 @@ public class FloodgateAuthTask implements Runnable {
// check if the Bedrock player is linked to a Java account
boolean isLinked = floodgatePlayer.getLinkedPlayer() != null;
AuthPlugin<Player> authPlugin = plugin.getCore().getAuthPluginHook();
String autoLoginFloodgate = plugin.getCore().getConfig().get("autoLoginFloodgate").toString().toLowerCase();
boolean autoRegisterFloodgate = plugin.getCore().getConfig().getBoolean("autoRegisterFloodgate");
String autoRegisterFloodgate = plugin.getCore().getConfig().get("autoRegisterFloodgate").toString().toLowerCase();
String allowNameConflict = plugin.getCore().getConfig().get("allowFloodgateNameConflict").toString().toLowerCase();
boolean isRegistered;
try {
@ -69,13 +74,39 @@ public class FloodgateAuthTask implements Runnable {
player.getName());
return;
}
if (!isRegistered && !autoRegisterFloodgate) {
//decide if checks should be made for conflicting Java player names
if (!isLinked //linked players have the same name as their Java profile
// if allowNameConflict is 'false' or 'linked' and the player had a conflicting
// name, than they would have been kicked in FloodgateHook#checkNameConflict
&& allowNameConflict.equals("true") &&
(
autoLoginFloodgate.equals("no-conflict")
|| !isRegistered && autoRegisterFloodgate.equals("no-conflict"))
) {
// check for conflicting Premium Java name
Optional<Profile> premiumUUID = Optional.empty();
try {
premiumUUID = plugin.getCore().getResolver().findProfile(player.getName());
} catch (IOException | RateLimitException e) {
plugin.getLog().error(
"Could not check wether Floodgate Player {}'s name conflits a premium Java player's name.",
player.getName());
return;
}
//stop execution if player's name is conflicting
if (premiumUUID.isPresent()) {
return;
}
}
if (!isRegistered && autoRegisterFloodgate.equals("false")) {
plugin.getLog().info(
"Auto registration is disabled for Floodgate players in config.yml");
return;
}
// logging in from bedrock for a second time threw an error with UUID
StoredProfile profile = plugin.getCore().getStorage().loadProfile(player.getName());
if (profile == null) {
@ -83,7 +114,7 @@ public class FloodgateAuthTask implements Runnable {
}
BukkitLoginSession session = new BukkitLoginSession(player.getName(), isRegistered, profile);
// enable auto login based on the value of 'autoLoginFloodgate' in config.yml
session.setVerified(autoLoginFloodgate.equals("true")
|| (autoLoginFloodgate.equals("linked") && isLinked));

View File

@ -50,7 +50,6 @@ 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;

View File

@ -194,9 +194,14 @@ autoLogin: true
# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
# Enabling any of these settings might lead to people gaining unauthorized access to other's accounts!
# This enables auto login for every player connecting through Floodgate.
# Possible values: false, true, linked
# Linked means that only Bedrock accounts linked to a Java account will be logged in automatically
# Automatically log in players connecting through Floodgate.
# Possible values:
# false: Disables auto login for every player connecting through Floodgate
# true: Enables auto login for every player connecting through Floodgate
# linked: Only Bedrock accounts that are linked to a Java account will be logged in automatically
# no-conflict: Bedrock players will only be automatically logged in if the Mojang API reports
# that there is no existing Premium Java MC account with their name.
# This option can be useful if you are not using 'username-prefix' in floodgate/config.yml
# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
# Enabling this might lead to people gaining unauthorized access to other's accounts!
autoLoginFloodgate: false
@ -225,8 +230,14 @@ autoLoginFloodgate: false
# Enabling this might lead to people gaining unauthorized access to other's accounts!
allowFloodgateNameConflict: false
# This enables auto registering every player connecting through Floodgate.
# autoLoginFloodgate must be 'true' for this to work
# Automatically register players connecting through Floodgate.
# autoLoginFloodgate must be available for the player to use this
# Possible values:
# false: Disables auto registering for every player connecting through Floodgate
# true: Enables auto registering for every player connecting through Floodgate
# no-conflict: Bedrock players will only be automatically registered if the Mojang API reports
# that there is no existing Premium Java MC account with their name.
# This option can be useful if you are not using 'username-prefix' in floodgate/config.yml
# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
# Enabling this might lead to people gaining unauthorized access to other's accounts!
autoRegisterFloodgate: false