From c7132a309190ba3480c59dfb76bd8d354f12b4b3 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 10 Sep 2019 19:33:05 +0200 Subject: Protocol 1.9: Alpha-sort, add useful debugging code. --- src/Protocol/Protocol_1_9.cpp | 81 ++++++++++++++++++++++++------------------- src/Protocol/Protocol_1_9.h | 4 +-- 2 files changed, 47 insertions(+), 38 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 29d8b1c34..4bf358567 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -592,6 +592,37 @@ void cProtocol_1_9_0::SendEntityVelocity(const cEntity & a_Entity) +void cProtocol_1_9_0::SendExperience(void) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, pktExperience); + cPlayer * Player = m_Client->GetPlayer(); + Pkt.WriteBEFloat(Player->GetXpPercentage()); + Pkt.WriteVarInt32(static_cast(Player->GetXpLevel())); + Pkt.WriteVarInt32(static_cast(Player->GetCurrentXp())); +} + + + + + +void cProtocol_1_9_0::SendExperienceOrb(const cExpOrb & a_ExpOrb) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, pktSpawnExperienceOrb); + Pkt.WriteVarInt32(a_ExpOrb.GetUniqueID()); + Pkt.WriteBEDouble(a_ExpOrb.GetPosX()); + Pkt.WriteBEDouble(a_ExpOrb.GetPosY()); + Pkt.WriteBEDouble(a_ExpOrb.GetPosZ()); + Pkt.WriteBEInt16(static_cast(a_ExpOrb.GetReward())); +} + + + + + void cProtocol_1_9_0::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) { ASSERT(m_State == 3); // In game mode? @@ -1215,37 +1246,6 @@ void cProtocol_1_9_0::SendRespawn(eDimension a_Dimension) -void cProtocol_1_9_0::SendExperience(void) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, pktExperience); - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEFloat(Player->GetXpPercentage()); - Pkt.WriteVarInt32(static_cast(Player->GetXpLevel())); - Pkt.WriteVarInt32(static_cast(Player->GetCurrentXp())); -} - - - - - -void cProtocol_1_9_0::SendExperienceOrb(const cExpOrb & a_ExpOrb) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, pktSpawnExperienceOrb); - Pkt.WriteVarInt32(a_ExpOrb.GetUniqueID()); - Pkt.WriteBEDouble(a_ExpOrb.GetPosX()); - Pkt.WriteBEDouble(a_ExpOrb.GetPosY()); - Pkt.WriteBEDouble(a_ExpOrb.GetPosZ()); - Pkt.WriteBEInt16(static_cast(a_ExpOrb.GetReward())); -} - - - - - void cProtocol_1_9_0::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) { ASSERT(m_State == 3); // In game mode? @@ -3392,9 +3392,6 @@ eHand cProtocol_1_9_0::HandIntToEnum(Int32 a_Hand) -//////////////////////////////////////////////////////////////////////////////// -// cProtocol_1_9_0::cPacketizer: - void cProtocol_1_9_0::SendPacket(cPacketizer & a_Pkt) { UInt32 PacketLen = static_cast(m_OutPacketBuffer.GetUsedSpace()); @@ -3445,10 +3442,22 @@ 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 %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 + m_CommLogFile.Printf("Outgoing packet: type %s (translated to 0x%02x), length %u (0x%04x), state %d. Payload (incl. type):\n%s\n", + cPacketizer::PacketTypeToStr(a_Pkt.GetPacketType()), GetPacketID(a_Pkt.GetPacketType()), + PacketLen, PacketLen, m_State, Hex + ); + /* + // Useful for debugging a new protocol: + LOGD("Outgoing packet: type %s (translated to 0x%02x), length %u (0x%04x), state %d. Payload (incl. type):\n%s\n", + cPacketizer::PacketTypeToStr(a_Pkt.GetPacketType()), GetPacketID(a_Pkt.GetPacketType()), + PacketLen, PacketLen, m_State, Hex ); + //*/ } + /* + // Useful for debugging a new protocol: + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + */ } diff --git a/src/Protocol/Protocol_1_9.h b/src/Protocol/Protocol_1_9.h index 681035d80..793367734 100644 --- a/src/Protocol/Protocol_1_9.h +++ b/src/Protocol/Protocol_1_9.h @@ -67,6 +67,8 @@ public: virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override; virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override; virtual void SendEntityVelocity (const cEntity & a_Entity) override; + virtual void SendExperience (void) override; + virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; @@ -98,8 +100,6 @@ public: virtual void SendResetTitle (void) override; virtual void SendRespawn (eDimension a_Dimension) override; virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override; - virtual void SendExperience (void) override; - virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override; virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override; -- cgit v1.2.3