From 55e3531718562c7241565760fa225b20886ad02c Mon Sep 17 00:00:00 2001
From: Smart123s <28480228+Smart123s@users.noreply.github.com>
Date: Thu, 4 Aug 2022 19:55:04 +0200
Subject: [PATCH 1/6] Extract channel from ProtocolLib event
---
bukkit/pom.xml | 4 +--
.../protocollib/ProtocolLibListener.java | 25 +++++++++++++++++++
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/bukkit/pom.xml b/bukkit/pom.xml
index 39ca1f92..0151a804 100644
--- a/bukkit/pom.xml
+++ b/bukkit/pom.xml
@@ -376,8 +376,8 @@
io.netty
netty-transport
${nettyVersion}
- test
-
+ provided
+
io.netty
diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java
index 18322389..f3c4949f 100644
--- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java
+++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java
@@ -30,6 +30,8 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
+import com.comphenix.protocol.injector.PacketFilterManager;
+import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.comphenix.protocol.wrappers.BukkitConverters;
@@ -42,6 +44,7 @@ import com.github.games647.fastlogin.core.antibot.AntiBotService;
import com.github.games647.fastlogin.core.antibot.AntiBotService.Action;
import com.mojang.datafixers.util.Either;
+import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.security.InvalidKeyException;
import java.security.KeyPair;
@@ -58,6 +61,7 @@ import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
+import io.netty.channel.Channel;
import lombok.val;
import org.bukkit.entity.Player;
@@ -67,6 +71,7 @@ import static com.comphenix.protocol.PacketType.Login.Client.START;
public class ProtocolLibListener extends PacketAdapter {
private final FastLoginBukkit plugin;
+ private final PlayerInjectionHandler handler;
//just create a new once on plugin enable. This used for verify token generation
private final SecureRandom random = new SecureRandom();
@@ -85,6 +90,7 @@ public class ProtocolLibListener extends PacketAdapter {
this.plugin = plugin;
this.antiBotService = antiBotService;
this.verifyClientKeys = verifyClientKeys;
+ this.handler = getHandler();
}
public static void register(FastLoginBukkit plugin, AntiBotService antiBotService, boolean verifyClientKeys) {
@@ -254,4 +260,23 @@ public class ProtocolLibListener extends PacketAdapter {
//player.getName() won't work at this state
return profile.getName();
}
+
+ private static PlayerInjectionHandler getHandler() {
+ try {
+ PacketFilterManager manager = (PacketFilterManager) ProtocolLibrary.getProtocolManager();
+ Field f = manager.getClass().getDeclaredField("playerInjectionHandler");
+ f.setAccessible(true);
+ PlayerInjectionHandler handler = (PlayerInjectionHandler) f.get(manager);
+ f.setAccessible(false);
+ return handler;
+ } catch (NoSuchFieldException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private Channel getChannel(Player player) {
+ return handler.getChannel(player);
+ }
}
From bf86042c52f2ac087a6d6ce7f18348c1976254d3 Mon Sep 17 00:00:00 2001
From: Smart123s <28480228+Smart123s@users.noreply.github.com>
Date: Fri, 5 Aug 2022 16:25:38 +0200
Subject: [PATCH 2/6] Disable checkstyle line length for JavaDoc links
GitHub permalinks can easily get longer than 120 characters.
---
checkstyle.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/checkstyle.xml b/checkstyle.xml
index f38f8615..0a882add 100644
--- a/checkstyle.xml
+++ b/checkstyle.xml
@@ -101,6 +101,7 @@
+
From 8571feef6d37f6b73ae42dd3f8dc14dc91e0d9fd Mon Sep 17 00:00:00 2001
From: Smart123s <28480228+Smart123s@users.noreply.github.com>
Date: Fri, 5 Aug 2022 17:03:55 +0200
Subject: [PATCH 3/6] Reimplement skipped Floodgate tasks
Due to a bug in ProtocolLib, Floodgate will never execute some of its tasks if an async listener is registered.
Related: https://github.com/GeyserMC/Floodgate/issues/143
Skipped code: https://github.com/GeyserMC/Floodgate/blob/5d5713ed9e9eeab0f4abdaa9cf5cd8619dc1909b/spigot/src/main/java/org/geysermc/floodgate/addon/data/SpigotDataHandler.java#L121-L175
Fixes #786
Fixes #703
Fixes #689
Fixes #647
---
.../protocollib/ProtocolLibListener.java | 58 ++++++++++++++++++-
1 file changed, 56 insertions(+), 2 deletions(-)
diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java
index f3c4949f..5c345e6c 100644
--- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java
+++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java
@@ -62,8 +62,11 @@ import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandler;
+import io.netty.util.AttributeKey;
import lombok.val;
import org.bukkit.entity.Player;
+import org.geysermc.floodgate.api.player.FloodgatePlayer;
import static com.comphenix.protocol.PacketType.Login.Client.ENCRYPTION_BEGIN;
import static com.comphenix.protocol.PacketType.Login.Client.START;
@@ -115,6 +118,15 @@ public class ProtocolLibListener extends PacketAdapter {
Player sender = packetEvent.getPlayer();
PacketType packetType = packetEvent.getPacketType();
if (packetType == START) {
+
+ if (plugin.getFloodgateService() != null) {
+ boolean success = processFloodgateTasks(packetEvent);
+ // don't continue execution if the player was kicked by Floodgate
+ if (!success) {
+ return;
+ }
+ }
+
PacketContainer packet = packetEvent.getPacket();
InetSocketAddress address = sender.getAddress();
@@ -276,7 +288,49 @@ public class ProtocolLibListener extends PacketAdapter {
}
}
- private Channel getChannel(Player player) {
- return handler.getChannel(player);
+ private FloodgatePlayer getFloodgatePlayer(Player player) {
+ Channel channel = handler.getChannel(player);
+ AttributeKey floodgateAttribute = AttributeKey.valueOf("floodgate-player");
+ return channel.attr(floodgateAttribute).get();
+ }
+
+ /**
+ * Reimplementation of the tasks injected Floodgate in ProtocolLib that are not run due to a bug
+ * @see Issue Floodgate#143
+ * @see Floodgate/SpigotDataHandler
+ * @param packetEvent the PacketEvent that won't be processed by Floodgate
+ * @return false if the player was kicked
+ */
+ private boolean processFloodgateTasks(PacketEvent packetEvent) {
+ PacketContainer packet = packetEvent.getPacket();
+ Player player = packetEvent.getPlayer();
+ FloodgatePlayer floodgatePlayer = getFloodgatePlayer(player);
+ if (floodgatePlayer == null) {
+ return true;
+ }
+
+ // kick the player, if necessary
+ Channel channel = handler.getChannel(packetEvent.getPlayer());
+ AttributeKey kickMessageAttribute = AttributeKey.valueOf("floodgate-kick-message");
+ String kickMessage = channel.attr(kickMessageAttribute).get();
+ if (kickMessage != null) {
+ player.kickPlayer(kickMessage);
+ return false;
+ }
+
+ // add prefix
+ String username = floodgatePlayer.getCorrectUsername();
+ if (packet.getGameProfiles().size() > 0) {
+ packet.getGameProfiles().write(0,
+ new WrappedGameProfile(floodgatePlayer.getCorrectUniqueId(), username));
+ } else {
+ packet.getStrings().write(0, username);
+ }
+
+ // remove real Floodgate data handler
+ ChannelHandler floodgateHandler = channel.pipeline().get("floodgate_data_handler");
+ channel.pipeline().remove(floodgateHandler);
+
+ return true;
}
}
From 61f949cf97a6f939d26733cd10d4b1f7994c0574 Mon Sep 17 00:00:00 2001
From: Smart123s <28480228+Smart123s@users.noreply.github.com>
Date: Fri, 5 Aug 2022 17:17:41 +0200
Subject: [PATCH 4/6] Revert "Fix Floodgate detection for buggy ProtocolLib"
This reverts commit 9978fe69
---
.../core/hooks/bedrock/FloodgateService.java | 12 ------------
1 file changed, 12 deletions(-)
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 9ef8985c..267a0267 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
@@ -99,23 +99,11 @@ public class FloodgateService extends BedrockService {
* The FloodgateApi does not support querying players by name, so this function
* iterates over every online FloodgatePlayer and checks if the requested
* username can be found
- *
- * Falls back to non-prefixed name checks, if ProtocolLib is installed
*
* @param prefixedUsername the name of the player with the prefix appended
* @return FloodgatePlayer if found, null otherwise
*/
public FloodgatePlayer getBedrockPlayer(String prefixedUsername) {
- //prefixes are broken with ProtocolLib, so fall back to name checks without prefixes
- //this should be removed if #493 gets fixed
- if (core.getPlugin().isPluginInstalled("ProtocolLib")) {
- for (FloodgatePlayer floodgatePlayer : floodgate.getPlayers()) {
- if (floodgatePlayer.getUsername().equals(prefixedUsername)) {
- return floodgatePlayer;
- }
- }
- return null;
- }
for (FloodgatePlayer floodgatePlayer : floodgate.getPlayers()) {
if (floodgatePlayer.getCorrectUsername().equals(prefixedUsername)) {
return floodgatePlayer;
From 649ce8cb1aa614768fe2fce44c15cc2886377f9c Mon Sep 17 00:00:00 2001
From: Smart123s <28480228+Smart123s@users.noreply.github.com>
Date: Fri, 5 Aug 2022 18:10:27 +0200
Subject: [PATCH 5/6] Revert "Workaround for Floodgate prefixes with
ProtocolLlib"
This reverts commit 94979a3
This reverts commit e82e7c7
This reverts commit b92911b
This reverts commit 03850ae
This reverts commit 8859ebb
---
.../fastlogin/bukkit/FastLoginBukkit.java | 20 ----
.../protocollib/ManualNameChange.java | 102 ------------------
.../protocollib/ProtocolLibListener.java | 5 -
core/src/main/resources/config.yml | 10 --
4 files changed, 137 deletions(-)
delete mode 100644 bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ManualNameChange.java
diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java
index b2bc397c..bf47eec9 100644
--- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java
+++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java
@@ -30,7 +30,6 @@ import com.github.games647.fastlogin.bukkit.command.CrackedCommand;
import com.github.games647.fastlogin.bukkit.command.PremiumCommand;
import com.github.games647.fastlogin.bukkit.listener.ConnectionListener;
import com.github.games647.fastlogin.bukkit.listener.PaperCacheListener;
-import com.github.games647.fastlogin.bukkit.listener.protocollib.ManualNameChange;
import com.github.games647.fastlogin.bukkit.listener.protocollib.ProtocolLibListener;
import com.github.games647.fastlogin.bukkit.listener.protocollib.SkinApplyListener;
import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener;
@@ -119,10 +118,6 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin
- * This is used as a workaround, because Floodgate fails to inject
- * the prefixes when it's used together with ProtocolLib and FastLogin.
- *
- * For more information visit: ...
- */
-public class ManualNameChange extends PacketAdapter {
-
- private final FloodgateService floodgate;
-
- public ManualNameChange(FastLoginBukkit plugin, FloodgateService floodgate) {
- super(params()
- .plugin(plugin)
- .types(START));
-
- this.plugin = plugin;
- this.floodgate = floodgate;
- }
-
- public static void register(FastLoginBukkit plugin, FloodgateService floodgate) {
- // they will be created with a static builder, because otherwise it will throw a NoClassDefFoundError
- ProtocolLibrary.getProtocolManager()
- .getAsynchronousManager()
- .registerAsyncHandler(new ManualNameChange(plugin, floodgate))
- .start();
- }
-
- @Override
- public void onPacketReceiving(PacketEvent packetEvent) {
- PacketContainer packet = packetEvent.getPacket();
- String username = readUsername(packet);
-
- if (floodgate.getBedrockPlayer(username) == null) {
- //not a Floodgate player, no need to add a prefix
- return;
- }
-
- packet.setMeta("original_name", username);
- String prefixedName = FloodgateApi.getInstance().getPlayerPrefix() + username;
- setUsername(packet, prefixedName);
- }
-
- private void setUsername(PacketContainer packet, String name) {
- if (packet.getGameProfiles().size() > 0) {
- WrappedGameProfile updatedProfile = new WrappedGameProfile(UUID.randomUUID(), name);
- packet.getGameProfiles().write(0, updatedProfile);
- } else {
- packet.getStrings().write(0, name);
- }
- }
-
- private String readUsername(PacketContainer packet) {
- if (packet.getGameProfiles().size() > 0) {
- return packet.getGameProfiles().read(0).getName();
- } else {
- return packet.getStrings().read(0);
- }
- }
-}
diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java
index 5c345e6c..bdc64021 100644
--- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java
+++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java
@@ -219,11 +219,6 @@ public class ProtocolLibListener extends PacketAdapter {
//remove old data every time on a new login in order to keep the session only for one person
plugin.removeSession(player.getAddress());
- if (packetEvent.getPacket().getMeta("original_name").isPresent()) {
- //username has been injected by ManualNameChange.java
- username = (String) packetEvent.getPacket().getMeta("original_name").get();
- }
-
PacketContainer packet = packetEvent.getPacket();
val profileKey = packet.getOptionals(BukkitConverters.getWrappedPublicKeyDataConverter())
.optionRead(0);
diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml
index 8ac92822..5132bb2b 100644
--- a/core/src/main/resources/config.yml
+++ b/core/src/main/resources/config.yml
@@ -236,8 +236,6 @@ autoLoginFloodgate: false
#
# To prevent conflicts from two different players having the same name, it is highly recommended using a
# 'username-prefix' in floodgate/config.yml
-# Note: 'username-prefix' is currently broken when used with FastLogin and ProtocolLib.
-# A solution to this is to enable 'floodgatePrefixWorkaround' below.
#
# Possible values:
# false: Kick Bedrock players, if they are using an existing Premium Java account's name
@@ -264,14 +262,6 @@ allowFloodgateNameConflict: false
# Enabling this might lead to people gaining unauthorized access to other's accounts!
autoRegisterFloodgate: false
-# Make FastLogin inject the Floodgate name prefixes, instead of Floodgate.
-# This can fix prefixes, if you are using Floodgate alongside ProtocolLib.
-# If either of those plugins are not installed, this option will have no effect.
-# For more information visit: https://github.com/games647/FastLogin/issues/493
-# !!!!!!!! WARNING: FLOODGATE SUPPORT IS AN EXPERIMENTAL FEATURE !!!!!!!!
-# Enabling this might lead to people gaining unauthorized access to other's accounts!
-floodgatePrefixWorkaround: false
-
# This option resembles the vanilla configuration option 'enforce-secure-profile' in the 'server.properties' file.
# It verifies if the incoming cryptographic key in the login request from the player is signed by Mojang. This key
# is necessary for servers where you or other in-game players want to verify that a chat message sent and signed by
From c8c4aa522d71c810b810a19160da1a7a9e5ba4ef Mon Sep 17 00:00:00 2001
From: Smart123s <28480228+Smart123s@users.noreply.github.com>
Date: Fri, 5 Aug 2022 18:12:49 +0200
Subject: [PATCH 6/6] Remove Floodgate 1.0 warning
Floodgate 2.0 has been released a long time ago.
---
.../fastlogin/bukkit/FastLoginBukkit.java | 16 ----------------
1 file changed, 16 deletions(-)
diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java
index bf47eec9..63de673b 100644
--- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java
+++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java
@@ -147,8 +147,6 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin