diff options
| author | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
|---|---|---|
| committer | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
| commit | b691c43c44ff180d10e7d4a9afc83b98551ff586 (patch) | |
| tree | 3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.World/CustomPayloadPacket.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.World/CustomPayloadPacket.cpp')
| -rw-r--r-- | Minecraft.World/CustomPayloadPacket.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Minecraft.World/CustomPayloadPacket.cpp b/Minecraft.World/CustomPayloadPacket.cpp new file mode 100644 index 00000000..29e2828e --- /dev/null +++ b/Minecraft.World/CustomPayloadPacket.cpp @@ -0,0 +1,75 @@ +#include "stdafx.h" +#include "InputOutputStream.h" +#include "PacketListener.h" +#include "BasicTypeContainers.h" +#include "CustomPayloadPacket.h" + +// Mojang-defined custom packets +const wstring CustomPayloadPacket::CUSTOM_BOOK_PACKET = L"MC|BEdit"; +const wstring CustomPayloadPacket::CUSTOM_BOOK_SIGN_PACKET = L"MC|BSign"; +const wstring CustomPayloadPacket::TEXTURE_PACK_PACKET = L"MC|TPack"; +const wstring CustomPayloadPacket::TRADER_LIST_PACKET = L"MC|TrList"; +const wstring CustomPayloadPacket::TRADER_SELECTION_PACKET = L"MC|TrSel"; +const wstring CustomPayloadPacket::SET_ADVENTURE_COMMAND_PACKET = L"MC|AdvCdm"; +const wstring CustomPayloadPacket::SET_BEACON_PACKET = L"MC|Beacon"; +const wstring CustomPayloadPacket::SET_ITEM_NAME_PACKET = L"MC|ItemName"; + +CustomPayloadPacket::CustomPayloadPacket() +{ +} + +CustomPayloadPacket::CustomPayloadPacket(const wstring &identifier, byteArray data) +{ + this->identifier = identifier; + this->data = data; + + if (data.data != NULL) + { + length = data.length; + + if (length > Short::MAX_VALUE) + { + app.DebugPrintf("Payload may not be larger than 32K\n"); +#ifndef _CONTENT_PACKAGE + __debugbreak(); +#endif + //throw new IllegalArgumentException("Payload may not be larger than 32k"); + } + } +} + +void CustomPayloadPacket::read(DataInputStream *dis) +{ + identifier = readUtf(dis, 20); + length = dis->readShort(); + + if (length > 0 && length < Short::MAX_VALUE) + { + if(data.data != NULL) + { + delete [] data.data; + } + data = byteArray(length); + dis->readFully(data); + } +} + +void CustomPayloadPacket::write(DataOutputStream *dos) +{ + writeUtf(identifier, dos); + dos->writeShort((short) length); + if (data.data != NULL) + { + dos->write(data); + } +} + +void CustomPayloadPacket::handle(PacketListener *listener) +{ + listener->handleCustomPayload( shared_from_this() ); +} + +int CustomPayloadPacket::getEstimatedSize() +{ + return 2 + identifier.length() * 2 + 2 + length; +}
\ No newline at end of file |
