forked from TuxCoding/FastLogin
Merge pull request #558 from Smart123s/fg-sharedtask
Add Floodgate config options for BungeeCord
This commit is contained in:
@ -79,7 +79,7 @@ public class ConnectionListener implements Listener {
|
|||||||
FloodgatePlayer floodgatePlayer = FloodgateApi.getInstance().getPlayer(player.getUniqueId());
|
FloodgatePlayer floodgatePlayer = FloodgateApi.getInstance().getPlayer(player.getUniqueId());
|
||||||
if (floodgatePlayer != null) {
|
if (floodgatePlayer != null) {
|
||||||
isFloodgateLogin = true;
|
isFloodgateLogin = true;
|
||||||
Runnable floodgateAuthTask = new FloodgateAuthTask(plugin, player, floodgatePlayer);
|
Runnable floodgateAuthTask = new FloodgateAuthTask(plugin.getCore(), player, floodgatePlayer);
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask);
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,94 +25,27 @@
|
|||||||
*/
|
*/
|
||||||
package com.github.games647.fastlogin.bukkit.task;
|
package com.github.games647.fastlogin.bukkit.task;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Optional;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
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.BukkitLoginSession;
|
||||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||||
import com.github.games647.fastlogin.core.StoredProfile;
|
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
import com.github.games647.fastlogin.core.shared.FloodgateManagement;
|
||||||
|
|
||||||
public class FloodgateAuthTask implements Runnable {
|
public class FloodgateAuthTask extends FloodgateManagement<Player, CommandSender, BukkitLoginSession, FastLoginBukkit> {
|
||||||
|
|
||||||
private final FastLoginBukkit plugin;
|
public FloodgateAuthTask(FastLoginCore<Player, CommandSender, FastLoginBukkit> core, Player player, FloodgatePlayer floodgatePlayer) {
|
||||||
private final Player player;
|
super(core, player, floodgatePlayer);
|
||||||
private final FloodgatePlayer floodgatePlayer;
|
|
||||||
|
|
||||||
public FloodgateAuthTask(FastLoginBukkit plugin, Player player, FloodgatePlayer floodgatePlayer) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.player = player;
|
|
||||||
this.floodgatePlayer = floodgatePlayer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
protected void startLogin() {
|
||||||
plugin.getLog().info(
|
|
||||||
"Player {} is connecting through Geyser Floodgate.",
|
|
||||||
player.getName());
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
String autoRegisterFloodgate = plugin.getCore().getConfig().get("autoRegisterFloodgate").toString().toLowerCase();
|
|
||||||
String allowNameConflict = plugin.getCore().getConfig().get("allowFloodgateNameConflict").toString().toLowerCase();
|
|
||||||
|
|
||||||
boolean isRegistered;
|
|
||||||
try {
|
|
||||||
isRegistered = authPlugin.isRegistered(player.getName());
|
|
||||||
} catch (Exception e) {
|
|
||||||
plugin.getLog().error(
|
|
||||||
"An error has occured while checking if player {} is registered",
|
|
||||||
player.getName());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//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) {
|
|
||||||
profile = new StoredProfile(player.getUniqueId(), player.getName(), true, player.getAddress().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
BukkitLoginSession session = new BukkitLoginSession(player.getName(), isRegistered, profile);
|
BukkitLoginSession session = new BukkitLoginSession(player.getName(), isRegistered, profile);
|
||||||
|
|
||||||
// enable auto login based on the value of 'autoLoginFloodgate' in config.yml
|
// enable auto login based on the value of 'autoLoginFloodgate' in config.yml
|
||||||
@ -120,8 +53,20 @@ public class FloodgateAuthTask implements Runnable {
|
|||||||
|| (autoLoginFloodgate.equals("linked") && isLinked));
|
|| (autoLoginFloodgate.equals("linked") && isLinked));
|
||||||
|
|
||||||
// run login task
|
// run login task
|
||||||
Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session);
|
Runnable forceLoginTask = new ForceLoginTask(core.getPlugin().getCore(), player, session);
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask);
|
Bukkit.getScheduler().runTaskAsynchronously(core.getPlugin(), forceLoginTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getName(Player player) {
|
||||||
|
return player.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected UUID getUUID(Player player) {
|
||||||
|
return player.getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InetSocketAddress getAddress(Player player) {
|
||||||
|
return player.getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -86,14 +86,7 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
|
|||||||
//events
|
//events
|
||||||
PluginManager pluginManager = getProxy().getPluginManager();
|
PluginManager pluginManager = getProxy().getPluginManager();
|
||||||
|
|
||||||
//check Floodgate version
|
ConnectListener connectListener = new ConnectListener(this, core.getRateLimiter());
|
||||||
String floodgateVersion = "0";
|
|
||||||
Plugin floodgatePlugin = pluginManager.getPlugin("floodgate");
|
|
||||||
if (floodgatePlugin != null) {
|
|
||||||
floodgateVersion = floodgatePlugin.getDescription().getVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
ConnectListener connectListener = new ConnectListener(this, core.getRateLimiter(), floodgateVersion);
|
|
||||||
|
|
||||||
pluginManager.registerListener(this, connectListener);
|
pluginManager.registerListener(this, connectListener);
|
||||||
pluginManager.registerListener(this, new PluginMessageListener(this));
|
pluginManager.registerListener(this, new PluginMessageListener(this));
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package com.github.games647.fastlogin.bungee.hook.floodgate;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface FloodgateHook {
|
|
||||||
|
|
||||||
boolean isBedrockPlayer(UUID uuid);
|
|
||||||
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package com.github.games647.fastlogin.bungee.hook.floodgate;
|
|
||||||
|
|
||||||
import org.geysermc.floodgate.FloodgateAPI;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class FloodgateV1Hook implements FloodgateHook {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBedrockPlayer(UUID uuid) {
|
|
||||||
return FloodgateAPI.isBedrockPlayer(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package com.github.games647.fastlogin.bungee.hook.floodgate;
|
|
||||||
|
|
||||||
import org.geysermc.floodgate.api.FloodgateApi;
|
|
||||||
import org.geysermc.floodgate.api.InstanceHolder;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class FloodgateV2Hook implements FloodgateHook {
|
|
||||||
|
|
||||||
private FloodgateApi floodgateApi;
|
|
||||||
|
|
||||||
public FloodgateV2Hook() {
|
|
||||||
this.floodgateApi = InstanceHolder.getApi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBedrockPlayer(UUID uuid) {
|
|
||||||
return floodgateApi.isFloodgatePlayer(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -28,10 +28,8 @@ package com.github.games647.fastlogin.bungee.listener;
|
|||||||
import com.github.games647.craftapi.UUIDAdapter;
|
import com.github.games647.craftapi.UUIDAdapter;
|
||||||
import com.github.games647.fastlogin.bungee.BungeeLoginSession;
|
import com.github.games647.fastlogin.bungee.BungeeLoginSession;
|
||||||
import com.github.games647.fastlogin.bungee.FastLoginBungee;
|
import com.github.games647.fastlogin.bungee.FastLoginBungee;
|
||||||
import com.github.games647.fastlogin.bungee.hook.floodgate.FloodgateHook;
|
|
||||||
import com.github.games647.fastlogin.bungee.hook.floodgate.FloodgateV1Hook;
|
|
||||||
import com.github.games647.fastlogin.bungee.hook.floodgate.FloodgateV2Hook;
|
|
||||||
import com.github.games647.fastlogin.bungee.task.AsyncPremiumCheck;
|
import com.github.games647.fastlogin.bungee.task.AsyncPremiumCheck;
|
||||||
|
import com.github.games647.fastlogin.bungee.task.FloodgateAuthTask;
|
||||||
import com.github.games647.fastlogin.bungee.task.ForceLoginTask;
|
import com.github.games647.fastlogin.bungee.task.ForceLoginTask;
|
||||||
import com.github.games647.fastlogin.core.RateLimiter;
|
import com.github.games647.fastlogin.core.RateLimiter;
|
||||||
import com.github.games647.fastlogin.core.StoredProfile;
|
import com.github.games647.fastlogin.core.StoredProfile;
|
||||||
@ -58,6 +56,8 @@ import net.md_5.bungee.connection.LoginResult.Property;
|
|||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
import net.md_5.bungee.event.EventPriority;
|
import net.md_5.bungee.event.EventPriority;
|
||||||
|
|
||||||
|
import org.geysermc.floodgate.api.FloodgateApi;
|
||||||
|
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -96,26 +96,16 @@ public class ConnectListener implements Listener {
|
|||||||
private final FastLoginBungee plugin;
|
private final FastLoginBungee plugin;
|
||||||
private final RateLimiter rateLimiter;
|
private final RateLimiter rateLimiter;
|
||||||
private final Property[] emptyProperties = {};
|
private final Property[] emptyProperties = {};
|
||||||
private final FloodgateHook floodgateHook;
|
|
||||||
|
|
||||||
public ConnectListener(FastLoginBungee plugin, RateLimiter rateLimiter, String floodgateVersion) {
|
public ConnectListener(FastLoginBungee plugin, RateLimiter rateLimiter) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.rateLimiter = rateLimiter;
|
this.rateLimiter = rateLimiter;
|
||||||
|
|
||||||
// Get the appropriate floodgate api hook based on the version
|
|
||||||
if (floodgateVersion.startsWith("1")) {
|
|
||||||
this.floodgateHook = new FloodgateV1Hook();
|
|
||||||
} else if (floodgateVersion.startsWith("2")) {
|
|
||||||
this.floodgateHook = new FloodgateV2Hook();
|
|
||||||
} else {
|
|
||||||
this.floodgateHook = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPreLogin(PreLoginEvent preLoginEvent) {
|
public void onPreLogin(PreLoginEvent preLoginEvent) {
|
||||||
PendingConnection connection = preLoginEvent.getConnection();
|
PendingConnection connection = preLoginEvent.getConnection();
|
||||||
if (preLoginEvent.isCancelled() || isBedrockPlayer(connection.getUniqueId())) {
|
if (preLoginEvent.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,6 +184,15 @@ public class ConnectListener implements Listener {
|
|||||||
ProxiedPlayer player = serverConnectedEvent.getPlayer();
|
ProxiedPlayer player = serverConnectedEvent.getPlayer();
|
||||||
Server server = serverConnectedEvent.getServer();
|
Server server = serverConnectedEvent.getServer();
|
||||||
|
|
||||||
|
if (plugin.isPluginInstalled("floodgate")) {
|
||||||
|
FloodgatePlayer floodgatePlayer = FloodgateApi.getInstance().getPlayer(player.getUniqueId());
|
||||||
|
if (floodgatePlayer != null) {
|
||||||
|
Runnable floodgateAuthTask = new FloodgateAuthTask(plugin.getCore(), player, floodgatePlayer, server);
|
||||||
|
plugin.getScheduler().runAsync(floodgateAuthTask);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BungeeLoginSession session = plugin.getSession().get(player.getPendingConnection());
|
BungeeLoginSession session = plugin.getSession().get(player.getPendingConnection());
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
return;
|
return;
|
||||||
@ -212,16 +211,4 @@ public class ConnectListener implements Listener {
|
|||||||
plugin.getSession().remove(player.getPendingConnection());
|
plugin.getSession().remove(player.getPendingConnection());
|
||||||
plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
|
plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBedrockPlayer(UUID correctedUUID) {
|
|
||||||
// Floodgate will set a correct UUID at the beginning of the PreLoginEvent
|
|
||||||
// and will cancel the online mode login for those players
|
|
||||||
// Therefore we just ignore those
|
|
||||||
if (floodgateHook == null || correctedUUID == null) {
|
|
||||||
// Also ignore if not set by floodgate or any other plugin
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.floodgateHook.isBedrockPlayer(correctedUUID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2021 <Your name and contributors>
|
||||||
|
*
|
||||||
|
* 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.bungee.task;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.connection.Server;
|
||||||
|
|
||||||
|
import com.github.games647.fastlogin.bungee.BungeeLoginSession;
|
||||||
|
import com.github.games647.fastlogin.bungee.FastLoginBungee;
|
||||||
|
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||||
|
import com.github.games647.fastlogin.core.shared.FloodgateManagement;
|
||||||
|
|
||||||
|
public class FloodgateAuthTask
|
||||||
|
extends FloodgateManagement<ProxiedPlayer, CommandSender, BungeeLoginSession, FastLoginBungee> {
|
||||||
|
|
||||||
|
private final Server server;
|
||||||
|
|
||||||
|
public FloodgateAuthTask(FastLoginCore<ProxiedPlayer, CommandSender, FastLoginBungee> core, ProxiedPlayer player,
|
||||||
|
FloodgatePlayer floodgatePlayer, Server server) {
|
||||||
|
super(core, player, floodgatePlayer);
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void startLogin() {
|
||||||
|
BungeeLoginSession session = new BungeeLoginSession(player.getName(), isRegistered, profile);
|
||||||
|
|
||||||
|
// enable auto login based on the value of 'autoLoginFloodgate' in config.yml
|
||||||
|
boolean forcedOnlineMode = autoLoginFloodgate.equals("true")
|
||||||
|
|| (autoLoginFloodgate.equals("linked") && isLinked);
|
||||||
|
|
||||||
|
// run login task
|
||||||
|
Runnable forceLoginTask = new ForceLoginTask(core.getPlugin().getCore(), player, server, session,
|
||||||
|
forcedOnlineMode);
|
||||||
|
core.getPlugin().getScheduler().runAsync(forceLoginTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getName(ProxiedPlayer player) {
|
||||||
|
return player.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected UUID getUUID(ProxiedPlayer player) {
|
||||||
|
return player.getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected InetSocketAddress getAddress(ProxiedPlayer player) {
|
||||||
|
return player.getAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -49,11 +49,21 @@ public class ForceLoginTask
|
|||||||
|
|
||||||
private final Server server;
|
private final Server server;
|
||||||
|
|
||||||
|
//treat player as if they had a premium account, even when they don't
|
||||||
|
//used for Floodgate auto login/register
|
||||||
|
private final boolean forcedOnlineMode;
|
||||||
|
|
||||||
public ForceLoginTask(FastLoginCore<ProxiedPlayer, CommandSender, FastLoginBungee> core,
|
public ForceLoginTask(FastLoginCore<ProxiedPlayer, CommandSender, FastLoginBungee> core,
|
||||||
ProxiedPlayer player, Server server, BungeeLoginSession session) {
|
ProxiedPlayer player, Server server, BungeeLoginSession session, boolean forcedOnlineMode) {
|
||||||
super(core, player, session);
|
super(core, player, session);
|
||||||
|
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
this.forcedOnlineMode = forcedOnlineMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ForceLoginTask(FastLoginCore<ProxiedPlayer, CommandSender, FastLoginBungee> core, ProxiedPlayer player,
|
||||||
|
Server server, BungeeLoginSession session) {
|
||||||
|
this(core, player, server, session, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -116,6 +126,6 @@ public class ForceLoginTask
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnlineMode() {
|
public boolean isOnlineMode() {
|
||||||
return player.getPendingConnection().isOnlineMode();
|
return forcedOnlineMode || player.getPendingConnection().isOnlineMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,149 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2021 <Your name and contributors>
|
||||||
|
*
|
||||||
|
* 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.shared;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
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.core.StoredProfile;
|
||||||
|
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||||
|
|
||||||
|
public abstract class FloodgateManagement<P extends C, C, L extends LoginSession, T extends PlatformPlugin<C>>
|
||||||
|
implements Runnable {
|
||||||
|
|
||||||
|
protected final FastLoginCore<P, C, T> core;
|
||||||
|
protected final P player;
|
||||||
|
private final FloodgatePlayer floodgatePlayer;
|
||||||
|
private final String username;
|
||||||
|
|
||||||
|
//config.yml values that might be accessed by multiple methods
|
||||||
|
protected final String autoLoginFloodgate;
|
||||||
|
protected final String autoRegisterFloodgate;
|
||||||
|
protected final String allowNameConflict;
|
||||||
|
|
||||||
|
//variables initialized through run() and accesses by subclasss
|
||||||
|
protected boolean isRegistered;
|
||||||
|
protected StoredProfile profile;
|
||||||
|
protected boolean isLinked;
|
||||||
|
|
||||||
|
public FloodgateManagement(FastLoginCore<P, C, T> core, P player, FloodgatePlayer floodgatePlayer) {
|
||||||
|
this.core = core;
|
||||||
|
this.player = player;
|
||||||
|
this.floodgatePlayer = floodgatePlayer;
|
||||||
|
this.username = getName(player);
|
||||||
|
|
||||||
|
//load values from config.yml
|
||||||
|
autoLoginFloodgate = core.getConfig().get("autoLoginFloodgate").toString().toLowerCase();
|
||||||
|
autoRegisterFloodgate = core.getConfig().get("autoRegisterFloodgate").toString().toLowerCase();
|
||||||
|
allowNameConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
core.getPlugin().getLog().info(
|
||||||
|
"Player {} is connecting through Geyser Floodgate.",
|
||||||
|
username);
|
||||||
|
|
||||||
|
// check if the Bedrock player is linked to a Java account
|
||||||
|
isLinked = floodgatePlayer.getLinkedPlayer() != null;
|
||||||
|
AuthPlugin<P> authPlugin = core.getAuthPluginHook();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isRegistered = authPlugin.isRegistered(username);
|
||||||
|
} catch (Exception e) {
|
||||||
|
core.getPlugin().getLog().error(
|
||||||
|
"An error has occured while checking if player {} is registered",
|
||||||
|
username);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//decide if checks should be made for conflicting Java player names
|
||||||
|
if (isNameCheckRequired()) {
|
||||||
|
// check for conflicting Premium Java name
|
||||||
|
Optional<Profile> 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 conflits a premium Java player's name.",
|
||||||
|
username);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//stop execution if player's name is conflicting
|
||||||
|
if (premiumUUID.isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isRegistered && autoRegisterFloodgate.equals("false")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//logging in from bedrock for a second time threw an error with UUID
|
||||||
|
profile = core.getStorage().loadProfile(username);
|
||||||
|
if (profile == null) {
|
||||||
|
profile = new StoredProfile(getUUID(player), username, true, getAddress(player).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
//start Bukkit/Bungee specific tasks
|
||||||
|
startLogin();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decides wether checks for conflicting Java names should be made
|
||||||
|
* @return ture if an API call to Mojang is needed
|
||||||
|
*/
|
||||||
|
private boolean isNameCheckRequired() {
|
||||||
|
//linked players have the same name as their Java profile
|
||||||
|
//OR
|
||||||
|
//if allowNameConflict is 'false' or 'linked' and the player had a conflicting
|
||||||
|
//name, than they would have been kicked in FloodgateHook#checkNameConflict
|
||||||
|
if (isLinked || !allowNameConflict.equals("true")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//autoRegisterFloodgate should only be checked if then player is not yet registered
|
||||||
|
if (!isRegistered && autoRegisterFloodgate.equals("no-conflict")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return autoLoginFloodgate.equals("no-conflict");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void startLogin();
|
||||||
|
protected abstract String getName(P player);
|
||||||
|
protected abstract UUID getUUID(P player);
|
||||||
|
protected abstract InetSocketAddress getAddress(P player);
|
||||||
|
|
||||||
|
}
|
@ -190,7 +190,6 @@ autoLogin: true
|
|||||||
# Floodgate configuration
|
# Floodgate configuration
|
||||||
# Connecing through Floodgate requires player's to sign in via their Xbox Live account
|
# Connecing through Floodgate requires player's to sign in via their Xbox Live account
|
||||||
# Requires Floodgate 2.0 https://github.com/GeyserMC/Floodgate/tree/dev/2.0
|
# Requires Floodgate 2.0 https://github.com/GeyserMC/Floodgate/tree/dev/2.0
|
||||||
# These settings only work in Bukkit/Spigot/Paper mode
|
|
||||||
# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
|
# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
|
||||||
# Enabling any of these settings might lead to people gaining unauthorized access to other's accounts!
|
# Enabling any of these settings might lead to people gaining unauthorized access to other's accounts!
|
||||||
|
|
||||||
@ -202,6 +201,7 @@ autoLogin: true
|
|||||||
# no-conflict: Bedrock players will only be automatically logged in if the Mojang API reports
|
# 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.
|
# 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
|
# This option can be useful if you are not using 'username-prefix' in floodgate/config.yml
|
||||||
|
# Requires 'autoLogin' to be 'true'
|
||||||
# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
|
# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
|
||||||
# Enabling this might lead to people gaining unauthorized access to other's accounts!
|
# Enabling this might lead to people gaining unauthorized access to other's accounts!
|
||||||
autoLoginFloodgate: false
|
autoLoginFloodgate: false
|
||||||
@ -237,6 +237,7 @@ allowFloodgateNameConflict: false
|
|||||||
# no-conflict: Bedrock players will only be automatically registered if the Mojang API reports
|
# 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.
|
# 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
|
# This option can be useful if you are not using 'username-prefix' in floodgate/config.yml
|
||||||
|
# Requires 'autoRegister' to be 'true'
|
||||||
# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
|
# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
|
||||||
# Enabling this might lead to people gaining unauthorized access to other's accounts!
|
# Enabling this might lead to people gaining unauthorized access to other's accounts!
|
||||||
autoRegisterFloodgate: false
|
autoRegisterFloodgate: false
|
||||||
|
Reference in New Issue
Block a user