From d0108af1e6525fe040a105796ecba41ba028e8e0 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Tue, 27 Apr 2021 16:24:32 +0800 Subject: [PATCH] Restore reader index after processing custom payload --- .../mixin/core/network/play/ServerPlayNetHandlerMixin.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/ServerPlayNetHandlerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/ServerPlayNetHandlerMixin.java index 2f386c59..0458323f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/ServerPlayNetHandlerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/ServerPlayNetHandlerMixin.java @@ -1684,7 +1684,7 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB private static final ResourceLocation CUSTOM_REGISTER = new ResourceLocation("register"); private static final ResourceLocation CUSTOM_UNREGISTER = new ResourceLocation("unregister"); - @Inject(method = "processCustomPayload", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/fml/network/NetworkHooks;onCustomPayload(Lnet/minecraftforge/fml/network/ICustomPacket;Lnet/minecraft/network/NetworkManager;)Z")) + @Inject(method = "processCustomPayload", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/fml/network/NetworkHooks;onCustomPayload(Lnet/minecraftforge/fml/network/ICustomPacket;Lnet/minecraft/network/NetworkManager;)Z")) private void arclight$customPayload(CCustomPayloadPacket packet, CallbackInfo ci) { if (packet.channel.equals(CUSTOM_REGISTER)) { try { @@ -1697,6 +1697,7 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } catch (Exception ex) { LOGGER.error("Couldn't register custom payload", ex); this.disconnect("Invalid payload REGISTER!"); + ci.cancel(); } } else if (packet.channel.equals(CUSTOM_UNREGISTER)) { try { @@ -1709,15 +1710,19 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } catch (Exception ex) { LOGGER.error("Couldn't unregister custom payload", ex); this.disconnect("Invalid payload UNREGISTER!"); + ci.cancel(); } } else { try { + int readerIndex = packet.data.readerIndex(); final byte[] data = new byte[packet.data.readableBytes()]; packet.data.readBytes(data); this.server.getMessenger().dispatchIncomingMessage(((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity(), packet.channel.toString(), data); + packet.data.readerIndex(readerIndex); } catch (Exception ex) { LOGGER.error("Couldn't dispatch custom payload", ex); this.disconnect("Invalid custom payload!"); + ci.cancel(); } } }