ProtocolLib

3M Downloads

Packet ID mismatch is not handled, leading to wrong packet IDs

Saghetti0 opened this issue ยท 2 comments

commented
  • This issue is not solved in a development build

Describe the bug
PacketType.fromCurrent() does not properly handle an ID mismatch. While there is code in the method that checks for a mismatch, the consumer it invokes (onIdMismatch) does nothing, and is never referenced anywhere else. When PacketRegistry initializes, it calls fromCurrent() in order to create PacketTypes with the correct IDs, but these correct IDs are dropped, and erroneous PacketTypes are returned. This results in packet IDs in the registry always being for the latest versions, even when the server is running an older version of Minecraft. This also results in plugins receiving PacketEvents containing PacketTypes with the wrong IDs.

To Reproduce
Run the following code on an older version of the game (ex: 1.20.4) and cross-reference packet IDs with the protocol docs for that version.

PacketRegistry.synchronize();
Set<PacketType> pTypes = PacketRegistry.getServerPacketTypes();

for (PacketType pType : pTypes) {
  getLogger().info(pType.getPacketClass().getName() + ": " + pType.getCurrentId());
}

Despite the server running on an older version, all the packet IDs correspond to latest.

Expected behavior
Packet IDs should correspond to the version of Minecraft that the server is running.

Version Info
https://pastebin.com/3JW4RgA0

Additional context
I know that getCurrentId() is deprecated, but the project I'm currently working on relies on it to work properly, because it records direct packet dumps from the game. These packet IDs are never hardcoded or checked.

commented

so if i'm understanding correctly, you need a way to get the ID of a packet in the running version. getCurrentID is returning the latest version. i think it should be reasonably straightforward to add some functionality to do that

commented

I went through the code to explain why getCurrentID returns the latest packet ID, but you got it. I just need a method to get packet IDs for the current server version.