From 42d45b3a9e2a5bf60d0e75b3700aedff2666c7fa Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Thu, 23 Mar 2023 16:01:46 -0500 Subject: [PATCH] Add version signature to packet data (#223) --- .../api/pony/network/MsgPonyData.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/com/minelittlepony/api/pony/network/MsgPonyData.java b/src/main/java/com/minelittlepony/api/pony/network/MsgPonyData.java index 7066f7ad..7aaa0feb 100644 --- a/src/main/java/com/minelittlepony/api/pony/network/MsgPonyData.java +++ b/src/main/java/com/minelittlepony/api/pony/network/MsgPonyData.java @@ -17,6 +17,10 @@ import java.util.function.Supplier; public class MsgPonyData implements IPonyData { + private final short API_IDENTIFIER = (short) 0xABCD; + // API version - increment this number before any time any data is added/removed/moved in the data stream + private final byte API_VERSION = 2; + private final Race race; private final TailLength tailLength; private final TailShape tailShape; @@ -41,6 +45,19 @@ public class MsgPonyData implements IPonyData { } public MsgPonyData(PacketByteBuf buffer) { + short data = buffer.readShort(); + if (data != API_IDENTIFIER || buffer.readByte() != API_VERSION) { + race = null; + tailLength = null; + tailShape = null; + gender = null; + size = null; + glowColor = 0; + noSkin = true; + wearables = null; + wearableColor = 0; + return; + } race = buffer.readEnumConstant(Race.class); tailLength = buffer.readEnumConstant(TailLength.class); tailShape = buffer.readEnumConstant(TailShape.class); @@ -70,6 +87,9 @@ public class MsgPonyData implements IPonyData { } public PacketByteBuf toBuffer(PacketByteBuf buffer) { + buffer.writeByte((API_IDENTIFIER & 0xFF00) >> 8); + buffer.writeByte(API_IDENTIFIER & 0x00FF); + buffer.writeByte(API_VERSION); buffer.writeEnumConstant(race); buffer.writeEnumConstant(tailLength); buffer.writeEnumConstant(tailShape);