the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 109 lines 3.3 kB view raw
1#pragma once 2using namespace std; 3 4class Packet; 5class PacketListener; 6class DataInputStream; 7class DataOutputStream; 8 9#define PACKET_ENABLE_STAT_TRACKING 0 10 11class Packet; 12 13typedef shared_ptr<Packet> (*packetCreateFn)(); 14 15class Packet 16{ 17public: 18 class PacketStatistics 19 { 20 private: 21 int count; 22 int totalSize; 23 24 static const int TOTAL_TICKS = 100; 25 26 // 4J Added 27 __int64 countSamples[TOTAL_TICKS]; 28 __int64 sizeSamples[TOTAL_TICKS]; 29 __int64 timeSamples[TOTAL_TICKS]; 30 int samplesPos; 31 32 public: 33 const int id; 34 35 public: 36 PacketStatistics(int id); 37 void addPacket(int bytes); 38 int getCount(); 39 int getTotalSize(); 40 double getAverageSize(); 41 __int64 getRunningTotal(); 42 __int64 getRunningCount(); 43 void IncrementPos(); 44 }; 45 46 // 4J JEV, replaces the static blocks. 47 static void staticCtor(); 48 49public: 50 static unordered_map<int, packetCreateFn> idToCreateMap; // IntHashMap in 1.8.2 ... needed? // Made public in 1.0.1 51 52 static unordered_set<int> clientReceivedPackets; 53 static unordered_set<int> serverReceivedPackets; 54 static unordered_set<int> sendToAnyClientPackets; 55 56 // 4J Stu - Added the sendToAnyClient param so we can limit some packets to be only sent to one player on a system 57 // 4J Stu - Added renderStats param for use in debugging 58 static void map(int id, bool receiveOnClient, bool receiveOnServer, bool sendToAnyClient, bool renderStats, const type_info& clazz, packetCreateFn ); 59 60public: 61 const __int64 createTime; 62 63 Packet(); 64 65 static shared_ptr<Packet> getPacket(int id); 66 67 // 4J Added 68 static bool canSendToAnyClient(shared_ptr<Packet> packet); 69 70 static void writeBytes(DataOutputStream *dataoutputstream, byteArray bytes); 71 static byteArray readBytes(DataInputStream *datainputstream); 72 73 virtual int getId() = 0; 74 75 bool shouldDelay; 76 77private: 78 // 4J Added to track stats for packets that are going out via QNet 79 static unordered_map<int, PacketStatistics *> outgoingStatistics; // IntHashMap in 1.8.2 ... needed? 80 static vector<PacketStatistics *> renderableStats; 81 static int renderPos; 82public: 83 static void recordOutgoingPacket(shared_ptr<Packet> packet, int playerIndex); 84 static void updatePacketStatsPIX(); 85private : 86 static unordered_map<int, PacketStatistics *> statistics; 87 //static int nextPrint; 88 89public: 90 static shared_ptr<Packet> readPacket(DataInputStream *dis, bool isServer); 91 static void writePacket(shared_ptr<Packet> packet, DataOutputStream *dos); 92 static void writeUtf(const wstring& value, DataOutputStream *dos); 93 static wstring readUtf(DataInputStream *dis, int maxLength); 94 virtual void read(DataInputStream *dis) = 0; // throws IOException = 0; TODO 4J JEV, should this declare a throws? 95 virtual void write(DataOutputStream *dos) = 0; // throws IOException = 0; TODO 4J JEV, should this declare a throws? 96 virtual void handle(PacketListener *listener) = 0; 97 virtual int getEstimatedSize() = 0; 98 virtual bool canBeInvalidated(); 99 virtual bool isInvalidatedBy(shared_ptr<Packet> packet); 100 virtual bool isAync(); 101 102 // 4J Stu - Brought these functions forward for enchanting/game rules 103 static shared_ptr<ItemInstance> readItem(DataInputStream *dis); 104 static void writeItem(shared_ptr<ItemInstance> item, DataOutputStream *dos); 105 static CompoundTag *readNbt(DataInputStream *dis); 106 107protected: 108 static void writeNbt(CompoundTag *tag, DataOutputStream *dos); 109};