badasintended / badpackets

multiplatform packet api
https://bai.lol/badpackets
Apache License 2.0
22 stars 4 forks source link

Fabric API's sendable channel sync randomly not working #10

Closed qouteall closed 1 year ago

qouteall commented 1 year ago

The latest version of ImmPtl added the code of rejecting vanilla clients using Fabric API functionality

https://github.com/iPortalTeam/ImmersivePortalsMod/blob/1.20.2/imm_ptl_core/src/main/java/qouteall/imm_ptl/core/network/ImmPtlNetworkConfig.java#L209

(following the doc of https://fabricmc.net/2023/09/12/1202.html)

Someone reported that it will wrongly recognize the client as not having ImmPtl when entering singleplayer world, when using bad packets mod, thus disconnecting the client. As I tested, this issue occurs randomly.

https://github.com/iPortalTeam/ImmersivePortalsMod/issues/1456

deirn commented 1 year ago

Are there any specific mod versions that I can look at, or does it happen on latest version?

deirn commented 1 year ago

Can only reproduce it once, and that's when I didn't place a breakpoint :/.

Looks like Bad Packets' sync task is called first somehow even though Fabric API's mixin has higher priority? Even then the synced channel ids should still be there by the time the event callback is called.

https://github.com/FabricMC/fabric/blob/1fbc78fabb035f7902f21f9f1f34c13ad4d02aff/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ServerConfigurationNetworkHandlerMixin.java#L46

https://github.com/FabricMC/fabric/blob/1fbc78fabb035f7902f21f9f1f34c13ad4d02aff/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ServerConfigurationNetworkHandlerMixin.java#L88-L92

https://github.com/badasintended/badpackets/blob/9c7bd74a13d742fb3575239b79151440fc10932e/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerConfigurationPacketListenerImpl.java#L53-L57

qouteall commented 1 year ago

Are there any specific mod versions that I can look at, or does it happen on latest version?

The latest version of ImmPtl.

Fabric API testmod has similar things https://github.com/FabricMC/fabric/blob/1.20.2/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/configuration/NetworkingConfigurationTest.java#L42

The randomness may be caused by multithreading. I guess that bad packets packet handling happens concurrently with Fabric API's (not sure). Breakpoint may interfere with it by slowing down some code.