the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "InputOutputStream.h"
3#include "PacketListener.h"
4#include "BasicTypeContainers.h"
5#include "GameCommandPacket.h"
6
7GameCommandPacket::GameCommandPacket()
8{
9 length = 0;
10}
11
12GameCommandPacket::GameCommandPacket(EGameCommand command, byteArray data)
13{
14 this->command = command;
15 this->data = data;
16 length = 0;
17
18 if (data.data != NULL)
19 {
20 length = data.length;
21
22 if (length > Short::MAX_VALUE)
23 {
24 app.DebugPrintf("Payload may not be larger than 32K\n");
25#ifndef _CONTENT_PACKAGE
26 __debugbreak();
27#endif
28 //throw new IllegalArgumentException("Payload may not be larger than 32k");
29 }
30 }
31}
32
33GameCommandPacket::~GameCommandPacket()
34{
35 delete [] data.data;
36}
37
38void GameCommandPacket::read(DataInputStream *dis)
39{
40 command = (EGameCommand)dis->readInt();
41 length = dis->readShort();
42
43 if (length > 0 && length < Short::MAX_VALUE)
44 {
45 if(data.data != NULL)
46 {
47 delete [] data.data;
48 }
49 data = byteArray(length);
50 dis->readFully(data);
51 }
52}
53
54void GameCommandPacket::write(DataOutputStream *dos)
55{
56 dos->writeInt(command);
57 dos->writeShort((short) length);
58 if (data.data != NULL)
59 {
60 dos->write(data);
61 }
62}
63
64void GameCommandPacket::handle(PacketListener *listener)
65{
66 listener->handleGameCommand( shared_from_this() );
67}
68
69int GameCommandPacket::getEstimatedSize()
70{
71 return 2 + 2 + length;
72}