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] 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);
+ }
}