From 2ac638f3f9b3db7d50fb69444da4e277b44dddd3 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 24 Oct 2021 16:23:07 +0200 Subject: [PATCH] Merge bedrock packet checks into a single function Floodgate and Geyser specific checks can now be modified without changing JoinManagement. Added the ability to resume Java specific checks for Bedrock players. This will be neccessary for Geyser `auth-type=online` players --- .../fastlogin/core/hooks/bedrock/BedrockService.java | 12 ++++++++++-- .../core/hooks/bedrock/FloodgateService.java | 5 ++++- .../fastlogin/core/hooks/bedrock/GeyserService.java | 5 +++-- .../fastlogin/core/shared/JoinManagement.java | 7 +++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java index 1552151f..f51bafb5 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java @@ -48,6 +48,15 @@ public abstract class BedrockService { this.allowConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase(); } + /** + * Perfrom every packet level check needed on a Bedrock player. + * + * @param username the name of the player + * @param source an instance of LoginSource + * @return true if Java specific checks can be skipped + */ + public abstract boolean performChecks(String username, LoginSource source); + /** * Check if the player's name conflicts an existing Java player's name, and kick * them if it does @@ -55,7 +64,7 @@ public abstract class BedrockService { * @param username the name of the player * @param source an instance of LoginSource */ - public void checkNameConflict(String username, LoginSource source) { + protected void checkNameConflict(String username, LoginSource source) { // check for conflicting Premium Java name Optional premiumUUID = Optional.empty(); try { @@ -81,7 +90,6 @@ public abstract class BedrockService { core.getPlugin().getLog().error("Could not kick Player {}", username, ex); } } - } /** diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java index b962321a..f88731f9 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java @@ -76,7 +76,7 @@ public class FloodgateService extends BedrockService { } @Override - public void checkNameConflict(String username, LoginSource source) { + public boolean performChecks(String username, LoginSource source) { // check if the Bedrock player is linked to a Java account FloodgatePlayer floodgatePlayer = getBedrockPlayer(username); boolean isLinked = floodgatePlayer.getLinkedPlayer() != null; @@ -87,6 +87,9 @@ public class FloodgateService extends BedrockService { } else { core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); } + + //Floodgate users don't need Java specific checks + return true; } /** diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/GeyserService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/GeyserService.java index 9b63c901..0fafddf6 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/GeyserService.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/GeyserService.java @@ -45,13 +45,14 @@ public class GeyserService extends BedrockService { } @Override - public void checkNameConflict(String username, LoginSource source) { - //TODO: Replace stub with Geyser specific code + public boolean performChecks(String username, LoginSource source) { + //TODO: Replace stub with Geyser specific code if ("false".equals(allowConflict)) { super.checkNameConflict(username, source); } else { core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); } + return true; } @Override diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java index a9b62a71..3f2835ef 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java @@ -56,10 +56,9 @@ public abstract class JoinManagement

{ } //check if the player is connecting through Bedrock Edition - if (bedrockService != null) { - if (bedrockService.isBedrockConnection(username)) { - bedrockService.checkNameConflict(username, source); - // skip flow for any Bedrock player + if (bedrockService != null && bedrockService.isBedrockConnection(username)) { + //perform Bedrock specific checks and skip Java checks, if they are not needed + if (bedrockService.performChecks(username, source)) { return; } }