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/GameCommandPacket.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.World/GameCommandPacket.cpp')
| -rw-r--r-- | Minecraft.World/GameCommandPacket.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/Minecraft.World/GameCommandPacket.cpp b/Minecraft.World/GameCommandPacket.cpp new file mode 100644 index 00000000..98cdd312 --- /dev/null +++ b/Minecraft.World/GameCommandPacket.cpp @@ -0,0 +1,72 @@ +#include "stdafx.h" +#include "InputOutputStream.h" +#include "PacketListener.h" +#include "BasicTypeContainers.h" +#include "GameCommandPacket.h" + +GameCommandPacket::GameCommandPacket() +{ + length = 0; +} + +GameCommandPacket::GameCommandPacket(EGameCommand command, byteArray data) +{ + this->command = command; + this->data = data; + length = 0; + + 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"); + } + } +} + +GameCommandPacket::~GameCommandPacket() +{ + delete [] data.data; +} + +void GameCommandPacket::read(DataInputStream *dis) +{ + command = (EGameCommand)dis->readInt(); + length = dis->readShort(); + + if (length > 0 && length < Short::MAX_VALUE) + { + if(data.data != NULL) + { + delete [] data.data; + } + data = byteArray(length); + dis->readFully(data); + } +} + +void GameCommandPacket::write(DataOutputStream *dos) +{ + dos->writeInt(command); + dos->writeShort((short) length); + if (data.data != NULL) + { + dos->write(data); + } +} + +void GameCommandPacket::handle(PacketListener *listener) +{ + listener->handleGameCommand( shared_from_this() ); +} + +int GameCommandPacket::getEstimatedSize() +{ + return 2 + 2 + length; +}
\ No newline at end of file |
