diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ClientAction.h | 33 | ||||
-rw-r--r-- | src/ClientHandle.cpp | 39 | ||||
-rw-r--r-- | src/Entities/Player.cpp | 4 | ||||
-rw-r--r-- | src/Entities/Player.h | 9 | ||||
-rw-r--r-- | src/Protocol/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/Protocol/Protocol.cpp | 87 | ||||
-rw-r--r-- | src/Protocol/Protocol.h | 47 | ||||
-rw-r--r-- | src/Protocol/Protocol17x.cpp | 524 | ||||
-rw-r--r-- | src/Protocol/Protocol17x.h | 85 | ||||
-rw-r--r-- | src/Protocol/Protocol18x.cpp | 10 | ||||
-rw-r--r-- | src/Protocol/Protocol18x.h | 23 | ||||
-rw-r--r-- | src/Protocol/ProtocolRecognizer.cpp | 4 | ||||
-rw-r--r-- | src/Protocol/ProtocolRecognizer.h | 20 | ||||
-rw-r--r-- | src/UI/SlotArea.cpp | 18 | ||||
-rw-r--r-- | src/UI/SlotArea.h | 20 | ||||
-rw-r--r-- | src/UI/Window.cpp | 2 | ||||
-rw-r--r-- | src/UI/Window.h | 2 |
17 files changed, 446 insertions, 484 deletions
diff --git a/src/ClientAction.h b/src/ClientAction.h index 444cf7f3d..d07d9a07b 100644 --- a/src/ClientAction.h +++ b/src/ClientAction.h @@ -1,4 +1,37 @@ +#pragma once + class cClientAction { +public: + enum class Type + { + StatusRequest, + StatusPing, + LoginStart, + LoginConfirmation, + Animation, + LeftClick, + RightClick, + Chat, + SetLocale, + SetViewDistance, + Respawn, + StatsRequest, + Achivement, + CreativeInventory + }; + + cClientAction(Type a_Type) : m_Type(a_Type) {} + + Type GetType() const { return m_Type; } + +private: + Type m_Type; +}; + +class cSimpleAction : public cClientAction +{ +public: + cSimpleAction(Type a_type) : cClientAction(a_type) {} }; diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index c8cd4a98e..e54b73db3 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -331,7 +331,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, } // Send login success (if the protocol supports it): - m_Protocol->SendLoginSuccess(); + m_Protocol->SendLoginSuccess(GetUUID(), GetUsername()); // Spawn player (only serversided, so data is loaded) m_Player = new cPlayer(m_Self, GetUsername()); @@ -371,7 +371,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, m_Protocol->SendTimeUpdate(World->GetWorldAge(), World->GetTimeOfDay(), World->IsDaylightCycleEnabled()); // Send contents of the inventory window - m_Protocol->SendWholeInventory(*m_Player->GetWindow()); + m_Protocol->SendWholeInventory(*m_Player, *m_Player->GetWindow()); // Send health m_Player->SendHealth(); @@ -1859,7 +1859,8 @@ bool cClientHandle::CheckBlockInteractionsRate(void) } - +//reminds me to come back later +void undefined(void *); void cClientHandle::Tick(float a_Dt) @@ -1872,7 +1873,9 @@ void cClientHandle::Tick(float a_Dt) } if (!IncomingData.empty()) { - m_Protocol->DataReceived(IncomingData.data(), IncomingData.size()); + std::vector<std::unique_ptr<cClientAction>> Actions; + auto success = m_Protocol->DataReceived(IncomingData.data(), IncomingData.size(), Actions); + undefined(&success); } // Send any queued outgoing data: @@ -1905,7 +1908,7 @@ void cClientHandle::Tick(float a_Dt) // If the chunk the player's in was just sent, spawn the player: if (m_HasSentPlayerChunk && (m_State == csDownloadingWorld)) { - m_Protocol->SendPlayerMoveLook(); + m_Protocol->SendPlayerMoveLook(*m_Player); m_State = csPlaying; } @@ -1974,7 +1977,9 @@ void cClientHandle::ServerTick(float a_Dt) } if (!IncomingData.empty()) { - m_Protocol->DataReceived(IncomingData.data(), IncomingData.size()); + std::vector<std::unique_ptr<cClientAction>> Actions; + auto success = m_Protocol->DataReceived(IncomingData.data(), IncomingData.size(), Actions); + undefined(&success); } // Send any queued outgoing data: @@ -2389,7 +2394,7 @@ void cClientHandle::SendGameMode(eGameMode a_GameMode) void cClientHandle::SendHealth(void) { - m_Protocol->SendHealth(); + m_Protocol->SendHealth(m_Player->GetHealth(), m_Player->GetFoodLevel(), m_Player->GetFoodSaturationLevel()); } @@ -2469,7 +2474,7 @@ void cClientHandle::SendEntityAnimation(const cEntity & a_Entity, char a_Animati void cClientHandle::SendPlayerAbilities() { - m_Protocol->SendPlayerAbilities(); + m_Protocol->SendPlayerAbilities(*m_Player); } @@ -2523,7 +2528,7 @@ void cClientHandle::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, co void cClientHandle::SendPlayerMaxSpeed(void) { - m_Protocol->SendPlayerMaxSpeed(); + m_Protocol->SendPlayerMaxSpeed(*m_Player); } @@ -2537,7 +2542,7 @@ void cClientHandle::SendPlayerMoveLook(void) m_Player->GetPosX(), m_Player->GetPosY(), m_Player->GetPosZ(), m_Player->GetStance(), m_Player->IsOnGround() ? 1 : 0 ); */ - m_Protocol->SendPlayerMoveLook(); + m_Protocol->SendPlayerMoveLook(*m_Player); } @@ -2546,7 +2551,7 @@ void cClientHandle::SendPlayerMoveLook(void) void cClientHandle::SendPlayerPosition(void) { - m_Protocol->SendPlayerPosition(); + m_Protocol->SendPlayerPosition(*m_Player); } @@ -2601,7 +2606,7 @@ void cClientHandle::SendResetTitle() void cClientHandle::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) { - m_Protocol->SendRespawn(a_Dimension, a_ShouldIgnoreDimensionChecks); + m_Protocol->SendRespawn(m_Player->GetEffectiveGameMode(), a_Dimension, a_ShouldIgnoreDimensionChecks); } @@ -2610,7 +2615,7 @@ void cClientHandle::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimen void cClientHandle::SendExperience(void) { - m_Protocol->SendExperience(); + m_Protocol->SendExperience(*m_Player); } @@ -2854,7 +2859,7 @@ void cClientHandle::SendWeather(eWeather a_Weather) void cClientHandle::SendWholeInventory(const cWindow & a_Window) { - m_Protocol->SendWholeInventory(a_Window); + m_Protocol->SendWholeInventory(*m_Player, a_Window); } @@ -2965,10 +2970,10 @@ void cClientHandle::AddWantedChunk(int a_ChunkX, int a_ChunkZ) - +#if 0 void cClientHandle::PacketBufferFull(void) { - #error + undefined(nullptr); // Too much data in the incoming queue, the server is probably too busy, kick the client: LOGERROR("Too much data in queue for client \"%s\" @ %s, kicking them.", m_Username.c_str(), m_IPString.c_str()); SendDisconnect("Server busy"); @@ -3082,7 +3087,7 @@ void cClientHandle::OnError(int a_ErrorCode, const AString & a_ErrorMsg) } SocketClosed(); } - +#endif diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 33ded6ab9..1c2432fc5 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -328,7 +328,7 @@ int cPlayer::XpForLevel(int a_Level) -int cPlayer::GetXpLevel() +int cPlayer::GetXpLevel() const { return CalcLevelFromXp(m_CurrentXp); } @@ -337,7 +337,7 @@ int cPlayer::GetXpLevel() -float cPlayer::GetXpPercentage() +float cPlayer::GetXpPercentage() const { int currentLevel = CalcLevelFromXp(m_CurrentXp); int currentLevel_XpBase = XpForLevel(currentLevel); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index bff9599f7..d33e40445 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -81,16 +81,16 @@ public: int DeltaExperience(int a_Xp_delta); /** Gets the experience total - XpTotal for score on death */ - inline int GetXpLifetimeTotal(void) { return m_LifetimeTotalXp; } + inline int GetXpLifetimeTotal(void) const { return m_LifetimeTotalXp; } /** Gets the current experience */ - inline int GetCurrentXp(void) { return m_CurrentXp; } + inline int GetCurrentXp(void) const { return m_CurrentXp; } /** Gets the current level - XpLevel */ - int GetXpLevel(void); + int GetXpLevel(void) const; /** Gets the experience bar percentage - XpP */ - float GetXpPercentage(void); + float GetXpPercentage(void) const; /** Calculates the amount of XP needed for a given level Ref: http://minecraft.gamepedia.com/XP @@ -128,6 +128,7 @@ public: /** Gets the contents of the player's associated enderchest */ cItemGrid & GetEnderChestContents(void) { return m_EnderChestContents; } + const cItemGrid & GetEnderChestContents(void) const { return m_EnderChestContents; } inline const cItem & GetEquippedItem(void) const { return GetInventory().GetEquippedItem(); } // tolua_export diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index e70dcbd57..3bbef197a 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -7,9 +7,9 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") SET (SRCS Authenticator.cpp ChunkDataSerializer.cpp + LengthenedProtocol.cpp MojangAPI.cpp Packetizer.cpp - Protocol.cpp Protocol17x.cpp Protocol18x.cpp ProtocolRecognizer.cpp @@ -18,6 +18,7 @@ SET (SRCS SET (HDRS Authenticator.h ChunkDataSerializer.h + LengthenedProtocol.h MojangAPI.h Packetizer.h Protocol.h diff --git a/src/Protocol/Protocol.cpp b/src/Protocol/Protocol.cpp deleted file mode 100644 index 2c8491a0b..000000000 --- a/src/Protocol/Protocol.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "Globals.h" -#include "Protocol.h" - -cProtocol::cProtocolError cProtocol::DataReceived(const char * a_Data, size_t a_Size, std::vector<std::unique_ptr<cClientAction>> & a_Actions) -{ - a_Actions.clear(); - if (m_IsEncrypted) - { - ASSERT((a_Size % 16) == 0); // AES requirement. - Byte Decrypted[512]; - while (a_Size > 0) - { - size_t NumBytes = (a_Size > sizeof(Decrypted)) ? sizeof(Decrypted) : a_Size; - m_Decryptor.ProcessData(Decrypted, reinterpret_cast<const Byte *>(a_Data), NumBytes); - auto success = AddReceivedData(reinterpret_cast<const char *>(Decrypted), NumBytes, a_Actions); - if (success != cProtocolError::Success) - { - return success; - } - a_Size -= NumBytes; - a_Data += NumBytes; - } - return cProtocolError::Success; - } - else - { - return AddReceivedData(a_Data, a_Size, a_Actions); - } -} - -cProtocol::cProtocolError cProtocol::AddReceivedData(const char * a_Data, size_t a_Size, std::vector<std::unique_ptr<cClientAction>> & a_Actions) -{ - // Write the incoming data into the comm log file: - if (g_ShouldLogCommIn) - { - if (m_ReceivedData.GetReadableSpace() > 0) - { - AString AllData; - size_t OldReadableSpace = m_ReceivedData.GetReadableSpace(); - m_ReceivedData.ReadAll(AllData); - m_ReceivedData.ResetRead(); - m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace); - ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); - AString Hex; - CreateHexDump(Hex, AllData.data(), AllData.size(), 16); - m_CommLogFile.Printf("Incoming data, " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") unparsed bytes already present in buffer:\n%s\n", - AllData.size(), AllData.size(), Hex.c_str() - ); - } - AString Hex; - CreateHexDump(Hex, a_Data, a_Size, 16); - m_CommLogFile.Printf("Incoming data: %u (0x%x) bytes: \n%s\n", - static_cast<unsigned>(a_Size), static_cast<unsigned>(a_Size), Hex.c_str() - ); - m_CommLogFile.Flush(); - } - - if (!m_ReceivedData.Write(a_Data, a_Size)) - { - return cProtocolError::BufferFull; - } - - auto status = OnDataAddedToBuffer(m_ReceivedData, a_Actions); - if (status != cProtocolError::Success) - { - return status; - } - - - // Log any leftover bytes into the logfile: - if (g_ShouldLogCommIn && (m_ReceivedData.GetReadableSpace() > 0)) - { - AString AllData; - size_t OldReadableSpace = m_ReceivedData.GetReadableSpace(); - m_ReceivedData.ReadAll(AllData); - m_ReceivedData.ResetRead(); - m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace); - ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); - AString Hex; - CreateHexDump(Hex, AllData.data(), AllData.size(), 16); - m_CommLogFile.Printf("There are " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") bytes of non-parse-able data left in the buffer:\n%s", - m_ReceivedData.GetReadableSpace(), m_ReceivedData.GetReadableSpace(), Hex.c_str() - ); - m_CommLogFile.Flush(); - } - return cProtocolError::Success; -} diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 775c7354c..675302c1d 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -65,15 +65,19 @@ public: { Success, BufferFull, - PacketError + PacketError, + PacketUnknown, + // The packet was unreadble + PacketReadError, + // One of the values read out of the packet was invalid. + // We send a kick packet in response to a process error + PacketProcessError }; - cProtocol(cClientHandle * a_Client, AString a_LogID) : - m_Client(a_Client), + cProtocol(AString a_LogID) : m_OutPacketBuffer(64 KiB), m_OutPacketLenBuffer(20), // 20 bytes is more than enough for one VarInt - m_IsEncrypted(false), - m_ReceivedData(32 KiB) + m_IsEncrypted(false) { // Create the comm log file, if so requested: if (g_ShouldLogCommIn || g_ShouldLogCommOut) @@ -88,7 +92,7 @@ public: virtual ~cProtocol() {} /** Called when client sends some data, a_Actions is cleared before being filled */ - cProtocolError DataReceived(const char * a_Data, size_t a_Size, std::vector<std::unique_ptr<cClientAction>> & a_Actions) WARN_UNUSED; + virtual cProtocolError DataReceived(const char * a_Data, size_t a_Size, std::vector<std::unique_ptr<cClientAction>> & a_Actions) WARN_UNUSED = 0; // Sending stuff to clients (alphabetically sorted): virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) = 0; @@ -115,16 +119,16 @@ public: virtual void SendEntityVelocity (const cEntity & a_Entity) = 0; virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) = 0; virtual void SendGameMode (eGameMode a_GameMode) = 0; - virtual void SendHealth (void) = 0; + virtual void SendHealth (int a_Health, int a_FoodLevel, double a_FoodSaturationLevel) = 0; virtual void SendHideTitle (void) = 0; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0; virtual void SendKeepAlive (UInt32 a_PingID) = 0; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0; - virtual void SendLoginSuccess (void) = 0; + virtual void SendLoginSuccess (const AString & a_UUID, const AString & a_Username) = 0; virtual void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY) = 0; virtual void SendPaintingSpawn (const cPainting & a_Painting) = 0; virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0; - virtual void SendPlayerAbilities (void) = 0; + virtual void SendPlayerAbilities (const cPlayer & a_Player) = 0; virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) = 0; virtual void SendParticleEffect (const AString & a_SoundName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) = 0; virtual void SendParticleEffect (const AString & a_SoundName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> a_Data) = 0; @@ -133,15 +137,15 @@ public: virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) = 0; virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) = 0; virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) = 0; - virtual void SendPlayerMaxSpeed (void) = 0; ///< Informs the client of the maximum player speed (1.6.1+) - virtual void SendPlayerMoveLook (void) = 0; - virtual void SendPlayerPosition (void) = 0; + virtual void SendPlayerMaxSpeed (const cPlayer & a_Player) = 0; ///< Informs the client of the maximum player speed (1.6.1+) + virtual void SendPlayerMoveLook (const cPlayer & a_Player) = 0; + virtual void SendPlayerPosition (const cPlayer & a_Player) = 0; virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) = 0; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) = 0; virtual void SendResetTitle (void) = 0; - virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) = 0; - virtual void SendExperience (void) = 0; + virtual void SendRespawn (eGameMode a_GameMode, eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) = 0; + virtual void SendExperience (const cPlayer & a_Player) = 0; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) = 0; virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) = 0; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) = 0; @@ -167,7 +171,7 @@ public: virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) = 0; virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) = 0; virtual void SendWeather (eWeather a_Weather) = 0; - virtual void SendWholeInventory (const cWindow & a_Window) = 0; + virtual void SendWholeInventory (const cPlayer & a_Player, const cWindow & a_Window) = 0; virtual void SendWindowClose (const cWindow & a_Window) = 0; virtual void SendWindowOpen (const cWindow & a_Window) = 0; virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) = 0; @@ -178,8 +182,6 @@ public: protected: friend class cPacketizer; - cClientHandle * m_Client; - /** Provides synchronization for sending the entire packet at once. Each SendXYZ() function must acquire this CS in order to send the whole packet at once. Automated via cPacketizer class. */ @@ -204,19 +206,8 @@ protected: The cPacketizer's destructor calls this to send the contained packet; protocol may transform the data (compression in 1.8 etc). */ virtual void SendPacket(cPacketizer & a_Packet) = 0; - /** This method should append the actions from incoming packets to a_Action */ - virtual cProtocolError OnDataAddedToBuffer(cByteBuffer & a_Buffer, std::vector<std::unique_ptr<cClientAction>> & a_Action) WARN_UNUSED = 0; - /** The logfile where the comm is logged, when g_ShouldLogComm is true */ cFile m_CommLogFile; - -private: - - /** Buffer for the received data */ - cByteBuffer m_ReceivedData; - - /** Adds the received (unencrypted) data to m_ReceivedData, parses complete packets, appends to a_Actions */ - cProtocolError AddReceivedData(const char * a_Data, size_t a_Size, std::vector<std::unique_ptr<cClientAction>> & a_Actions) WARN_UNUSED; } ; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 586efdd85..873efa075 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -52,18 +52,7 @@ Implements the 1.7.x protocol classes: /** The slot number that the client uses to indicate "outside the window". */ -static const Int16 SLOT_NUM_OUTSIDE = -999; - - - - - -#define HANDLE_READ(ByteBuf, Proc, Type, Var) \ - Type Var; \ - if (!ByteBuf.Proc(Var))\ - {\ - return;\ - } +//static const Int16 SLOT_NUM_OUTSIDE = -999; @@ -75,7 +64,7 @@ static const Int16 SLOT_NUM_OUTSIDE = -999; if (!ByteBuf.Proc(Var)) \ { \ ByteBuf.CheckValid(); \ - return false; \ + return cProtocolError::PacketReadError; \ } \ ByteBuf.CheckValid(); \ } @@ -99,9 +88,9 @@ extern bool g_ShouldLogCommIn, g_ShouldLogCommOut; //////////////////////////////////////////////////////////////////////////////// // cProtocol172: - +/* cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client, a_Client->GetIPString()), + super(a_Client->GetIPString()), m_ServerAddress(a_ServerAddress), m_ServerPort(a_ServerPort), m_State(a_State), @@ -115,12 +104,12 @@ cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAdd { LOGD("Player at %s connected via BungeeCord", Params[1].c_str()); m_ServerAddress = Params[0]; - m_Client->SetIPString(Params[1]); - m_Client->SetUUID(cMojangAPI::MakeUUIDShort(Params[2])); - m_Client->SetProperties(Params[3]); + a_Client->SetIPString(Params[1]); + a_Client->SetUUID(cMojangAPI::MakeUUIDShort(Params[2])); + a_Client->SetProperties(Params[3]); } } - +*/ @@ -513,15 +502,14 @@ void cProtocol172::SendGameMode(eGameMode a_GameMode) -void cProtocol172::SendHealth(void) +void cProtocol172::SendHealth(int a_Health, int a_FoodLevel, double a_FoodSaturationLevel) { ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, 0x06); // Update Health packet - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEFloat(static_cast<float>(Player->GetHealth())); - Pkt.WriteBEInt16(static_cast<short>(Player->GetFoodLevel())); - Pkt.WriteBEFloat(static_cast<float>(Player->GetFoodSaturationLevel())); + Pkt.WriteBEFloat(static_cast<float>(a_Health)); + Pkt.WriteBEInt16(static_cast<short>(a_FoodLevel)); + Pkt.WriteBEFloat(static_cast<float>(a_FoodSaturationLevel)); } @@ -592,20 +580,20 @@ void cProtocol172::SendLogin(const cPlayer & a_Player, const cWorld & a_World) } // Send player abilities: - SendPlayerAbilities(); + SendPlayerAbilities(a_Player); } -void cProtocol172::SendLoginSuccess(void) +void cProtocol172::SendLoginSuccess(const AString & a_UUID, const AString & a_Username) { ASSERT(m_State == 2); // State: login? { cPacketizer Pkt(*this, 0x02); // Login success packet - Pkt.WriteString(cMojangAPI::MakeUUIDDashed(m_Client->GetUUID())); - Pkt.WriteString(m_Client->GetUsername()); + Pkt.WriteString(cMojangAPI::MakeUUIDDashed(a_UUID)); + Pkt.WriteString(a_Username); } m_State = 3; // State = Game @@ -715,29 +703,28 @@ void cProtocol172::SendPickupSpawn(const cPickup & a_Pickup) -void cProtocol172::SendPlayerAbilities(void) +void cProtocol172::SendPlayerAbilities(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, 0x39); // Player Abilities packet Byte Flags = 0; - cPlayer * Player = m_Client->GetPlayer(); - if (Player->IsGameModeCreative()) + if (a_Player.IsGameModeCreative()) { Flags |= 0x01; Flags |= 0x08; // Godmode, used for creative } - if (Player->IsFlying()) + if (a_Player.IsFlying()) { Flags |= 0x02; } - if (Player->CanFly()) + if (a_Player.CanFly()) { Flags |= 0x04; } Pkt.WriteBEUInt8(Flags); - Pkt.WriteBEFloat(static_cast<float>(0.05 * Player->GetFlyingMaxSpeed())); - Pkt.WriteBEFloat(static_cast<float>(0.1 * Player->GetNormalMaxSpeed())); + Pkt.WriteBEFloat(static_cast<float>(0.05 * a_Player.GetFlyingMaxSpeed())); + Pkt.WriteBEFloat(static_cast<float>(0.1 * a_Player.GetNormalMaxSpeed())); } @@ -846,23 +833,22 @@ void cProtocol172::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, con -void cProtocol172::SendPlayerMaxSpeed(void) +void cProtocol172::SendPlayerMaxSpeed(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, 0x20); // Entity Properties - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEUInt32(Player->GetUniqueID()); + Pkt.WriteBEUInt32(a_Player.GetUniqueID()); Pkt.WriteBEInt32(1); // Count Pkt.WriteString("generic.movementSpeed"); // The default game speed is 0.1, multiply that value by the relative speed: - Pkt.WriteBEDouble(0.1 * Player->GetNormalMaxSpeed()); - if (Player->IsSprinting()) + Pkt.WriteBEDouble(0.1 * a_Player.GetNormalMaxSpeed()); + if (a_Player.IsSprinting()) { Pkt.WriteBEInt16(1); // Modifier count Pkt.WriteBEUInt64(0x662a6b8dda3e4c1c); Pkt.WriteBEUInt64(0x881396ea6097278d); // UUID of the modifier - Pkt.WriteBEDouble(Player->GetSprintingMaxSpeed() - Player->GetNormalMaxSpeed()); + Pkt.WriteBEDouble(a_Player.GetSprintingMaxSpeed() - a_Player.GetNormalMaxSpeed()); Pkt.WriteBEUInt8(2); } else @@ -875,32 +861,31 @@ void cProtocol172::SendPlayerMaxSpeed(void) -void cProtocol172::SendPlayerMoveLook(void) +void cProtocol172::SendPlayerMoveLook(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, 0x08); // Player Position And Look packet - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEDouble(Player->GetPosX()); + Pkt.WriteBEDouble(a_Player.GetPosX()); // Protocol docs say this is PosY, but #323 says this is eye-pos // Moreover, the "+ 0.001" is there because otherwise the player falls through the block they were standing on. - Pkt.WriteBEDouble(Player->GetStance() + 0.001); + Pkt.WriteBEDouble(a_Player.GetStance() + 0.001); - Pkt.WriteBEDouble(Player->GetPosZ()); - Pkt.WriteBEFloat(static_cast<float>(Player->GetYaw())); - Pkt.WriteBEFloat(static_cast<float>(Player->GetPitch())); - Pkt.WriteBool(Player->IsOnGround()); + Pkt.WriteBEDouble(a_Player.GetPosZ()); + Pkt.WriteBEFloat(static_cast<float>(a_Player.GetYaw())); + Pkt.WriteBEFloat(static_cast<float>(a_Player.GetPitch())); + Pkt.WriteBool(a_Player.IsOnGround()); } -void cProtocol172::SendPlayerPosition(void) +void cProtocol172::SendPlayerPosition(const cPlayer & a_Player) { // There is no dedicated packet for this, send the whole thing: - SendPlayerMoveLook(); + SendPlayerMoveLook(a_Player); } @@ -977,7 +962,7 @@ void cProtocol172::SendResetTitle(void) -void cProtocol172::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) +void cProtocol172::SendRespawn(eGameMode a_GameMode, eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) { if ((m_LastSentDimension == a_Dimension) && !a_ShouldIgnoreDimensionChecks) { @@ -986,10 +971,9 @@ void cProtocol172::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimens } cPacketizer Pkt(*this, 0x07); // Respawn packet - cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEInt32(static_cast<int>(a_Dimension)); Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal) - Pkt.WriteBEUInt8(static_cast<Byte>(Player->GetEffectiveGameMode())); + Pkt.WriteBEUInt8(static_cast<Byte>(a_GameMode)); Pkt.WriteString("default"); m_LastSentDimension = a_Dimension; } @@ -998,15 +982,14 @@ void cProtocol172::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimens -void cProtocol172::SendExperience (void) +void cProtocol172::SendExperience (const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, 0x1f); // Experience Packet - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEFloat(Player->GetXpPercentage()); - Pkt.WriteBEInt16(static_cast<Int16>(std::min<int>(Player->GetXpLevel(), std::numeric_limits<Int16>::max()))); - Pkt.WriteBEInt16(static_cast<Int16>(std::min<int>(Player->GetCurrentXp(), std::numeric_limits<Int16>::max()))); + Pkt.WriteBEFloat(a_Player.GetXpPercentage()); + Pkt.WriteBEInt16(static_cast<Int16>(std::min<int>(a_Player.GetXpLevel(), std::numeric_limits<Int16>::max()))); + Pkt.WriteBEInt16(static_cast<Int16>(std::min<int>(a_Player.GetCurrentXp(), std::numeric_limits<Int16>::max()))); } @@ -1439,7 +1422,7 @@ void cProtocol172::SendWeather(eWeather a_Weather) -void cProtocol172::SendWholeInventory(const cWindow & a_Window) +void cProtocol172::SendWholeInventory(const cPlayer & a_Player, const cWindow & a_Window) { ASSERT(m_State == 3); // In game mode? @@ -1447,7 +1430,7 @@ void cProtocol172::SendWholeInventory(const cWindow & a_Window) Pkt.WriteBEInt8(a_Window.GetWindowID()); Pkt.WriteBEInt16(static_cast<short>(a_Window.GetNumSlots())); cItems Slots; - a_Window.GetSlots(*(m_Client->GetPlayer()), Slots); + a_Window.GetSlots(a_Player, Slots); for (cItems::const_iterator itr = Slots.begin(), end = Slots.end(); itr != end; ++itr) { WriteItem(Pkt, *itr); @@ -1558,8 +1541,13 @@ cProtocol::cProtocolError cProtocol172::OnDataAddedToBuffer(cByteBuffer & a_Buff ); } - if (!HandlePacket(bb, PacketType)) + auto success = HandlePacket(bb, PacketType, a_Action); + if (success != cProtocolError::Success) { + if (success != cProtocolError::PacketUnknown) + { + return success; + } // Unknown packet, already been reported, but without the length. Log the length here: LOGWARNING("Unhandled packet: type 0x%x, state %d, length %u", PacketType, m_State, PacketLen); @@ -1580,7 +1568,7 @@ cProtocol::cProtocolError cProtocol172::OnDataAddedToBuffer(cByteBuffer & a_Buff m_CommLogFile.Printf("^^^^^^ Unhandled packet ^^^^^^\n\n\n"); } - return cProtocolError::PacketError; + return cProtocolError::PacketUnknown; } if (bb.GetReadableSpace() != 1) @@ -1607,9 +1595,13 @@ cProtocol::cProtocolError cProtocol172::OnDataAddedToBuffer(cByteBuffer & a_Buff } +#define HANDLE_PACKET(Num, Name) \ + case Num: \ + { \ + return HandlePacket##Name(a_ByteBuffer, a_Action); \ + } - -bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) +cProtocol::cProtocolError cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType, ActionList & a_Action) { switch (m_State) { @@ -1618,10 +1610,13 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) // Status switch (a_PacketType) { - case 0x00: HandlePacketStatusRequest(a_ByteBuffer); return true; - case 0x01: HandlePacketStatusPing (a_ByteBuffer); return true; + HANDLE_PACKET(0x00, StatusRequest); + HANDLE_PACKET(0x01, StatusPing); + default: + { + return cProtocolError::PacketUnknown; + } } - break; } case 2: @@ -1629,10 +1624,13 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) // Login switch (a_PacketType) { - case 0x00: HandlePacketLoginStart (a_ByteBuffer); return true; - case 0x01: HandlePacketLoginEncryptionResponse(a_ByteBuffer); return true; + HANDLE_PACKET(0x00, LoginStart); + HANDLE_PACKET(0x01, LoginEncryptionResponse); + default: + { + return cProtocolError::PacketUnknown; + } } - break; } case 3: @@ -1640,32 +1638,31 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) // Game switch (a_PacketType) { - case 0x00: HandlePacketKeepAlive (a_ByteBuffer); return true; - case 0x01: HandlePacketChatMessage (a_ByteBuffer); return true; - case 0x02: HandlePacketUseEntity (a_ByteBuffer); return true; - case 0x03: HandlePacketPlayer (a_ByteBuffer); return true; - case 0x04: HandlePacketPlayerPos (a_ByteBuffer); return true; - case 0x05: HandlePacketPlayerLook (a_ByteBuffer); return true; - case 0x06: HandlePacketPlayerPosLook (a_ByteBuffer); return true; - case 0x07: HandlePacketBlockDig (a_ByteBuffer); return true; - case 0x08: HandlePacketBlockPlace (a_ByteBuffer); return true; - case 0x09: HandlePacketSlotSelect (a_ByteBuffer); return true; - case 0x0a: HandlePacketAnimation (a_ByteBuffer); return true; - case 0x0b: HandlePacketEntityAction (a_ByteBuffer); return true; - case 0x0c: HandlePacketSteerVehicle (a_ByteBuffer); return true; - case 0x0d: HandlePacketWindowClose (a_ByteBuffer); return true; - case 0x0e: HandlePacketWindowClick (a_ByteBuffer); return true; - case 0x0f: // Confirm transaction - not used in MCS - case 0x10: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true; - case 0x11: HandlePacketEnchantItem (a_ByteBuffer); return true; - case 0x12: HandlePacketUpdateSign (a_ByteBuffer); return true; - case 0x13: HandlePacketPlayerAbilities (a_ByteBuffer); return true; - case 0x14: HandlePacketTabComplete (a_ByteBuffer); return true; - case 0x15: HandlePacketClientSettings (a_ByteBuffer); return true; - case 0x16: HandlePacketClientStatus (a_ByteBuffer); return true; - case 0x17: HandlePacketPluginMessage (a_ByteBuffer); return true; + HANDLE_PACKET(0x00, KeepAlive); + HANDLE_PACKET(0x01, ChatMessage); + HANDLE_PACKET(0x02, UseEntity); + HANDLE_PACKET(0x03, Player); + HANDLE_PACKET(0x04, PlayerPos); + HANDLE_PACKET(0x05, PlayerLook); + HANDLE_PACKET(0x06, PlayerPosLook); + HANDLE_PACKET(0x07, BlockDig); + HANDLE_PACKET(0x08, BlockPlace); + HANDLE_PACKET(0x09, SlotSelect); + HANDLE_PACKET(0x0a, Animation); + HANDLE_PACKET(0x0b, EntityAction); + HANDLE_PACKET(0x0c, SteerVehicle); + HANDLE_PACKET(0x0d, WindowClose); + HANDLE_PACKET(0x0e, WindowClick); + HANDLE_PACKET(0x0f, CreativeInventoryAction); // Confirm transaction - not used in MCS + HANDLE_PACKET(0x10, CreativeInventoryAction); + HANDLE_PACKET(0x11, EnchantItem); + HANDLE_PACKET(0x12, UpdateSign); + HANDLE_PACKET(0x13, PlayerAbilities); + HANDLE_PACKET(0x14, TabComplete); + HANDLE_PACKET(0x15, ClientSettings); + HANDLE_PACKET(0x16, ClientStatus); + HANDLE_PACKET(0x17, PluginMessage); } - break; } default: { @@ -1676,44 +1673,47 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) // Switch to a state when all further packets are silently ignored: m_State = 255; - return false; + return cProtocolError::PacketUnknown; } case 255: { // This is the state used for "not processing packets anymore" when we receive a bad packet from a client. // Do not output anything (the caller will do that for us), just return failure - return false; + return cProtocolError::PacketUnknown; } } // switch (m_State) - - // Unknown packet type, report to the ClientHandle: - m_Client->PacketUnknown(a_PacketType); - return false; } +#define ADD_SIMPLE_ACTION(Name) a_Action.push_back(cpp14::make_unique<cSimpleAction>(cClientAction::Type::Name)); - -void cProtocol172::HandlePacketStatusPing(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketStatusPing(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, Timestamp); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt64, Int64, Timestamp); cPacketizer Pkt(*this, 0x01); // Ping packet Pkt.WriteBEInt64(Timestamp); + + ADD_SIMPLE_ACTION(StatusPing); + return cProtocolError::Success; } -void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { + ADD_SIMPLE_ACTION(StatusRequest); + return cProtocolError::Success; +/* cServer * Server = cRoot::Get()->GetServer(); AString ServerDescription = Server->GetDescription(); int NumPlayers = Server->GetNumPlayers(); int MaxPlayers = Server->GetMaxPlayers(); AString Favicon = Server->GetFaviconData(); + cRoot::Get()->GetPluginManager()->CallHookServerPing(*m_Client, ServerDescription, NumPlayers, MaxPlayers, Favicon); // Version: @@ -1746,44 +1746,32 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) cPacketizer Pkt(*this, 0x00); // Response packet Pkt.WriteString(Response); +*/ } -void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - UInt16 EncKeyLength, EncNonceLength; - if (!a_ByteBuffer.ReadBEUInt16(EncKeyLength)) - { - return; - } + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt16, UInt16, EncKeyLength); if (EncKeyLength > MAX_ENC_LEN) { LOGD("Invalid Encryption Key length: %u (0x%04x). Kicking client.", EncKeyLength, EncKeyLength); - m_Client->Kick("Invalid EncKeyLength"); - return; + return cProtocolError::PacketProcessError; } AString EncKey; if (!a_ByteBuffer.ReadString(EncKey, EncKeyLength)) { - return; - } - if (!a_ByteBuffer.ReadBEUInt16(EncNonceLength)) - { - return; - } - if (EncNonceLength > MAX_ENC_LEN) - { - LOGD("Invalid Encryption Nonce length: %u (0x%04x). Kicking client.", EncNonceLength, EncNonceLength); - m_Client->Kick("Invalid EncNonceLength"); - return; + return cProtocolError::PacketReadError; } + + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt16, UInt16, EncNonceLength); AString EncNonce; if (!a_ByteBuffer.ReadString(EncNonce, EncNonceLength)) { - return; + return cProtocolError::PacketProcessError; } // Decrypt EncNonce using privkey @@ -1796,14 +1784,12 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe if (res != 4) { LOGD("Bad nonce length: got %d, exp %d", res, 4); - m_Client->Kick("Hacked client"); - return; + return cProtocolError::PacketProcessError; } if (ntohl(DecryptedNonce[0]) != static_cast<UInt32>(reinterpret_cast<uintptr_t>(this))) { LOGD("Bad nonce value"); - m_Client->Kick("Hacked client"); - return; + return cProtocolError::PacketProcessError; } // Decrypt the symmetric encryption key using privkey: @@ -1815,31 +1801,35 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe if (res != 16) { LOGD("Bad key length"); - m_Client->Kick("Hacked client"); - return; + return cProtocolError::PacketProcessError; } StartEncryption(DecryptedKey); - m_Client->HandleLogin(4, m_Client->GetUsername()); + //m_Client->HandleLogin(4, m_Client->GetUsername()); + ADD_SIMPLE_ACTION(LoginConfirmation); + return cProtocolError::Success; } -void cProtocol172::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { AString Username; if (!a_ByteBuffer.ReadVarUTF8String(Username)) { - m_Client->Kick("Bad username"); - return; + LOGD("Bad username"); + return cProtocolError::PacketProcessError; } - + + ADD_SIMPLE_ACTION(LoginStart); + return cProtocolError::Success; + /* if (!m_Client->HandleHandshake(Username)) { // The client is not welcome here, they have been sent a Kick packet already - return; + return cProtocolError::PacketProcessError; } cServer * Server = cRoot::Get()->GetServer(); @@ -1856,138 +1846,158 @@ void cProtocol172::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) m_Client->SetUsername(Username); return; } - + m_Client->HandleLogin(4, Username); + */ } -void cProtocol172::HandlePacketAnimation(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketAnimation(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEUInt32, UInt32, EntityID); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Animation); - m_Client->HandleAnimation(Animation); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt32, UInt32, EntityID); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Animation); + //m_Client->HandleAnimation(Animation); + ADD_SIMPLE_ACTION(Animation); + return cProtocolError::Success; } -void cProtocol172::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Status); - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, BlockY); - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ); - HANDLE_READ(a_ByteBuffer, ReadBEInt8, Int8, Face); - m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), Status); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Status); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, BlockY); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt8, Int8, Face); + //m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), Status); + ADD_SIMPLE_ACTION(LeftClick); + return cProtocolError::Success; } -void cProtocol172::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, BlockY); - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ); - HANDLE_READ(a_ByteBuffer, ReadBEInt8, Int8, Face); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, BlockY); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt8, Int8, Face); cItem Item; ReadItem(a_ByteBuffer, Item); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorX); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorY); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorZ); - m_Client->HandleRightClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), CursorX, CursorY, CursorZ, m_Client->GetPlayer()->GetEquippedItem()); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorX); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorY); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorZ); + //m_Client->HandleRightClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), CursorX, CursorY, CursorZ, m_Client->GetPlayer()->GetEquippedItem()); + ADD_SIMPLE_ACTION(RightClick); + return cProtocolError::Success; } -void cProtocol172::HandlePacketChatMessage(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketChatMessage(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Message); - m_Client->HandleChat(Message); + HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Message); + //m_Client->HandleChat(Message); + ADD_SIMPLE_ACTION(Chat); + return cProtocolError::Success; } -void cProtocol172::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Locale); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ViewDistance); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ChatFlags); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ChatColors); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Difficulty); - HANDLE_READ(a_ByteBuffer, ReadBool, bool, ShowCape); + HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Locale); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ViewDistance); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ChatFlags); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ChatColors); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Difficulty); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, ShowCape); - m_Client->SetLocale(Locale); - m_Client->SetViewDistance(ViewDistance); + //m_Client->SetLocale(Locale); + //m_Client->SetViewDistance(ViewDistance); // TODO: Do anything with the other values. + ADD_SIMPLE_ACTION(SetLocale); + ADD_SIMPLE_ACTION(SetViewDistance); + return cProtocolError::Success; } -void cProtocol172::HandlePacketClientStatus(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketClientStatus(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ActionID); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ActionID); switch (ActionID) { case 0: { // Respawn - m_Client->HandleRespawn(); + //m_Client->HandleRespawn(); + ADD_SIMPLE_ACTION(Respawn); break; } case 1: { // Request stats - const cStatManager & Manager = m_Client->GetPlayer()->GetStatManager(); - SendStatistics(Manager); - + //const cStatManager & Manager = m_Client->GetPlayer()->GetStatManager(); + //SendStatistics(Manager); + ADD_SIMPLE_ACTION(StatsRequest); break; } case 2: { // Open Inventory achievement - m_Client->GetPlayer()->AwardAchievement(achOpenInv); + //m_Client->GetPlayer()->AwardAchievement(achOpenInv); + ADD_SIMPLE_ACTION(Achivement); break; } + default: + return cProtocolError::PacketReadError; } + return cProtocolError::Success; } -void cProtocol172::HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum); - cItem Item; + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum); + /*cItem Item; if (!ReadItem(a_ByteBuffer, Item)) { return; } m_Client->HandleCreativeInventory(SlotNum, Item, (SlotNum < 0) ? caLeftClick : caLeftClickOutside); + */ + ADD_SIMPLE_ACTION(CreativeInventory); + return cProtocolError::Success; } - -void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer) +/* +cProtocol::cProtocolError cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEUInt32, UInt32, PlayerID); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Action); - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, JumpBoost); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt32, UInt32, PlayerID); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Action); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, JumpBoost); switch (Action) { @@ -2003,9 +2013,9 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketKeepAlive(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketKeepAlive(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEUInt32, UInt32, KeepAliveID); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt32, UInt32, KeepAliveID); m_Client->HandleKeepAlive(KeepAliveID); } @@ -2013,9 +2023,9 @@ void cProtocol172::HandlePacketKeepAlive(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketPlayer(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketPlayer(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); // TODO: m_Client->HandlePlayerOnGround(IsOnGround); } @@ -2023,11 +2033,11 @@ void cProtocol172::HandlePacketPlayer(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketPlayerAbilities(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketPlayerAbilities(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Flags); - HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, FlyingSpeed); - HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, WalkingSpeed); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Flags); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEFloat, float, FlyingSpeed); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEFloat, float, WalkingSpeed); // Convert flags bitfield into individual bool flags: bool IsFlying = false, CanFly = false; @@ -2047,11 +2057,11 @@ void cProtocol172::HandlePacketPlayerAbilities(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketPlayerLook(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketPlayerLook(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Yaw); - HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Pitch); - HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEFloat, float, Yaw); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEFloat, float, Pitch); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); m_Client->HandlePlayerLook(Yaw, Pitch, IsOnGround); } @@ -2059,13 +2069,13 @@ void cProtocol172::HandlePacketPlayerLook(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketPlayerPos(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketPlayerPos(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosX); - HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosY); - HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, Stance); - HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosZ); - HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEDouble, double, PosX); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEDouble, double, PosY); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEDouble, double, Stance); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEDouble, double, PosZ); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); m_Client->HandlePlayerPos(PosX, PosY, PosZ, Stance, IsOnGround); } @@ -2073,15 +2083,15 @@ void cProtocol172::HandlePacketPlayerPos(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketPlayerPosLook(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketPlayerPosLook(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosX); - HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosY); - HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, Stance); - HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosZ); - HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Yaw); - HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Pitch); - HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEDouble, double, PosX); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEDouble, double, PosY); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEDouble, double, Stance); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEDouble, double, PosZ); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEFloat, float, Yaw); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEFloat, float, Pitch); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); m_Client->HandlePlayerMoveLook(PosX, PosY, PosZ, Stance, Yaw, Pitch, IsOnGround); } @@ -2089,10 +2099,10 @@ void cProtocol172::HandlePacketPlayerPosLook(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel); - HANDLE_READ(a_ByteBuffer, ReadBEUInt16, UInt16, Length); + HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt16, UInt16, Length); if (Length != a_ByteBuffer.GetReadableSpace() - 1) { LOGD("Invalid plugin message packet, payload length doesn't match packet length (exp %u, got %u)", @@ -2121,9 +2131,9 @@ void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketSlotSelect(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketSlotSelect(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum); m_Client->HandleSlotSelected(SlotNum); } @@ -2131,12 +2141,12 @@ void cProtocol172::HandlePacketSlotSelect(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketSteerVehicle(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketSteerVehicle(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Forward); - HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Sideways); - HANDLE_READ(a_ByteBuffer, ReadBool, bool, ShouldJump); - HANDLE_READ(a_ByteBuffer, ReadBool, bool, ShouldUnmount); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEFloat, float, Forward); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEFloat, float, Sideways); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, ShouldJump); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, ShouldUnmount); if (ShouldUnmount) { m_Client->HandleUnmount(); @@ -2151,9 +2161,9 @@ void cProtocol172::HandlePacketSteerVehicle(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketTabComplete(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketTabComplete(cByteBuffer & a_ByteBuffer, ActionList & a_Action) { - HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Text); + HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Text); m_Client->HandleTabCompletion(Text); } @@ -2161,15 +2171,15 @@ void cProtocol172::HandlePacketTabComplete(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer) { - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX); - HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, BlockY); - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ); - HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line1); - HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line2); - HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line3); - HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line4); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, BlockY); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ); + HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line1); + HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line2); + HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line3); + HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line4); m_Client->HandleUpdateSign(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4); } @@ -2177,10 +2187,10 @@ void cProtocol172::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer) { - HANDLE_READ(a_ByteBuffer, ReadBEUInt32, UInt32, EntityID); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, MouseButton); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt32, UInt32, EntityID); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, MouseButton); m_Client->HandleUseEntity(EntityID, (MouseButton == 1)); } @@ -2188,10 +2198,10 @@ void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer) { - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Enchantment); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Enchantment); m_Client->HandleEnchantItem(WindowID, Enchantment); } @@ -2200,13 +2210,13 @@ void cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer) { - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID); - HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Button); - HANDLE_READ(a_ByteBuffer, ReadBEUInt16, UInt16, TransactionID); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Mode); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Button); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt16, UInt16, TransactionID); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Mode); cItem Item; ReadItem(a_ByteBuffer, Item); @@ -2252,9 +2262,9 @@ void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketWindowClose(cByteBuffer & a_ByteBuffer) +cProtocol::cProtocolError cProtocol172::HandlePacketWindowClose(cByteBuffer & a_ByteBuffer) { - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID); m_Client->HandleWindowClose(WindowID); } @@ -2267,16 +2277,16 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const if (a_Channel == "MC|AdvCdm") { size_t BeginningSpace = a_ByteBuffer.GetReadableSpace(); - HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Mode); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Mode); switch (Mode) { case 0x00: { // Block-based commandblock update: - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX); - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockY); - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ); - HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Command); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockX); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockY); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ); + HANDLE_PACKET_READ(a_ByteBuffer, ReadVarUTF8String, AString, Command); m_Client->HandleCommandBlockBlockChange(BlockX, BlockY, BlockZ, Command); break; } @@ -2317,8 +2327,8 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const } else if (a_Channel == "MC|Beacon") { - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect1); - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect2); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect1); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect2); m_Client->HandleBeaconSelection(Effect1, Effect2); return; } @@ -2333,7 +2343,7 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const } else if (a_Channel == "MC|TrSel") { - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, SlotNum); + HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt32, Int32, SlotNum); m_Client->HandleNPCTrade(SlotNum); return; } @@ -2744,7 +2754,7 @@ void cProtocol172::WriteBlockEntity(cPacketizer & a_Pkt, const cBlockEntity & a_ a_Pkt.WriteBEUInt16(static_cast<UInt16>(Compressed.size())); a_Pkt.WriteBuf(Compressed.data(), Compressed.size()); } - +*/ @@ -3162,7 +3172,7 @@ void cProtocol176::SendPlayerSpawn(const cPlayer & a_Player) - +/* void cProtocol176::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) { cServer * Server = cRoot::Get()->GetServer(); @@ -3203,7 +3213,7 @@ void cProtocol176::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) cPacketizer Pkt(*this, 0x00); // Response packet Pkt.WriteString(Response); } - +*/ diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 41af2e568..16a4e972e 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -16,6 +16,7 @@ Declares the 1.7.x protocol classes: #pragma once #include "Protocol.h" +#include "LengthenedProtocol.h" #include "../ByteBuffer.h" #ifdef _MSC_VER @@ -46,9 +47,9 @@ namespace Json class cProtocol172 : - public cProtocol + public cLengthenedProtocol { - typedef cProtocol super; + typedef cLengthenedProtocol super; public: @@ -79,35 +80,35 @@ 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 SendExperience (const cPlayer & a_Player) 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; + virtual void SendHealth (int a_Health, int a_FoodLevel, double a_FoodSaturationLevel) override; virtual void SendHideTitle (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (UInt32 a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; - virtual void SendLoginSuccess (void) override; + virtual void SendLoginSuccess (const AString & a_UUID, const AString & a_Username) override; virtual void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY) override; virtual void SendPaintingSpawn (const cPainting & a_Painting) override; virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) override; virtual void SendParticleEffect (const AString & a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> a_Data) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; - virtual void SendPlayerAbilities (void) override; + virtual void SendPlayerAbilities (const cPlayer & a_Player) override; virtual void SendPlayerListAddPlayer (const cPlayer & a_Player) override; virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) override; virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override; virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) override; virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) override; - virtual void SendPlayerMaxSpeed (void) override; - virtual void SendPlayerMoveLook (void) override; - virtual void SendPlayerPosition (void) override; + virtual void SendPlayerMaxSpeed (const cPlayer & a_Player) override; + virtual void SendPlayerMoveLook (const cPlayer & a_Player) override; + virtual void SendPlayerPosition (const cPlayer & a_Player) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; virtual void SendResetTitle (void) override; - virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override; + virtual void SendRespawn (eGameMode a_GameMode, eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override; virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; virtual void SendSetSubTitle (const cCompositeChat & a_SubTitle) override; @@ -131,7 +132,7 @@ public: virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override; virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual void SendWeather (eWeather a_Weather) override; - virtual void SendWholeInventory (const cWindow & a_Window) override; + virtual void SendWholeInventory (const cPlayer & a_Player, const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (const cWindow & a_Window) override; virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; @@ -140,6 +141,8 @@ public: protected: + typedef std::vector<std::unique_ptr<cClientAction>> ActionList; + AString m_ServerAddress; UInt16 m_ServerPort; @@ -156,40 +159,40 @@ protected: /** Reads and handles the packet. The packet length and type have already been read. Returns true if the packet was understood, false if it was an unknown packet */ - bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType); + cProtocolError HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType, ActionList & a_Action) WARN_UNUSED; // Packet handlers while in the Status state (m_State == 1): - void HandlePacketStatusPing(cByteBuffer & a_ByteBuffer); - virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer); + cProtocolError HandlePacketStatusPing(cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + virtual cProtocolError HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; // Packet handlers while in the Login state (m_State == 2): - void HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer); - void HandlePacketLoginStart(cByteBuffer & a_ByteBuffer); - + cProtocolError HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketLoginStart(cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + // Packet handlers while in the Game state (m_State == 3): - void HandlePacketAnimation (cByteBuffer & a_ByteBuffer); - void HandlePacketBlockDig (cByteBuffer & a_ByteBuffer); - void HandlePacketBlockPlace (cByteBuffer & a_ByteBuffer); - void HandlePacketChatMessage (cByteBuffer & a_ByteBuffer); - void HandlePacketClientSettings (cByteBuffer & a_ByteBuffer); - void HandlePacketClientStatus (cByteBuffer & a_ByteBuffer); - void HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffer); - void HandlePacketEntityAction (cByteBuffer & a_ByteBuffer); - void HandlePacketKeepAlive (cByteBuffer & a_ByteBuffer); - void HandlePacketPlayer (cByteBuffer & a_ByteBuffer); - void HandlePacketPlayerAbilities (cByteBuffer & a_ByteBuffer); - void HandlePacketPlayerLook (cByteBuffer & a_ByteBuffer); - void HandlePacketPlayerPos (cByteBuffer & a_ByteBuffer); - void HandlePacketPlayerPosLook (cByteBuffer & a_ByteBuffer); - void HandlePacketPluginMessage (cByteBuffer & a_ByteBuffer); - void HandlePacketSlotSelect (cByteBuffer & a_ByteBuffer); - void HandlePacketSteerVehicle (cByteBuffer & a_ByteBuffer); - void HandlePacketTabComplete (cByteBuffer & a_ByteBuffer); - void HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer); - void HandlePacketUseEntity (cByteBuffer & a_ByteBuffer); - void HandlePacketEnchantItem (cByteBuffer & a_ByteBuffer); - void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer); - void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer); + cProtocolError HandlePacketAnimation (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketBlockDig (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketBlockPlace (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketChatMessage (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketClientSettings (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketClientStatus (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketEntityAction (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketKeepAlive (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketPlayer (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketPlayerAbilities (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketPlayerLook (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketPlayerPos (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketPlayerPosLook (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketPluginMessage (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketSlotSelect (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketSteerVehicle (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketTabComplete (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketUseEntity (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketEnchantItem (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketWindowClick (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; + cProtocolError HandlePacketWindowClose (cByteBuffer & a_ByteBuffer, ActionList & a_Action) WARN_UNUSED; /** Parses Vanilla plugin messages into specific ClientHandle calls. The message payload is still in the bytebuffer, to be read by this function. */ @@ -248,7 +251,7 @@ public: // cProtocol172 overrides: virtual void SendPlayerSpawn(const cPlayer & a_Player) override; - virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) override; + virtual cProtocolError HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer, ActionList & a_Action) override WARN_UNUSED; } ; diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index c1d01e1f7..d40fd97d6 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -1,4 +1,6 @@ +#if 0 + // Protocol18x.cpp /* @@ -539,7 +541,7 @@ void cProtocol180::SendGameMode(eGameMode a_GameMode) -void cProtocol180::SendHealth(void) +void cProtocol180::SendHealth(int a_Health, int a_FoodLevel, double a_FoodSaturationLevel) { ASSERT(m_State == 3); // In game mode? @@ -733,7 +735,7 @@ void cProtocol180::SendPickupSpawn(const cPickup & a_Pickup) -void cProtocol180::SendPlayerAbilities(void) +void cProtocol180::SendPlayerAbilities(const cPlayer const * a_Player) { ASSERT(m_State == 3); // In game mode? @@ -1069,7 +1071,7 @@ void cProtocol180::SendResetTitle(void) -void cProtocol180::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) +void cProtocol180::SendRespawn(eGameMode a_GameMode, eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) { if ((m_LastSentDimension == a_Dimension) && !a_ShouldIgnoreDimensionChecks) { @@ -3560,5 +3562,7 @@ void cProtocol180::WriteEntityProperties(cPacketizer & a_Pkt, const cEntity & a_ a_Pkt.WriteBEInt32(0); // NumProperties } +#endif + diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h index 73f942895..97169ec90 100644 --- a/src/Protocol/Protocol18x.h +++ b/src/Protocol/Protocol18x.h @@ -15,6 +15,7 @@ Declares the 1.8.x protocol classes: #pragma once #include "Protocol.h" +#include "LengthenedProtocol.h" #include "../ByteBuffer.h" #ifdef _MSC_VER @@ -48,9 +49,9 @@ namespace Json class cProtocol180 : - public cProtocol + public cLengthenedProtocol { - typedef cProtocol super; + typedef cLengthenedProtocol super; public: @@ -81,16 +82,16 @@ public: virtual void SendEntityVelocity (const cEntity & a_Entity) 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; + virtual void SendHealth (int a_Health, int a_FoodLevel, double a_FoodSaturationLevel) override; virtual void SendHideTitle (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (UInt32 a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; - virtual void SendLoginSuccess (void) override; + virtual void SendLoginSuccess (const AString & a_UUID, const AString & a_Username) override; virtual void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY) override; virtual void SendPaintingSpawn (const cPainting & a_Painting) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; - virtual void SendPlayerAbilities (void) override; + virtual void SendPlayerAbilities (const cPlayer & a_Player) override; virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override; virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) override; virtual void SendParticleEffect (const AString & a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> a_Data) override; @@ -99,16 +100,16 @@ public: virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override; virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) override; virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) override; - virtual void SendPlayerMaxSpeed (void) override; - virtual void SendPlayerMoveLook (void) override; - virtual void SendPlayerPosition (void) override; + virtual void SendPlayerMaxSpeed (const cPlayer & a_Player) override; + virtual void SendPlayerMoveLook (const cPlayer & a_Player) override; + virtual void SendPlayerPosition (const cPlayer & a_Player) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; virtual void SendResetTitle (void) override; - virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override; + virtual void SendRespawn (eGameMode a_GameMode, eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) 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 SendExperience (const cPlayer & a_Player) 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; @@ -133,7 +134,7 @@ public: virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override; virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual void SendWeather (eWeather a_Weather) override; - virtual void SendWholeInventory (const cWindow & a_Window) override; + virtual void SendWholeInventory (const cPlayer & a_Player, const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (const cWindow & a_Window) override; virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index c88bd8639..c8e1cba1b 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -18,7 +18,7 @@ - +#if 0 cProtocolRecognizer::cProtocolRecognizer(cClientHandle * a_Client) : super(a_Client), @@ -1051,7 +1051,7 @@ void cProtocolRecognizer::SendPacket(cPacketizer & a_Pkt) ASSERT(!"Function not to be called"); } - +#endif diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index c548ad5ba..98dd95b17 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -45,7 +45,7 @@ public: static AString GetVersionTextFromInt(int a_ProtocolVersion); /** Called when client sends some data: */ - virtual void DataReceived(const char * a_Data, size_t a_Size) override; + virtual cProtocolError DataReceived(const char * a_Data, size_t a_Size, std::vector<std::unique_ptr<cClientAction>> & a_Actions) override WARN_UNUSED; /** Sending stuff to clients (alphabetically sorted): */ virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override; @@ -72,33 +72,33 @@ public: virtual void SendEntityVelocity (const cEntity & a_Entity) 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; + virtual void SendHealth (int a_Health, int a_FoodLevel, double a_FoodSaturationLevel) override; virtual void SendHideTitle (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (UInt32 a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; - virtual void SendLoginSuccess (void) override; + virtual void SendLoginSuccess (const AString & a_UUID, const AString & a_Username) override; virtual void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY) override; virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) override; virtual void SendParticleEffect (const AString & a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> a_Data) override; virtual void SendPaintingSpawn (const cPainting & a_Painting) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; - virtual void SendPlayerAbilities (void) override; + virtual void SendPlayerAbilities (const cPlayer & a_Player) override; virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override; virtual void SendPlayerListAddPlayer (const cPlayer & a_Player) override; virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) override; virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override; virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) override; virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) override; - virtual void SendPlayerMaxSpeed (void) override; - virtual void SendPlayerMoveLook (void) override; - virtual void SendPlayerPosition (void) override; + virtual void SendPlayerMaxSpeed (const cPlayer & a_Player) override; + virtual void SendPlayerMoveLook (const cPlayer & a_Player) override; + virtual void SendPlayerPosition (const cPlayer & a_Player) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; virtual void SendResetTitle (void) override; - virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override; - virtual void SendExperience (void) override; + virtual void SendRespawn (eGameMode a_GameMode, eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override; + virtual void SendExperience (const cPlayer & a_Player) 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; @@ -124,7 +124,7 @@ public: virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override; virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual void SendWeather (eWeather a_Weather) override; - virtual void SendWholeInventory (const cWindow & a_Window) override; + virtual void SendWholeInventory (const cPlayer & a_Player, const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (const cWindow & a_Window) override; virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index dc89ff8d4..32a202f58 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -428,7 +428,7 @@ cSlotAreaChest::cSlotAreaChest(cChestEntity * a_Chest, cWindow & a_ParentWindow) -const cItem * cSlotAreaChest::GetSlot(int a_SlotNum, cPlayer & a_Player) const +const cItem * cSlotAreaChest::GetSlot(int a_SlotNum, const cPlayer & a_Player) const { // a_SlotNum ranges from 0 to 26, use that to index the chest entity's inventory directly: return &(m_Chest->GetSlot(a_SlotNum)); @@ -461,7 +461,7 @@ cSlotAreaDoubleChest::cSlotAreaDoubleChest(cChestEntity * a_TopChest, cChestEnti -const cItem * cSlotAreaDoubleChest::GetSlot(int a_SlotNum, cPlayer & a_Player) const +const cItem * cSlotAreaDoubleChest::GetSlot(int a_SlotNum, const cPlayer & a_Player) const { // a_SlotNum ranges from 0 to 53, use that to index the correct chest's inventory: if (a_SlotNum < 27) @@ -1358,7 +1358,7 @@ void cSlotAreaBeacon::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, b -const cItem * cSlotAreaBeacon::GetSlot(int a_SlotNum, cPlayer & a_Player) const +const cItem * cSlotAreaBeacon::GetSlot(int a_SlotNum, const cPlayer & a_Player) const { UNUSED(a_Player); return &(m_Beacon->GetSlot(a_SlotNum)); @@ -1669,7 +1669,7 @@ cSlotAreaEnderChest::cSlotAreaEnderChest(cEnderChestEntity * a_EnderChest, cWind -const cItem * cSlotAreaEnderChest::GetSlot(int a_SlotNum, cPlayer & a_Player) const +const cItem * cSlotAreaEnderChest::GetSlot(int a_SlotNum, const cPlayer & a_Player) const { return &(a_Player.GetEnderChestContents().GetSlot(a_SlotNum)); } @@ -1886,7 +1886,7 @@ void cSlotAreaFurnace::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, -const cItem * cSlotAreaFurnace::GetSlot(int a_SlotNum, cPlayer & a_Player) const +const cItem * cSlotAreaFurnace::GetSlot(int a_SlotNum, const cPlayer & a_Player) const { UNUSED(a_Player); // a_SlotNum ranges from 0 to 2, query the items from the underlying furnace: @@ -2184,7 +2184,7 @@ cSlotAreaMinecartWithChest::cSlotAreaMinecartWithChest(cMinecartWithChest * a_Ch -const cItem * cSlotAreaMinecartWithChest::GetSlot(int a_SlotNum, cPlayer & a_Player) const +const cItem * cSlotAreaMinecartWithChest::GetSlot(int a_SlotNum, const cPlayer & a_Player) const { // a_SlotNum ranges from 0 to 26, use that to index the minecart chest entity's inventory directly: UNUSED(a_Player); @@ -2242,7 +2242,7 @@ void cSlotAreaInventoryBase::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAc -const cItem * cSlotAreaInventoryBase::GetSlot(int a_SlotNum, cPlayer & a_Player) const +const cItem * cSlotAreaInventoryBase::GetSlot(int a_SlotNum, const cPlayer & a_Player) const { // a_SlotNum ranges from 0 to 35, map that to the player's inventory slots according to the internal offset return &a_Player.GetInventory().GetSlot(a_SlotNum + m_SlotOffset); @@ -2426,7 +2426,7 @@ cSlotAreaItemGrid::~cSlotAreaItemGrid() -const cItem * cSlotAreaItemGrid::GetSlot(int a_SlotNum, cPlayer & a_Player) const +const cItem * cSlotAreaItemGrid::GetSlot(int a_SlotNum, const cPlayer & a_Player) const { return &m_ItemGrid.GetSlot(a_SlotNum); } @@ -2466,7 +2466,7 @@ cSlotAreaTemporary::cSlotAreaTemporary(int a_NumSlots, cWindow & a_ParentWindow) -const cItem * cSlotAreaTemporary::GetSlot(int a_SlotNum, cPlayer & a_Player) const +const cItem * cSlotAreaTemporary::GetSlot(int a_SlotNum, const cPlayer & a_Player) const { cItemMap::const_iterator itr = m_Items.find(a_Player.GetUniqueID()); if (itr == m_Items.end()) diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 0ff36ce50..0d60c0b2f 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -37,7 +37,7 @@ public: int GetNumSlots(void) const { return m_NumSlots; } /** Called to retrieve an item in the specified slot for the specified player. Must return a valid cItem. */ - virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const = 0; + virtual const cItem * GetSlot(int a_SlotNum, const cPlayer & a_Player) const = 0; /** Called to set an item in the specified slot for the specified player */ virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) = 0; @@ -100,7 +100,7 @@ public: // Creative inventory's click handling is somewhat different from survival inventory's, handle that here: virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; - virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; + virtual const cItem * GetSlot(int a_SlotNum, const cPlayer & a_Player) const override; virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; protected: @@ -180,7 +180,7 @@ public: virtual ~cSlotAreaItemGrid(); - virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; + virtual const cItem * GetSlot(int a_SlotNum, const cPlayer & a_Player) const override; virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; protected: @@ -206,7 +206,7 @@ public: cSlotAreaTemporary(int a_NumSlots, cWindow & a_ParentWindow); // cSlotArea overrides: - virtual const cItem * GetSlot (int a_SlotNum, cPlayer & a_Player) const override; + virtual const cItem * GetSlot (int a_SlotNum, const cPlayer & a_Player) const override; virtual void SetSlot (int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; virtual void OnPlayerAdded (cPlayer & a_Player) override; virtual void OnPlayerRemoved(cPlayer & a_Player) override; @@ -330,7 +330,7 @@ public: virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill) override; - virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; + virtual const cItem * GetSlot(int a_SlotNum, const cPlayer & a_Player) const override; virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; protected: @@ -381,7 +381,7 @@ class cSlotAreaChest : public: cSlotAreaChest(cChestEntity * a_Chest, cWindow & a_ParentWindow); - virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; + virtual const cItem * GetSlot(int a_SlotNum, const cPlayer & a_Player) const override; virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; protected: @@ -398,7 +398,7 @@ class cSlotAreaDoubleChest : public: cSlotAreaDoubleChest(cChestEntity * a_TopChest, cChestEntity * a_BottomChest, cWindow & a_ParentWindow); - virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; + virtual const cItem * GetSlot(int a_SlotNum, const cPlayer & a_Player) const override; virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; protected: @@ -416,7 +416,7 @@ class cSlotAreaEnderChest : public: cSlotAreaEnderChest(cEnderChestEntity * a_EnderChest, cWindow & a_ParentWindow); - virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; + virtual const cItem * GetSlot(int a_SlotNum, const cPlayer & a_Player) const override; virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; protected: @@ -440,7 +440,7 @@ public: virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill) override; - virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; + virtual const cItem * GetSlot(int a_SlotNum, const cPlayer & a_Player) const override; virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; protected: @@ -492,7 +492,7 @@ class cSlotAreaMinecartWithChest : public: cSlotAreaMinecartWithChest(cMinecartWithChest * a_ChestCart, cWindow & a_ParentWindow); - virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; + virtual const cItem * GetSlot(int a_SlotNum, const cPlayer & a_Player) const override; virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; protected: diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index d0b963e13..146131728 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -170,7 +170,7 @@ bool cWindow::IsSlotInPlayerInventory(int a_SlotNum) const -void cWindow::GetSlots(cPlayer & a_Player, cItems & a_Slots) const +void cWindow::GetSlots(const cPlayer & a_Player, cItems & a_Slots) const { a_Slots.clear(); a_Slots.reserve(static_cast<size_t>(GetNumSlots())); diff --git a/src/UI/Window.h b/src/UI/Window.h index 76d22a12c..675a83d92 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -108,7 +108,7 @@ public: // tolua_end /** Fills a_Slots with the slots read from m_SlotAreas[], for the specified player */ - void GetSlots(cPlayer & a_Player, cItems & a_Slots) const; + void GetSlots(const cPlayer & a_Player, cItems & a_Slots) const; /** Handles a click event from a player */ void Clicked( |