From 1f4757669c282833506c26866abfbec6355e51db Mon Sep 17 00:00:00 2001 From: games647 Date: Tue, 22 Jun 2021 11:15:21 +0200 Subject: [PATCH] Allow packet modifications by other plugins If we disable filters, other plugins are advised to only monitor packets. Potential modifications can be allowed by enabling the filtering again, but adding our meta data to prevent duplicate processing. --- .../bukkit/listener/protocollib/ProtocolLibListener.java | 7 +++++++ .../bukkit/listener/protocollib/VerifyResponseTask.java | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) 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 383afff3..47018615 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 @@ -43,6 +43,8 @@ import static com.comphenix.protocol.PacketType.Login.Client.START; public class ProtocolLibListener extends PacketAdapter { + public static final String SOURCE_META_KEY = "source"; + private final FastLoginBukkit plugin; //just create a new once on plugin enable. This used for verify token generation @@ -77,6 +79,11 @@ public class ProtocolLibListener extends PacketAdapter { return; } + if (packetEvent.getPacket().getMeta(SOURCE_META_KEY).map(val -> val.equals(plugin.getName())).orElse(false)) { + // this is our own packet + return; + } + Player sender = packetEvent.getPlayer(); PacketType packetType = packetEvent.getPacketType(); if (packetType == START) { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java index 10239f04..926857aa 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java @@ -285,7 +285,8 @@ public class VerifyResponseTask implements Runnable { startPacket.getGameProfiles().write(0, fakeProfile); try { //we don't want to handle our own packets so ignore filters - ProtocolLibrary.getProtocolManager().recieveClientPacket(player, startPacket, false); + ProtocolLibrary.getProtocolManager().recieveClientPacket(player, startPacket, true); + startPacket.setMeta(ProtocolLibListener.SOURCE_META_KEY, plugin.getName()); } catch (InvocationTargetException | IllegalAccessException ex) { plugin.getLog().warn("Failed to fake a new start packet for: {}", username, ex); //cancel the event in order to prevent the server receiving an invalid packet