Files
MinecraftConsoles/Minecraft.World/GameCommandPacket.cpp
Loki Rautio 087b7e7abf Revert "Project modernization (#630)"
This code was not tested and breaks in Release builds, reverting to restore
functionality of the nightly. All in-game menus do not work and generating
a world crashes.

This reverts commit a9be52c41a.
2026-03-07 21:12:22 -06:00

72 lines
1.3 KiB
C++

#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;
}