mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-05-15 22:43:50 +00:00
Initial commit
This commit is contained in:
parent
def8cb4153
commit
b691c43c44
19437 changed files with 4363922 additions and 0 deletions
72
Minecraft.World/GameCommandPacket.cpp
Normal file
72
Minecraft.World/GameCommandPacket.cpp
Normal file
|
|
@ -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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue