forked from TuxCoding/FastLogin
Move Floodgate name conflict check to Core
This commit is contained in:
@ -25,72 +25,13 @@
|
||||
*/
|
||||
package com.github.games647.fastlogin.bukkit.hook.floodgate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
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.FastLoginBukkit;
|
||||
import com.github.games647.fastlogin.core.shared.LoginSource;
|
||||
|
||||
public class FloodgateHook {
|
||||
|
||||
private final FastLoginBukkit plugin;
|
||||
|
||||
public FloodgateHook(FastLoginBukkit plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player's name conflicts an existing Java player's name, and
|
||||
* kick them if it does
|
||||
*
|
||||
* @param core the FastLoginCore
|
||||
* @param username the name of the player
|
||||
* @param source an instance of LoginSource
|
||||
* @param plugin the FastLoginBukkit plugin
|
||||
*/
|
||||
public void checkNameConflict(String username, LoginSource source, FloodgatePlayer floodgatePlayer) {
|
||||
String allowConflict = plugin.getCore().getConfig().get("allowFloodgateNameConflict").toString().toLowerCase();
|
||||
|
||||
// check if the Bedrock player is linked to a Java account
|
||||
boolean isLinked = floodgatePlayer.getLinkedPlayer() != null;
|
||||
|
||||
if (allowConflict.equals("false")
|
||||
|| allowConflict.equals("linked") && !isLinked) {
|
||||
|
||||
// check for conflicting Premium Java name
|
||||
Optional<Profile> premiumUUID = Optional.empty();
|
||||
try {
|
||||
premiumUUID = plugin.getCore().getResolver().findProfile(username);
|
||||
} catch (IOException | RateLimitException e) {
|
||||
plugin.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) {
|
||||
plugin.getLog().error("Could not kick Player {}", username);
|
||||
}
|
||||
}
|
||||
|
||||
if (premiumUUID.isPresent()) {
|
||||
plugin.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) {
|
||||
plugin.getLog().error("Could not kick Player {}", username);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
plugin.getLog().info("Skipping name conflict checking for player {}", username);
|
||||
}
|
||||
}
|
||||
public FloodgateHook() { }
|
||||
|
||||
/**
|
||||
* The FloodgateApi does not support querying players by name, so this function
|
||||
|
@ -72,17 +72,7 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ProtocolLibLoginSource source = new ProtocolLibLoginSource(packetEvent, player, random, publicKey);
|
||||
|
||||
//check if the player is connecting through Floodgate
|
||||
FloodgatePlayer floodgatePlayer = floodgateHook.getFloodgatePlayer(username);
|
||||
|
||||
if (floodgatePlayer != null) {
|
||||
floodgateHook.checkNameConflict(username, source, floodgatePlayer);
|
||||
} else {
|
||||
//do Java login tasks
|
||||
super.onLogin(username, source);
|
||||
}
|
||||
super.onLogin(username, new ProtocolLibLoginSource(packetEvent, player, random, publicKey));
|
||||
} finally {
|
||||
ProtocolLibrary.getProtocolManager().getAsynchronousManager().signalPacketTransmission(packetEvent);
|
||||
}
|
||||
@ -127,4 +117,12 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
|
||||
plugin.putSession(player.getAddress(), loginSession);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FloodgatePlayer getFloodgatePlayer(Object id) {
|
||||
if ((id instanceof String)) {
|
||||
return floodgateHook.getFloodgatePlayer((String) id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class ProtocolLibListener extends PacketAdapter {
|
||||
|
||||
this.plugin = plugin;
|
||||
this.rateLimiter = rateLimiter;
|
||||
this.floodgateHook = new FloodgateHook(plugin);
|
||||
this.floodgateHook = new FloodgateHook();
|
||||
}
|
||||
|
||||
public static void register(FastLoginBukkit plugin, RateLimiter rateLimiter) {
|
||||
|
@ -60,7 +60,7 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
|
||||
|
||||
this.plugin = plugin;
|
||||
this.rateLimiter = rateLimiter;
|
||||
this.floodgateHook = new FloodgateHook(plugin);
|
||||
this.floodgateHook = new FloodgateHook();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -81,16 +81,7 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
|
||||
plugin.removeSession(address);
|
||||
|
||||
ProtocolLoginSource source = new ProtocolLoginSource(loginStartEvent);
|
||||
|
||||
//check if the player is connecting through Floodgate
|
||||
FloodgatePlayer floodgatePlayer = floodgateHook.getFloodgatePlayer(username);
|
||||
|
||||
if (floodgatePlayer != null) {
|
||||
floodgateHook.checkNameConflict(username, source, floodgatePlayer);
|
||||
} else {
|
||||
//do Java login tasks
|
||||
super.onLogin(username, source);
|
||||
}
|
||||
super.onLogin(username, source);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -139,4 +130,12 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
|
||||
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
|
||||
plugin.putSession(source.getAddress(), loginSession);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FloodgatePlayer getFloodgatePlayer(Object id) {
|
||||
if ((id instanceof String)) {
|
||||
return floodgateHook.getFloodgatePlayer((String) id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,8 @@
|
||||
*/
|
||||
package com.github.games647.fastlogin.bungee.task;
|
||||
|
||||
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
||||
|
||||
import com.github.games647.fastlogin.bungee.BungeeLoginSession;
|
||||
import com.github.games647.fastlogin.bungee.BungeeLoginSource;
|
||||
import com.github.games647.fastlogin.bungee.FastLoginBungee;
|
||||
@ -89,4 +91,10 @@ public class AsyncPremiumCheck extends JoinManagement<ProxiedPlayer, CommandSend
|
||||
public void startCrackedSession(BungeeLoginSource source, StoredProfile profile, String username) {
|
||||
plugin.getSession().put(source.getConnection(), new BungeeLoginSession(username, false, profile));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FloodgatePlayer getFloodgatePlayer(Object id) {
|
||||
// force disabled for BungeeCord for now
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
13
core/pom.xml
13
core/pom.xml
@ -53,6 +53,11 @@
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<!-- Floodgate -->
|
||||
<repository>
|
||||
<id>nukkitx-snapshot</id>
|
||||
<url>https://repo.nukkitx.com/maven-snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -85,6 +90,14 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!--Floodgate for Xbox Live Authentication-->
|
||||
<dependency>
|
||||
<groupId>org.geysermc.floodgate</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--Common component for contacting the Mojang API-->
|
||||
<dependency>
|
||||
<groupId>com.github.games647</groupId>
|
||||
|
@ -31,8 +31,11 @@ import com.github.games647.fastlogin.core.StoredProfile;
|
||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||
import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
||||
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
||||
@ -52,6 +55,13 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
||||
return;
|
||||
}
|
||||
|
||||
//check if the player is connecting through Floodgate
|
||||
FloodgatePlayer floodgatePlayer = getFloodgatePlayer(username);
|
||||
|
||||
if (floodgatePlayer != null) {
|
||||
checkFloodgateNameConflict(username, source, floodgatePlayer);
|
||||
return;
|
||||
}
|
||||
callFastLoginPreLoginEvent(username, source, profile);
|
||||
|
||||
Configuration config = core.getConfig();
|
||||
@ -131,6 +141,60 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player's name conflicts an existing Java player's name, and
|
||||
* kick them if it does
|
||||
*
|
||||
* @param core the FastLoginCore
|
||||
* @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.getLinkedPlayer() != null;
|
||||
|
||||
if (allowConflict.equals("false")
|
||||
|| allowConflict.equals("linked") && !isLinked) {
|
||||
|
||||
// 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 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player is connecting through Floodgate
|
||||
* @param id UUID for BungeeCord, username for Bukkit
|
||||
* @return true if the player is connecting through Floodgate
|
||||
* <br> null if Floodgate is unavailable
|
||||
*/
|
||||
protected abstract FloodgatePlayer getFloodgatePlayer(Object id);
|
||||
|
||||
public abstract FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, S source, StoredProfile profile);
|
||||
|
||||
public abstract void requestPremiumLogin(S source, StoredProfile profile, String username, boolean registered);
|
||||
|
Reference in New Issue
Block a user