the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 57 lines 1.3 kB view raw
1#include "stdafx.h" 2#include <iostream> 3#include "InputOutputStream.h" 4#include "PacketListener.h" 5#include "ComplexItemDataPacket.h" 6 7 8 9ComplexItemDataPacket::~ComplexItemDataPacket() 10{ 11 delete [] data.data; 12} 13 14ComplexItemDataPacket::ComplexItemDataPacket() 15{ 16 shouldDelay = true; 17 itemType = 0; 18} 19 20ComplexItemDataPacket::ComplexItemDataPacket(short itemType, short itemId, charArray data) 21{ 22 shouldDelay = true; 23 this->itemType = itemType; 24 this->itemId = itemId; 25 // Take copy of array passed in as we want the packets to have full ownership of any data they reference 26 this->data = charArray(data.length); 27 memcpy(this->data.data, data.data, data.length); 28} 29 30void ComplexItemDataPacket::read(DataInputStream *dis) //throws IOException 31{ 32 itemType = dis->readShort(); 33 itemId = dis->readShort(); 34 35 data = charArray(dis->readUnsignedShort() & 0xffff); 36 dis->readFully(data); 37} 38 39void ComplexItemDataPacket::write(DataOutputStream *dos) //throws IOException 40{ 41 dos->writeShort(itemType); 42 dos->writeShort(itemId); 43 dos->writeUnsignedShort(data.length); 44 45 byteArray ba( (byte*)data.data, data.length ); 46 dos->write(ba); 47} 48 49void ComplexItemDataPacket::handle(PacketListener *listener) 50{ 51 listener->handleComplexItemData( shared_from_this() ); 52} 53 54int ComplexItemDataPacket::getEstimatedSize() 55{ 56 return 2+2+2+ data.length; 57}