From 2c804dd34a58ff9702bd1ab2cab30f6a61503638 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Mon, 9 Sep 2019 18:22:37 +0200 Subject: Protocol: Use logical outgoing packet types. --- src/Protocol/Protocol_1_9.cpp | 309 ++++++++++++++++++++++++++++-------------- 1 file changed, 204 insertions(+), 105 deletions(-) (limited to 'src/Protocol/Protocol_1_9.cpp') diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index f9a018a5c..29d8b1c34 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -116,7 +116,7 @@ extern bool g_ShouldLogCommIn, g_ShouldLogCommOut; // cProtocol_1_9_0: cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client), + Super(a_Client), m_ServerAddress(a_ServerAddress), m_ServerPort(a_ServerPort), m_State(a_State), @@ -227,7 +227,7 @@ void cProtocol_1_9_0::DataReceived(const char * a_Data, size_t a_Size) void cProtocol_1_9_0::SendAttachEntity(const cEntity & a_Entity, const cEntity & a_Vehicle) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendAttachEntity)); // Set passangers packet + cPacketizer Pkt(*this, pktAttachEntity); Pkt.WriteVarInt32(a_Vehicle.GetUniqueID()); Pkt.WriteVarInt32(1); // 1 passenger Pkt.WriteVarInt32(a_Entity.GetUniqueID()); @@ -241,7 +241,7 @@ void cProtocol_1_9_0::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendBlockAction)); // Block Action packet + cPacketizer Pkt(*this, pktBlockAction); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Pkt.WriteBEInt8(a_Byte1); Pkt.WriteBEInt8(a_Byte2); @@ -256,7 +256,7 @@ void cProtocol_1_9_0::SendBlockBreakAnim(UInt32 a_EntityID, int a_BlockX, int a_ { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendBlockBreakAnim)); // Block Break Animation packet + cPacketizer Pkt(*this, pktBlockBreakAnim); Pkt.WriteVarInt32(a_EntityID); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Pkt.WriteBEInt8(a_Stage); @@ -270,7 +270,7 @@ void cProtocol_1_9_0::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendBlockChange)); // Block Change packet + cPacketizer Pkt(*this, pktBlockChange); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Pkt.WriteVarInt32((static_cast(a_BlockType) << 4) | (static_cast(a_BlockMeta) & 15)); } @@ -283,7 +283,7 @@ void cProtocol_1_9_0::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlo { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendBlockChanges)); // Multi Block Change packet + cPacketizer Pkt(*this, pktBlockChanges); Pkt.WriteBEInt32(a_ChunkX); Pkt.WriteBEInt32(a_ChunkZ); Pkt.WriteVarInt32(static_cast(a_Changes.size())); @@ -301,7 +301,7 @@ void cProtocol_1_9_0::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlo void cProtocol_1_9_0::SendCameraSetTo(const cEntity & a_Entity) { - cPacketizer Pkt(*this, GetPacketId(sendCameraSetTo)); // Camera Packet (Attach the camera of a player at another entity in spectator mode) + cPacketizer Pkt(*this, pktCameraSetTo); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); } @@ -336,7 +336,7 @@ void cProtocol_1_9_0::SendChatRaw(const AString & a_MessageRaw, eChatType a_Type ASSERT(m_State == 3); // In game mode? // Send the json string to the client: - cPacketizer Pkt(*this, GetPacketId(sendChatRaw)); // Chat Message packet + cPacketizer Pkt(*this, pktChatRaw); Pkt.WriteString(a_MessageRaw); Pkt.WriteBEInt8(a_Type); } @@ -366,7 +366,7 @@ void cProtocol_1_9_0::SendCollectEntity(const cEntity & a_Entity, const cPlayer UNUSED(a_Count); ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendCollectEntity)); // Collect Item packet + cPacketizer Pkt(*this, pktCollectEntity); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteVarInt32(a_Player.GetUniqueID()); } @@ -379,7 +379,7 @@ void cProtocol_1_9_0::SendDestroyEntity(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendDestroyEntity)); // Destroy Entities packet + cPacketizer Pkt(*this, pktDestroyEntity); Pkt.WriteVarInt32(1); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); } @@ -391,7 +391,7 @@ void cProtocol_1_9_0::SendDestroyEntity(const cEntity & a_Entity) void cProtocol_1_9_0::SendDetachEntity(const cEntity & a_Entity, const cEntity & a_PreviousVehicle) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendAttachEntity)); // Set passangers packet + cPacketizer Pkt(*this, pktAttachEntity); Pkt.WriteVarInt32(a_PreviousVehicle.GetUniqueID()); Pkt.WriteVarInt32(0); // No passangers } @@ -407,14 +407,14 @@ void cProtocol_1_9_0::SendDisconnect(const AString & a_Reason) case 2: { // During login: - cPacketizer Pkt(*this, GetPacketId(sendDisconnectDuringLogin)); + cPacketizer Pkt(*this, pktDisconnectDuringLogin); Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str())); break; } case 3: { // In-game: - cPacketizer Pkt(*this, GetPacketId(sendDisconnectDuringGame)); + cPacketizer Pkt(*this, pktDisconnectDuringGame); Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str())); break; } @@ -429,7 +429,7 @@ void cProtocol_1_9_0::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEditSign)); // Sign Editor Open packet + cPacketizer Pkt(*this, pktEditSign); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); } @@ -441,7 +441,7 @@ void cProtocol_1_9_0::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityEffect)); // Entity Effect packet + cPacketizer Pkt(*this, pktEntityEffect); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEUInt8(static_cast(a_EffectID)); Pkt.WriteBEUInt8(static_cast(a_Amplifier)); @@ -457,7 +457,7 @@ void cProtocol_1_9_0::SendEntityEquipment(const cEntity & a_Entity, short a_Slot { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityEquipment)); // Entity Equipment packet + cPacketizer Pkt(*this, pktEntityEquipment); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); // Needs to be adjusted due to the insertion of offhand at slot 1 if (a_SlotNum > 0) @@ -476,7 +476,7 @@ void cProtocol_1_9_0::SendEntityHeadLook(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityHeadLook)); // Entity Head Look packet + cPacketizer Pkt(*this, pktEntityHeadLook); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteByteAngle(a_Entity.GetHeadYaw()); } @@ -489,7 +489,7 @@ void cProtocol_1_9_0::SendEntityLook(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityLook)); // Entity Look packet + cPacketizer Pkt(*this, pktEntityLook); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteByteAngle(a_Entity.GetYaw()); Pkt.WriteByteAngle(a_Entity.GetPitch()); @@ -504,7 +504,7 @@ void cProtocol_1_9_0::SendEntityMetadata(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityMeta)); // Entity Metadata packet + cPacketizer Pkt(*this, pktEntityMeta); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); WriteEntityMetadata(Pkt, a_Entity); Pkt.WriteBEUInt8(0xff); // The termination byte @@ -518,7 +518,7 @@ void cProtocol_1_9_0::SendEntityProperties(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityProperties)); // Entity Properties packet + cPacketizer Pkt(*this, pktEntityProperties); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); WriteEntityProperties(Pkt, a_Entity); } @@ -531,7 +531,7 @@ void cProtocol_1_9_0::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, c { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityRelMove)); // Entity Relative Move packet + cPacketizer Pkt(*this, pktEntityRelMove); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); // TODO: 1.9 changed these from chars to shorts, meaning that there can be more percision and data. Other code needs to be updated for that. Pkt.WriteBEInt16(a_RelX * 128); @@ -548,7 +548,7 @@ void cProtocol_1_9_0::SendEntityRelMoveLook(const cEntity & a_Entity, char a_Rel { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityRelMoveLook)); // Entity Look And Relative Move packet + cPacketizer Pkt(*this, pktEntityRelMoveLook); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); // TODO: 1.9 changed these from chars to shorts, meaning that there can be more percision and data. Other code needs to be updated for that. Pkt.WriteBEInt16(a_RelX * 128); @@ -567,7 +567,7 @@ void cProtocol_1_9_0::SendEntityStatus(const cEntity & a_Entity, char a_Status) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityStatus)); // Entity Status packet + cPacketizer Pkt(*this, pktEntityStatus); Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); Pkt.WriteBEInt8(a_Status); } @@ -580,7 +580,7 @@ void cProtocol_1_9_0::SendEntityVelocity(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityVelocity)); // Entity Velocity packet + cPacketizer Pkt(*this, pktEntityVelocity); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); // 400 = 8000 / 20 ... Conversion from our speed in m / s to 8000 m / tick Pkt.WriteBEInt16(static_cast(a_Entity.GetSpeedX() * 400)); @@ -596,7 +596,7 @@ void cProtocol_1_9_0::SendExplosion(double a_BlockX, double a_BlockY, double a_B { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendExplosion)); // Explosion packet + cPacketizer Pkt(*this, pktExplosion); Pkt.WriteBEFloat(static_cast(a_BlockX)); Pkt.WriteBEFloat(static_cast(a_BlockY)); Pkt.WriteBEFloat(static_cast(a_BlockZ)); @@ -621,7 +621,7 @@ void cProtocol_1_9_0::SendGameMode(eGameMode a_GameMode) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendGameMode)); // Change Game State packet + cPacketizer Pkt(*this, pktGameMode); Pkt.WriteBEUInt8(3); // Reason: Change game mode Pkt.WriteBEFloat(static_cast(a_GameMode)); // The protocol really represents the value with a float! } @@ -634,7 +634,7 @@ void cProtocol_1_9_0::SendHealth(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendHealth)); // Update Health packet + cPacketizer Pkt(*this, pktUpdateHealth); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEFloat(static_cast(Player->GetHealth())); Pkt.WriteVarInt32(static_cast(Player->GetFoodLevel())); @@ -649,7 +649,7 @@ void cProtocol_1_9_0::SendHeldItemChange(int a_ItemIndex) { ASSERT((a_ItemIndex >= 0) && (a_ItemIndex <= 8)); // Valid check - cPacketizer Pkt(*this, GetPacketId(sendHeldItemChange)); // Held item change + cPacketizer Pkt(*this, pktHeldItemChange); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEInt8(static_cast(Player->GetInventory().GetEquippedSlotNum())); } @@ -662,7 +662,7 @@ void cProtocol_1_9_0::SendHideTitle(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(3); // Hide title } @@ -674,7 +674,7 @@ void cProtocol_1_9_0::SendInventorySlot(char a_WindowID, short a_SlotNum, const { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendInventorySlot)); // Set Slot packet + cPacketizer Pkt(*this, pktInventorySlot); Pkt.WriteBEInt8(a_WindowID); Pkt.WriteBEInt16(a_SlotNum); WriteItem(Pkt, a_Item); @@ -689,11 +689,11 @@ void cProtocol_1_9_0::SendKeepAlive(UInt32 a_PingID) // Drop the packet if the protocol is not in the Game state yet (caused a client crash): if (m_State != 3) { - LOGWARNING("Trying to send a KeepAlive packet to a player who's not yet fully logged in (%d). The protocol class prevented the packet.", m_State); + LOG("Trying to send a KeepAlive packet to a player who's not yet fully logged in (%d). The protocol class prevented the packet.", m_State); return; } - cPacketizer Pkt(*this, GetPacketId(sendKeepAlive)); // Keep Alive packet + cPacketizer Pkt(*this, pktKeepAlive); Pkt.WriteVarInt32(a_PingID); } @@ -704,7 +704,7 @@ void cProtocol_1_9_0::SendKeepAlive(UInt32 a_PingID) void cProtocol_1_9_0::SendLeashEntity(const cEntity & a_Entity, const cEntity & a_EntityLeashedTo) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendLeashEntity)); // Set Attach Entity packet + cPacketizer Pkt(*this, pktLeashEntity); Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); Pkt.WriteBEUInt32(a_EntityLeashedTo.GetUniqueID()); } @@ -716,7 +716,7 @@ void cProtocol_1_9_0::SendLeashEntity(const cEntity & a_Entity, const cEntity & void cProtocol_1_9_0::SendUnleashEntity(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendLeashEntity)); // Set Attach Entity packet + cPacketizer Pkt(*this, pktLeashEntity); Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); Pkt.WriteBEInt32(-1); // Unleash a_Entity } @@ -730,7 +730,7 @@ void cProtocol_1_9_0::SendLogin(const cPlayer & a_Player, const cWorld & a_World // Send the Join Game packet: { cServer * Server = cRoot::Get()->GetServer(); - cPacketizer Pkt(*this, GetPacketId(sendJoinGame)); // Join Game packet + cPacketizer Pkt(*this, pktJoinGame); Pkt.WriteBEUInt32(a_Player.GetUniqueID()); Pkt.WriteBEUInt8(static_cast(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 Pkt.WriteBEInt8(static_cast(a_World.GetDimension())); @@ -742,13 +742,13 @@ void cProtocol_1_9_0::SendLogin(const cPlayer & a_Player, const cWorld & a_World // Send the spawn position: { - cPacketizer Pkt(*this, GetPacketId(sendSpawnPosition)); // Spawn Position packet + cPacketizer Pkt(*this, pktSpawnPosition); Pkt.WritePosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ())); } // Send the server difficulty: { - cPacketizer Pkt(*this, GetPacketId(sendDifficulty)); // Server difficulty packet + cPacketizer Pkt(*this, pktDifficulty); Pkt.WriteBEInt8(1); } @@ -766,14 +766,14 @@ void cProtocol_1_9_0::SendLoginSuccess(void) // Enable compression: { - cPacketizer Pkt(*this, 0x03); // Set compression packet + cPacketizer Pkt(*this, pktStartCompression); Pkt.WriteVarInt32(256); } m_State = 3; // State = Game { - cPacketizer Pkt(*this, 0x02); // Login success packet + cPacketizer Pkt(*this, pktLoginSuccess); Pkt.WriteString(m_Client->GetUUID().ToLongString()); Pkt.WriteString(m_Client->GetUsername()); } @@ -790,7 +790,7 @@ void cProtocol_1_9_0::SendPaintingSpawn(const cPainting & a_Painting) double PosY = a_Painting.GetPosY(); double PosZ = a_Painting.GetPosZ(); - cPacketizer Pkt(*this, GetPacketId(sendPaintingSpawn)); // Spawn Painting packet + cPacketizer Pkt(*this, pktSpawnPainting); Pkt.WriteVarInt32(a_Painting.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -808,7 +808,7 @@ void cProtocol_1_9_0::SendMapData(const cMap & a_Map, int a_DataStartX, int a_Da { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendMapData)); // Map packet + cPacketizer Pkt(*this, pktMapData); Pkt.WriteVarInt32(a_Map.GetID()); Pkt.WriteBEUInt8(static_cast(a_Map.GetScale())); @@ -841,7 +841,7 @@ void cProtocol_1_9_0::SendPickupSpawn(const cPickup & a_Pickup) ASSERT(m_State == 3); // In game mode? { // TODO Use SendSpawnObject - cPacketizer Pkt(*this, GetPacketId(sendSpawnObject)); // Spawn Object packet + cPacketizer Pkt(*this, pktSpawnObject); Pkt.WriteVarInt32(a_Pickup.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -869,7 +869,7 @@ void cProtocol_1_9_0::SendPlayerAbilities(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerAbilities)); // Player Abilities packet + cPacketizer Pkt(*this, pktPlayerAbilities); Byte Flags = 0; cPlayer * Player = m_Client->GetPlayer(); if (Player->IsGameModeCreative()) @@ -898,7 +898,7 @@ void cProtocol_1_9_0::SendEntityAnimation(const cEntity & a_Entity, char a_Anima { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityAnimation)); // Animation packet + cPacketizer Pkt(*this, pktEntityAnimation); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEInt8(a_Animation); } @@ -912,7 +912,7 @@ void cProtocol_1_9_0::SendParticleEffect(const AString & a_ParticleName, float a ASSERT(m_State == 3); // In game mode? int ParticleID = GetParticleID(a_ParticleName); - cPacketizer Pkt(*this, GetPacketId(sendParticleEffect)); // Particle effect packet + cPacketizer Pkt(*this, pktParticleEffect); Pkt.WriteBEInt32(ParticleID); Pkt.WriteBool(false); Pkt.WriteBEFloat(a_SrcX); @@ -934,7 +934,7 @@ void cProtocol_1_9_0::SendParticleEffect(const AString & a_ParticleName, Vector3 ASSERT(m_State == 3); // In game mode? int ParticleID = GetParticleID(a_ParticleName); - cPacketizer Pkt(*this, GetPacketId(sendParticleEffect)); // Particle effect packet + cPacketizer Pkt(*this, pktParticleEffect); Pkt.WriteBEInt32(ParticleID); Pkt.WriteBool(false); Pkt.WriteBEFloat(a_Src.x); @@ -977,7 +977,7 @@ void cProtocol_1_9_0::SendPlayerListAddPlayer(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(0); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -1014,7 +1014,7 @@ void cProtocol_1_9_0::SendPlayerListRemovePlayer(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(4); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -1028,7 +1028,7 @@ void cProtocol_1_9_0::SendPlayerListUpdateGameMode(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(1); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -1046,7 +1046,7 @@ void cProtocol_1_9_0::SendPlayerListUpdatePing(const cPlayer & a_Player) auto ClientHandle = a_Player.GetClientHandlePtr(); if (ClientHandle != nullptr) { - cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(2); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -1062,7 +1062,7 @@ void cProtocol_1_9_0::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(3); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -1086,7 +1086,7 @@ void cProtocol_1_9_0::SendPlayerMaxSpeed(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerMaxSpeed)); // Entity Properties + cPacketizer Pkt(*this, pktPlayerMaxSpeed); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteVarInt32(Player->GetUniqueID()); Pkt.WriteBEInt32(1); // Count @@ -1115,7 +1115,7 @@ void cProtocol_1_9_0::SendPlayerMoveLook(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerMoveLook)); // Player Position And Look packet + cPacketizer Pkt(*this, pktPlayerMoveLook); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEDouble(Player->GetPosX()); Pkt.WriteBEDouble(Player->GetPosY()); @@ -1146,7 +1146,7 @@ void cProtocol_1_9_0::SendPlayerPosition(void) void cProtocol_1_9_0::SendPlayerSpawn(const cPlayer & a_Player) { // Called to spawn another player for the client - cPacketizer Pkt(*this, GetPacketId(sendPlayerSpawn)); // Spawn Player packet + cPacketizer Pkt(*this, pktSpawnOtherPlayer); Pkt.WriteVarInt32(a_Player.GetUniqueID()); Pkt.WriteUUID(a_Player.GetUUID()); Vector3d LastSentPos = a_Player.GetLastSentPos(); @@ -1167,7 +1167,7 @@ void cProtocol_1_9_0::SendPluginMessage(const AString & a_Channel, const AString { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPluginMessage)); // Plugin message packet + cPacketizer Pkt(*this, pktPluginMessage); Pkt.WriteString(a_Channel); Pkt.WriteBuf(a_Message.data(), a_Message.size()); } @@ -1180,7 +1180,7 @@ void cProtocol_1_9_0::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Eff { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendRemoveEntityEffect)); // Remove entity effect packet + cPacketizer Pkt(*this, pktRemoveEntityEffect); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEUInt8(static_cast(a_EffectID)); } @@ -1193,7 +1193,7 @@ void cProtocol_1_9_0::SendResetTitle(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(4); // Reset title } @@ -1203,7 +1203,7 @@ void cProtocol_1_9_0::SendResetTitle(void) void cProtocol_1_9_0::SendRespawn(eDimension a_Dimension) { - cPacketizer Pkt(*this, GetPacketId(sendRespawn)); // Respawn packet + cPacketizer Pkt(*this, pktRespawn); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEInt32(static_cast(a_Dimension)); Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal) @@ -1219,7 +1219,7 @@ void cProtocol_1_9_0::SendExperience(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendExperience)); // Experience Packet + cPacketizer Pkt(*this, pktExperience); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEFloat(Player->GetXpPercentage()); Pkt.WriteVarInt32(static_cast(Player->GetXpLevel())); @@ -1234,7 +1234,7 @@ void cProtocol_1_9_0::SendExperienceOrb(const cExpOrb & a_ExpOrb) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendExperienceOrb)); // Spawn experience orb packet + cPacketizer Pkt(*this, pktSpawnExperienceOrb); Pkt.WriteVarInt32(a_ExpOrb.GetUniqueID()); Pkt.WriteBEDouble(a_ExpOrb.GetPosX()); Pkt.WriteBEDouble(a_ExpOrb.GetPosY()); @@ -1250,7 +1250,7 @@ void cProtocol_1_9_0::SendScoreboardObjective(const AString & a_Name, const AStr { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendScoreboardObjective)); // Scoreboard objective packet + cPacketizer Pkt(*this, pktScoreboardObjective); Pkt.WriteString(a_Name); Pkt.WriteBEUInt8(a_Mode); if ((a_Mode == 0) || (a_Mode == 2)) @@ -1268,7 +1268,7 @@ void cProtocol_1_9_0::SendScoreUpdate(const AString & a_Objective, const AString { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendScoreUpdate)); // Update score packet + cPacketizer Pkt(*this, pktUpdateScore); Pkt.WriteString(a_Player); Pkt.WriteBEUInt8(a_Mode); Pkt.WriteString(a_Objective); @@ -1287,7 +1287,7 @@ void cProtocol_1_9_0::SendDisplayObjective(const AString & a_Objective, cScorebo { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendDisplayObjective)); // Display scoreboard packet + cPacketizer Pkt(*this, pktDisplayObjective); Pkt.WriteBEUInt8(static_cast(a_Display)); Pkt.WriteString(a_Objective); } @@ -1309,9 +1309,8 @@ void cProtocol_1_9_0::SendSetRawSubTitle(const AString & a_SubTitle) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(1); // Set subtitle - Pkt.WriteString(a_SubTitle); } @@ -1332,9 +1331,8 @@ void cProtocol_1_9_0::SendSetRawTitle(const AString & a_Title) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(0); // Set title - Pkt.WriteString(a_Title); } @@ -1346,7 +1344,7 @@ void cProtocol_1_9_0::SendSoundEffect(const AString & a_SoundName, double a_X, d { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSoundEffect)); // Named sound effect packet + cPacketizer Pkt(*this, pktSoundEffect); Pkt.WriteString(a_SoundName); Pkt.WriteVarInt32(0); // Master sound category (may want to be changed to a parameter later) Pkt.WriteBEInt32(static_cast(a_X * 8.0)); @@ -1364,7 +1362,7 @@ void cProtocol_1_9_0::SendSoundParticleEffect(const EffectID a_EffectID, int a_S { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSoundParticleEffect)); // Effect packet + cPacketizer Pkt(*this, pktSoundParticleEffect); Pkt.WriteBEInt32(static_cast(a_EffectID)); Pkt.WritePosition64(a_SrcX, a_SrcY, a_SrcZ); Pkt.WriteBEInt32(a_Data); @@ -1379,7 +1377,7 @@ void cProtocol_1_9_0::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSpawnObject)); // Spawn Object packet + cPacketizer Pkt(*this, pktSpawnObject); Pkt.WriteVarInt32(a_FallingBlock.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -1405,7 +1403,7 @@ void cProtocol_1_9_0::SendSpawnMob(const cMonster & a_Mob) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSpawnMob)); // Spawn Mob packet + cPacketizer Pkt(*this, pktSpawnMob); Pkt.WriteVarInt32(a_Mob.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -1440,7 +1438,7 @@ void cProtocol_1_9_0::SendSpawnObject(const cEntity & a_Entity, char a_ObjectTyp FixItemFramePositions(a_ObjectData, PosX, PosZ, Yaw); } - cPacketizer Pkt(*this, GetPacketId(sendSpawnObject)); // Spawn Object packet + cPacketizer Pkt(*this, pktSpawnObject); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -1465,7 +1463,7 @@ void cProtocol_1_9_0::SendSpawnVehicle(const cEntity & a_Vehicle, char a_Vehicle { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSpawnObject)); // Spawn Object packet + cPacketizer Pkt(*this, pktSpawnObject); Pkt.WriteVarInt32(a_Vehicle.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -1491,7 +1489,7 @@ void cProtocol_1_9_0::SendStatistics(const cStatManager & a_Manager) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendStatistics)); // Statistics packet + cPacketizer Pkt(*this, pktStatistics); Pkt.WriteVarInt32(statCount); // TODO 2014-05-11 xdot: Optimization: Send "dirty" statistics only size_t Count = static_cast(statCount); @@ -1513,7 +1511,7 @@ void cProtocol_1_9_0::SendTabCompletionResults(const AStringVector & a_Results) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTabCompletion)); // Tab-Complete packet + cPacketizer Pkt(*this, pktTabCompletionResults); Pkt.WriteVarInt32(static_cast(a_Results.size())); for (AStringVector::const_iterator itr = a_Results.begin(), end = a_Results.end(); itr != end; ++itr) @@ -1530,7 +1528,7 @@ void cProtocol_1_9_0::SendTeleportEntity(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTeleportEntity)); // Entity teleport packet + cPacketizer Pkt(*this, pktTeleportEntity); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEDouble(a_Entity.GetPosX()); Pkt.WriteBEDouble(a_Entity.GetPosY()); @@ -1548,7 +1546,7 @@ void cProtocol_1_9_0::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSpawnGlobalEntity)); // Spawn Global Entity packet + cPacketizer Pkt(*this, pktSpawnGlobalEntity); Pkt.WriteVarInt32(0); // EntityID = 0, always Pkt.WriteBEUInt8(1); // Type = Thunderbolt Pkt.WriteBEDouble(a_BlockX); @@ -1564,9 +1562,8 @@ void cProtocol_1_9_0::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(2); // Set title display times - Pkt.WriteBEInt32(a_FadeInTicks); Pkt.WriteBEInt32(a_DisplayTicks); Pkt.WriteBEInt32(a_FadeOutTicks); @@ -1585,7 +1582,7 @@ void cProtocol_1_9_0::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a a_TimeOfDay = std::min(-a_TimeOfDay, -1LL); } - cPacketizer Pkt(*this, GetPacketId(sendTimeUpdate)); // Time update packet + cPacketizer Pkt(*this, pktTimeUpdate); Pkt.WriteBEInt64(a_WorldAge); Pkt.WriteBEInt64(a_TimeOfDay); } @@ -1598,7 +1595,7 @@ void cProtocol_1_9_0::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendUnloadChunk)); // Unload chunk packet + cPacketizer Pkt(*this, pktUnloadChunk); Pkt.WriteBEInt32(a_ChunkX); Pkt.WriteBEInt32(a_ChunkZ); } @@ -1611,9 +1608,8 @@ void cProtocol_1_9_0::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendUpdateBlockEntity)); // Update tile entity packet + cPacketizer Pkt(*this, pktUpdateBlockEntity); Pkt.WritePosition64(a_BlockEntity.GetPosX(), a_BlockEntity.GetPosY(), a_BlockEntity.GetPosZ()); - Byte Action = 0; switch (a_BlockEntity.GetBlockType()) { @@ -1638,7 +1634,7 @@ void cProtocol_1_9_0::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, c { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendUpdateSign)); // Update sign packet + cPacketizer Pkt(*this, pktUpdateSign); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Json::StyledWriter JsonWriter; @@ -1659,7 +1655,7 @@ void cProtocol_1_9_0::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_B { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendUseBed)); // Use bed + cPacketizer Pkt(*this, pktUseBed); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); } @@ -1673,7 +1669,7 @@ void cProtocol_1_9_0::SendWeather(eWeather a_Weather) ASSERT(m_State == 3); // In game mode? { - cPacketizer Pkt(*this, GetPacketId(sendWeather)); // Change Game State packet + cPacketizer Pkt(*this, pktWeather); Pkt.WriteBEUInt8((a_Weather == wSunny) ? 1 : 2); // End rain / begin rain Pkt.WriteBEFloat(0); // Unused for weather } @@ -1689,7 +1685,7 @@ void cProtocol_1_9_0::SendWholeInventory(const cWindow & a_Window) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendWindowItems)); // Window Items packet + cPacketizer Pkt(*this, pktWindowItems); Pkt.WriteBEInt8(a_Window.GetWindowID()); Pkt.WriteBEInt16(static_cast(a_Window.GetNumSlots())); cItems Slots; @@ -1708,7 +1704,7 @@ void cProtocol_1_9_0::SendWindowClose(const cWindow & a_Window) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendWindowClose)); // Close window packet + cPacketizer Pkt(*this, pktWindowClose); Pkt.WriteBEInt8(a_Window.GetWindowID()); } @@ -1726,7 +1722,7 @@ void cProtocol_1_9_0::SendWindowOpen(const cWindow & a_Window) return; } - cPacketizer Pkt(*this, GetPacketId(sendWindowOpen)); // Open window packet + cPacketizer Pkt(*this, pktWindowOpen); Pkt.WriteBEInt8(a_Window.GetWindowID()); Pkt.WriteString(a_Window.GetWindowTypeName()); Pkt.WriteString(Printf("{\"text\":\"%s\"}", a_Window.GetWindowTitle().c_str())); @@ -1762,7 +1758,7 @@ void cProtocol_1_9_0::SendWindowProperty(const cWindow & a_Window, short a_Prope { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendWindowProperty)); // Window Property packet + cPacketizer Pkt(*this, pktWindowProperty); Pkt.WriteBEInt8(a_Window.GetWindowID()); Pkt.WriteBEInt16(a_Property); Pkt.WriteBEInt16(a_Value); @@ -2118,6 +2114,91 @@ void cProtocol_1_9_0::AddReceivedData(const char * a_Data, size_t a_Size) +UInt32 cProtocol_1_9_0::GetPacketID(cProtocol::ePacketType a_Packet) +{ + switch (a_Packet) + { + case pktAttachEntity: return 0x40; + case pktBlockAction: return 0x0a; + case pktBlockBreakAnim: return 0x08; + case pktBlockChange: return 0x0b; + case pktBlockChanges: return 0x10; + case pktCameraSetTo: return 0x36; + case pktChatRaw: return 0x0f; + case pktCollectEntity: return 0x49; + case pktDestroyEntity: return 0x30; + case pktDifficulty: return 0x0d; + case pktDisconnectDuringGame: return 0x1a; + case pktDisconnectDuringLogin: return 0x0; + case pktDisplayObjective: return 0x38; + case pktEditSign: return 0x2a; + case pktEncryptionRequest: return 0x01; + case pktEntityAnimation: return 0x06; + case pktEntityEffect: return 0x4c; + case pktEntityEquipment: return 0x3c; + case pktEntityHeadLook: return 0x34; + case pktEntityLook: return 0x27; + case pktEntityMeta: return 0x39; + case pktEntityProperties: return 0x4b; + case pktEntityRelMove: return 0x25; + case pktEntityRelMoveLook: return 0x26; + case pktEntityStatus: return 0x1b; + case pktEntityVelocity: return 0x3b; + case pktExperience: return 0x3d; + case pktExplosion: return 0x1c; + case pktGameMode: return 0x1e; + case pktHeldItemChange: return 0x37; + case pktInventorySlot: return 0x16; + case pktJoinGame: return 0x23; + case pktKeepAlive: return 0x1f; + case pktLeashEntity: return 0x3a; + case pktLoginSuccess: return 0x02; + case pktMapData: return 0x24; + case pktParticleEffect: return 0x22; + case pktPingResponse: return 0x01; + case pktPlayerAbilities: return 0x2b; + case pktPlayerList: return 0x2d; + case pktPlayerMaxSpeed: return 0x4b; + case pktPlayerMoveLook: return 0x2e; + case pktPluginMessage: return 0x18; + case pktRemoveEntityEffect: return 0x31; + case pktRespawn: return 0x33; + case pktScoreboardObjective: return 0x3f; + case pktSpawnExperienceOrb: return 0x01; + case pktSpawnGlobalEntity: return 0x02; + case pktSpawnObject: return 0x00; + case pktSpawnOtherPlayer: return 0x05; + case pktSpawnPainting: return 0x04; + case pktSpawnPosition: return 0x43; + case pktSoundEffect: return 0x19; + case pktSoundParticleEffect: return 0x21; + case pktSpawnMob: return 0x03; + case pktStartCompression: return 0x03; + case pktStatistics: return 0x07; + case pktStatusResponse: return 0x00; + case pktTabCompletionResults: return 0x0e; + case pktTeleportEntity: return 0x4a; + case pktTimeUpdate: return 0x44; + case pktTitle: return 0x45; + case pktUnloadChunk: return 0x1d; + case pktUpdateBlockEntity: return 0x09; + case pktUpdateHealth: return 0x3e; + case pktUpdateScore: return 0x42; + case pktUpdateSign: return 0x46; + case pktUseBed: return 0x2f; + case pktWeather: return 0x1e; + case pktWindowClose: return 0x12; + case pktWindowItems: return 0x14; + case pktWindowOpen: return 0x13; + case pktWindowProperty: return 0x15; + } + UNREACHABLE("Unsupported outgoing packet type"); +} + + + + + bool cProtocol_1_9_0::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) { switch (m_State) @@ -2214,7 +2295,7 @@ void cProtocol_1_9_0::HandlePacketStatusPing(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, Timestamp); - cPacketizer Pkt(*this, 0x01); // Ping packet + cPacketizer Pkt(*this, pktPingResponse); Pkt.WriteBEInt64(Timestamp); } @@ -2260,7 +2341,7 @@ void cProtocol_1_9_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) Json::FastWriter Writer; AString Response = Writer.write(ResponseValue); - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); } @@ -2350,7 +2431,7 @@ void cProtocol_1_9_0::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) // If auth is required, then send the encryption request: if (Server->ShouldAuthenticate()) { - cPacketizer Pkt(*this, 0x01); + cPacketizer Pkt(*this, pktEncryptionRequest); Pkt.WriteString(Server->GetServerID()); const AString & PubKeyDer = Server->GetPublicKeyDER(); Pkt.WriteVarInt32(static_cast(PubKeyDer.size())); @@ -3364,8 +3445,8 @@ void cProtocol_1_9_0::SendPacket(cPacketizer & a_Pkt) AString Hex; ASSERT(PacketData.size() > 0); CreateHexDump(Hex, PacketData.data(), PacketData.size(), 16); - m_CommLogFile.Printf("Outgoing packet: type %d (0x%x), length %u (0x%x), state %d. Payload (incl. type):\n%s\n", - a_Pkt.GetPacketType(), a_Pkt.GetPacketType(), PacketLen, PacketLen, m_State, Hex.c_str() + m_CommLogFile.Printf("Outgoing packet: type %s (0x%02x), length %u (0x%04x), state %d. Payload (incl. type):\n%s\n", + cPacketizer::PacketTypeToStr(a_Pkt.GetPacketType()), a_Pkt.GetPacketType(), PacketLen, PacketLen, m_State, Hex ); } } @@ -4212,7 +4293,7 @@ void cProtocol_1_9_0::WriteEntityProperties(cPacketizer & a_Pkt, const cEntity & // cProtocol_1_9_1: cProtocol_1_9_1::cProtocol_1_9_1(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client, a_ServerAddress, a_ServerPort, a_State) + Super(a_Client, a_ServerAddress, a_ServerPort, a_State) { } @@ -4225,7 +4306,7 @@ void cProtocol_1_9_1::SendLogin(const cPlayer & a_Player, const cWorld & a_World // Send the Join Game packet: { cServer * Server = cRoot::Get()->GetServer(); - cPacketizer Pkt(*this, GetPacketId(sendJoinGame)); // Join Game packet + cPacketizer Pkt(*this, pktJoinGame); Pkt.WriteBEUInt32(a_Player.GetUniqueID()); Pkt.WriteBEUInt8(static_cast(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 Pkt.WriteBEInt32(static_cast(a_World.GetDimension())); // This is the change from 1.9.0 (Int8 to Int32) @@ -4237,13 +4318,13 @@ void cProtocol_1_9_1::SendLogin(const cPlayer & a_Player, const cWorld & a_World // Send the spawn position: { - cPacketizer Pkt(*this, GetPacketId(sendSpawnPosition)); // Spawn Position packet + cPacketizer Pkt(*this, pktSpawnPosition); Pkt.WritePosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ())); } // Send the server difficulty: { - cPacketizer Pkt(*this, GetPacketId(sendDifficulty)); // Server difficulty packet + cPacketizer Pkt(*this, pktDifficulty); Pkt.WriteBEInt8(1); } @@ -4293,7 +4374,7 @@ void cProtocol_1_9_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) Json::FastWriter Writer; AString Response = Writer.write(ResponseValue); - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); } @@ -4305,7 +4386,7 @@ void cProtocol_1_9_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) // cProtocol_1_9_2: cProtocol_1_9_2::cProtocol_1_9_2(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client, a_ServerAddress, a_ServerPort, a_State) + Super(a_Client, a_ServerAddress, a_ServerPort, a_State) { } @@ -4351,7 +4432,7 @@ void cProtocol_1_9_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) Json::FastWriter Writer; AString Response = Writer.write(ResponseValue); - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); } @@ -4363,7 +4444,7 @@ void cProtocol_1_9_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) // cProtocol_1_9_4: cProtocol_1_9_4::cProtocol_1_9_4(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client, a_ServerAddress, a_ServerPort, a_State) + Super(a_Client, a_ServerAddress, a_ServerPort, a_State) { } @@ -4409,7 +4490,7 @@ void cProtocol_1_9_4::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) Json::FastWriter Writer; AString Response = Writer.write(ResponseValue); - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); } @@ -4438,7 +4519,7 @@ void cProtocol_1_9_4::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, c ASSERT(m_State == 3); // In game mode? // 1.9.4 removed the update sign packet and now uses Update Block Entity - cPacketizer Pkt(*this, 0x09); // Update tile entity packet + cPacketizer Pkt(*this, pktUpdateBlockEntity); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Pkt.WriteBEUInt8(9); // Action 9 - update sign @@ -4465,3 +4546,21 @@ void cProtocol_1_9_4::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, c Writer.Finish(); Pkt.WriteBuf(Writer.GetResult().data(), Writer.GetResult().size()); } + + + + + +UInt32 cProtocol_1_9_4::GetPacketID(cProtocol::ePacketType a_Packet) +{ + switch (a_Packet) + { + case pktCollectEntity: return 0x48; + case pktEntityEffect: return 0x4b; + case pktEntityProperties: return 0x4a; + case pktPlayerMaxSpeed: return 0x4a; + case pktTeleportEntity: return 0x49; + + default: return Super::GetPacketID(a_Packet); + } +} -- cgit v1.2.3