mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-31 19:24:47 +02:00
Partially move FloodgateAuthTask to Core
The moved code can be used in a BungeeCord implementation
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,33 @@
|
|||||||
*/
|
*/
|
||||||
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() {
|
public void run() {
|
||||||
plugin.getLog().info(
|
super.run();
|
||||||
"Player {} is connecting through Geyser Floodgate.",
|
|
||||||
player.getName());
|
|
||||||
|
|
||||||
// check if the Bedrock player is linked to a Java account
|
if (!performLogin) {
|
||||||
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;
|
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 +59,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
//variables initialized through run() and accesses by subclasss
|
||||||
|
protected boolean isRegistered;
|
||||||
|
protected StoredProfile profile;
|
||||||
|
protected String autoLoginFloodgate;
|
||||||
|
protected boolean isLinked;
|
||||||
|
protected boolean performLogin; //will be set to ture if core#run() wasn't interrupted by a return;
|
||||||
|
|
||||||
|
public FloodgateManagement(FastLoginCore<P, C, T> core, P player, FloodgatePlayer floodgatePlayer) {
|
||||||
|
this.core = core;
|
||||||
|
this.player = player;
|
||||||
|
this.floodgatePlayer = floodgatePlayer;
|
||||||
|
this.username = getName(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
|
||||||
|
autoLoginFloodgate = core.getConfig().get("autoLoginFloodgate").toString().toLowerCase();
|
||||||
|
String autoRegisterFloodgate = core.getConfig().get("autoRegisterFloodgate").toString().toLowerCase();
|
||||||
|
String allowNameConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase();
|
||||||
|
|
||||||
|
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 (!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 = 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")) {
|
||||||
|
core.getPlugin().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
|
||||||
|
profile = core.getStorage().loadProfile(username);
|
||||||
|
if (profile == null) {
|
||||||
|
profile = new StoredProfile(getUUID(player), username, true, getAddress(player).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
performLogin = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String getName(P player);
|
||||||
|
protected abstract UUID getUUID(P player);
|
||||||
|
protected abstract InetSocketAddress getAddress(P player);
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user