dmulloy2 / ProtocolLib

Provides read and write access to the Minecraft protocol with Bukkit.
GNU General Public License v2.0
1k stars 261 forks source link

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

Open Saghetti0 opened 1 month ago

Saghetti0 commented 1 month ago

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.

dmulloy2 commented 1 month ago

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

Saghetti0 commented 1 month ago

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.