retrooper / packetevents

PacketEvents is emerging as a strong contender in the realm of Minecraft packet processing libraries. Designed to simplify packet manipulation while delivering high performance, this powerful tool aims to demystify the complexities of projects utilizing packets.
GNU General Public License v3.0
496 stars 143 forks source link

Cannot cancel packets sent by downstream server on Bungeecord and Velocity #891

Closed Rubenicos closed 3 weeks ago

Rubenicos commented 1 month ago

Describe the bug I made a plugin that cancel duplicated resource pack requests compatible with multiple APIs, but PacketEvents doesn't work. Basically, the plugin cancel any duplicated resource pack request packet when it is sent to player and also cancel almost every resource pack clear packet sent by plugins like ViaVersion or ItemsAdder when player joins on backend server. With PacketEvents the player gets disconnected when any PacketSendEvent is cancelled.

Software brand Waterfall 1.21 build 579 Velocity 3.3.0-SNAPSHOT

Plugins

How To Reproduce

  1. Connect two 1.20.4 backend servers with some proxy server (Velocity or Bungeecord)
  2. Put PacketEvents and OneTimePack on proxy server
  3. Put ViaVersion and ViaBackwards on backend servers
  4. Put some plugin that send the same resource pack on both backend servers
  5. Join with MC 1.20.1 or 1.20.4
  6. Move to the other backend server (to let OneTimePack work)
  7. You will get disconnected

Expected behavior A clear and concise description of what you expected to happen.

Screenshots image

Additional context Clearing the buffer on Bungeecord/Velocity doesn't solve the problem, you should replace the cancelled packet by some dummy KeepAlive packet to avoid those errors. https://github.com/retrooper/packetevents/blob/4524b4289cc1912363faf873ee81034105924f1e/bungeecord/src/main/java/io/github/retrooper/packetevents/handlers/PacketEventsEncoder.java#L67 https://github.com/retrooper/packetevents/blob/4524b4289cc1912363faf873ee81034105924f1e/velocity/src/main/java/io/github/retrooper/packetevents/handlers/PacketEventsEncoder.java#L55

retrooper commented 1 month ago

Still investigating, but might be related: https://github.com/saicone/OneTimePack/issues/6

Rubenicos commented 1 month ago

After some testing I found that the error is when I try to write a packet. https://github.com/saicone/OneTimePack/blob/36370092970d467afb252214a339a28583b439dc/module/module-packetevents/src/main/java/com/saicone/onetimepack/core/PacketEventsProcessor.java#L87

I try to send that packet to the downstream server where the player is connected, I'm making it wrong?

retrooper commented 1 month ago

Of course, you should read the issue I created saicone/OneTimePack#6

Rubenicos commented 1 month ago

I actually read it, after applying the changes I found that the problem comes when I try to write a packet as I mentioned above

retrooper commented 1 month ago

Well, at least respond to the issue created on your project. Please make the changes so I can see your current progress and tell you what more to fix.

Rubenicos commented 1 month ago

Done, I also changed to receivePacket (to send a packet to downstream server as if it from player) but there is a new error

Using #receivePacket() on Bungeecord

Click to see ``` [10:59:45 WARN]: [/...|Rubenicos] -> UpstreamBridge - A decoder exception has been thrown: io.netty.handler.codec.DecoderException: java.lang.IllegalArgumentException: Decompressed size 27 less than compression threshold 256 at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:333) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:455) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1407) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:918) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:799) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:501) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:399) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at java.lang.Thread.run(Thread.java:840) [?:?] Caused by: java.lang.IllegalArgumentException: Decompressed size 27 less than compression threshold 256 at com.google.common.base.Preconditions.checkArgument(Preconditions.java:302) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at net.md_5.bungee.compress.PacketDecompressor.decode(PacketDecompressor.java:41) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at net.md_5.bungee.compress.PacketDecompressor.decode(PacketDecompressor.java:13) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] ... 20 more ```

Using #receivePacketSilently() on Bungeecord

Click to see ``` [10:48:24 ERROR]: [/...|Rubenicos] -> UpstreamBridge - encountered exception java.lang.ClassCastException: class io.netty.buffer.PooledUnsafeDirectByteBuf cannot be cast to class net.md_5.bungee.protocol.PacketWrapper (io.netty.buffer.PooledUnsafeDirectByteBuf and net.md_5.bungee.protocol.PacketWrapper are in unnamed module of loader 'app') at net.md_5.bungee.netty.HandlerBoss.channelRead(HandlerBoss.java:109) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.github.retrooper.packetevents.impl.netty.channel.ChannelOperatorImpl.fireChannelReadInContext(ChannelOperatorImpl.java:85) ~[?:?] at com.github.retrooper.packetevents.netty.channel.ChannelHelper.fireChannelReadInContext(ChannelHelper.java:73) ~[?:?] at io.github.retrooper.packetevents.impl.netty.manager.protocol.ProtocolManagerAbstract.receivePacketSilently(ProtocolManagerAbstract.java:81) ~[?:?] at com.github.retrooper.packetevents.manager.protocol.ProtocolManager.receivePacketsSilently(ProtocolManager.java:91) ~[?:?] at com.github.retrooper.packetevents.manager.protocol.ProtocolManager.receivePacketSilently(ProtocolManager.java:142) ~[?:?] at com.saicone.onetimepack.core.PacketEventsProcessor.onPackPush(PacketEventsProcessor.java:87) ~[?:?] at com.saicone.onetimepack.core.PacketEventsProcessor.onPacketSend(PacketEventsProcessor.java:63) ~[?:?] at com.github.retrooper.packetevents.event.PacketListener$1.onPacketSend(PacketListener.java:46) ~[?:?] at com.github.retrooper.packetevents.event.PacketSendEvent.call(PacketSendEvent.java:51) ~[?:?] at com.github.retrooper.packetevents.event.EventManager.callEvent(EventManager.java:52) ~[?:?] at io.github.retrooper.packetevents.handlers.PacketEventsEncoder.read(PacketEventsEncoder.java:53) ~[?:?] at io.github.retrooper.packetevents.handlers.PacketEventsEncoder.encode(PacketEventsEncoder.java:81) ~[?:?] at io.github.retrooper.packetevents.handlers.PacketEventsEncoder.encode(PacketEventsEncoder.java:37) ~[?:?] at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:893) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:875) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:984) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:868) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:120) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:893) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:956) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:982) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:950) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1019) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:310) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at net.md_5.bungee.netty.ChannelWrapper.write(ChannelWrapper.java:86) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at net.md_5.bungee.UserConnection.sendPacket(UserConnection.java:193) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at net.md_5.bungee.connection.DownstreamBridge.handle(DownstreamBridge.java:161) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at net.md_5.bungee.netty.HandlerBoss.channelRead(HandlerBoss.java:136) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:289) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:333) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:455) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1407) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:918) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:799) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:501) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:399) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[waterfall-1.21-579.jar:git:Waterfall-Bootstrap:1.21-R0.1-SNAPSHOT:de8345a:579] at java.lang.Thread.run(Thread.java:840) [?:?] ```

Using #receivePacket() and #receivePacketSilently() on Velocity

[11:23:44 INFO]: [connected player] Rubenicos (/...) has disconnected: An internal error occurred in your connection.
Sweet-Duck commented 3 weeks ago

Same problem

retrooper commented 3 weeks ago

If you follow the issue created on his project, he managed to fix it.