mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 02:37:34 +02:00
Move Floodgate conflict chechking to core
The FloodgateApi is the same for Bukkit and Bungee, so the Floodgate related code could be used in a future Bungee implementation too. Currently, Bungee will report Floodgate disabled to core, so the upstream Floodgate implementation will be used there. If enough code will be moved to core, I might consider enabling these features to BungeeCord too.
This commit is contained in:
@ -40,8 +40,6 @@ import java.util.Random;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.geysermc.floodgate.api.FloodgateApi;
|
|
||||||
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
|
||||||
|
|
||||||
public class NameCheckTask extends JoinManagement<Player, CommandSender, ProtocolLibLoginSource>
|
public class NameCheckTask extends JoinManagement<Player, CommandSender, ProtocolLibLoginSource>
|
||||||
implements Runnable {
|
implements Runnable {
|
||||||
@ -70,13 +68,8 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
// check if the player is connecting through Geyser
|
boolean floodgateAvailable = Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate");
|
||||||
if (!plugin.getCore().getConfig().get("allowFloodgateNameConflict").toString().equalsIgnoreCase("false")
|
super.onLogin(username, new ProtocolLibLoginSource(packetEvent, player, random, publicKey), floodgateAvailable);
|
||||||
&& getFloodgatePlayer(username) != null) {
|
|
||||||
plugin.getLog().info("Skipping name conflict checking for player {}", username);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
super.onLogin(username, new ProtocolLibLoginSource(packetEvent, player, random, publicKey));
|
|
||||||
} finally {
|
} finally {
|
||||||
ProtocolLibrary.getProtocolManager().getAsynchronousManager().signalPacketTransmission(packetEvent);
|
ProtocolLibrary.getProtocolManager().getAsynchronousManager().signalPacketTransmission(packetEvent);
|
||||||
}
|
}
|
||||||
@ -121,15 +114,4 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
|
|||||||
plugin.putSession(player.getAddress(), loginSession);
|
plugin.putSession(player.getAddress(), loginSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FloodgatePlayer getFloodgatePlayer(String username) {
|
|
||||||
if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate")) {
|
|
||||||
// the Floodgate API requires UUID, which is inaccessible at NameCheckTask.java
|
|
||||||
for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) {
|
|
||||||
if (floodgatePlayer.getUsername().equals(username)) {
|
|
||||||
return floodgatePlayer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
|
|||||||
//remove old data every time on a new login in order to keep the session only for one person
|
//remove old data every time on a new login in order to keep the session only for one person
|
||||||
plugin.removeSession(address);
|
plugin.removeSession(address);
|
||||||
|
|
||||||
super.onLogin(username, new ProtocolLoginSource(loginStartEvent));
|
super.onLogin(username, new ProtocolLoginSource(loginStartEvent), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -136,7 +136,7 @@
|
|||||||
<!-- Version 2.0 -->
|
<!-- Version 2.0 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.geysermc.floodgate</groupId>
|
<groupId>org.geysermc.floodgate</groupId>
|
||||||
<artifactId>bungee</artifactId>
|
<artifactId>api</artifactId>
|
||||||
<version>2.0-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -62,7 +62,7 @@ public class AsyncPremiumCheck extends JoinManagement<ProxiedPlayer, CommandSend
|
|||||||
plugin.getSession().remove(connection);
|
plugin.getSession().remove(connection);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
super.onLogin(username, new BungeeLoginSource(connection, preLoginEvent));
|
super.onLogin(username, new BungeeLoginSource(connection, preLoginEvent), false);
|
||||||
} finally {
|
} finally {
|
||||||
preLoginEvent.completeIntent(plugin);
|
preLoginEvent.completeIntent(plugin);
|
||||||
}
|
}
|
||||||
|
14
core/pom.xml
14
core/pom.xml
@ -53,6 +53,12 @@
|
|||||||
<id>codemc-repo</id>
|
<id>codemc-repo</id>
|
||||||
<url>https://repo.codemc.io/repository/maven-public/</url>
|
<url>https://repo.codemc.io/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
|
<!-- Floodgate -->
|
||||||
|
<repository>
|
||||||
|
<id>nukkitx-snapshot</id>
|
||||||
|
<url>https://repo.nukkitx.com/maven-snapshots/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -92,6 +98,14 @@
|
|||||||
<version>0.4</version>
|
<version>0.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--Floodgate for Xbox Live Authentication-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geysermc.floodgate</groupId>
|
||||||
|
<artifactId>api</artifactId>
|
||||||
|
<version>2.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- APIs we can use because they are available in all platforms (Spigot, Bungee) -->
|
<!-- APIs we can use because they are available in all platforms (Spigot, Bungee) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
|
@ -33,6 +33,9 @@ import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.geysermc.floodgate.api.FloodgateApi;
|
||||||
|
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
||||||
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
|
||||||
public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
||||||
@ -45,8 +48,28 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
|||||||
this.authHook = authHook;
|
this.authHook = authHook;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLogin(String username, S source) {
|
public void onLogin(String username, S source, boolean floodgateAvailable) {
|
||||||
core.getPlugin().getLog().info("Handling player {}", username);
|
core.getPlugin().getLog().info("Handling player {}", username);
|
||||||
|
|
||||||
|
// check if the player is connecting through Geyser
|
||||||
|
if (floodgateAvailable && getFloodgatePlayer(username) != null) {
|
||||||
|
if (core.getConfig().get("allowFloodgateNameConflict").toString().equalsIgnoreCase("false")) {
|
||||||
|
core.getPlugin().getLog().info(
|
||||||
|
"Bedrock Player {}'s name conflits an existing Java Premium Player's name",
|
||||||
|
username);
|
||||||
|
try {
|
||||||
|
source.kick("Your name conflits an existing Java Premium Player's name");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
core.getPlugin().getLog().error("Could not kick Player {}", username);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
StoredProfile profile = core.getStorage().loadProfile(username);
|
StoredProfile profile = core.getStorage().loadProfile(username);
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
return;
|
return;
|
||||||
@ -130,6 +153,24 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a FloodgatePlayyer by their name.
|
||||||
|
* This is not supported by FloodgateApi.
|
||||||
|
* <br>
|
||||||
|
* <b>WARNING: This method does not check if the floodgate plugin is actually installed on the server!</b>
|
||||||
|
* @param username the name of the player
|
||||||
|
* @return FloodgatePlayer if found, null if the player is not online
|
||||||
|
*/
|
||||||
|
protected static FloodgatePlayer getFloodgatePlayer(String username) {
|
||||||
|
// the Floodgate API requires UUID, which is inaccessible at NameCheckTask.java
|
||||||
|
for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) {
|
||||||
|
if (floodgatePlayer.getUsername().equals(username)) {
|
||||||
|
return floodgatePlayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, S source, StoredProfile profile);
|
public abstract FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, S source, StoredProfile profile);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user