From 7175b9e435a54cff33914d21384625a445cc5cf0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 20 Aug 2016 13:34:29 +0100 Subject: test --- src/Protocol/Protocol18x.cpp | 109 ++++++++++++++++--------------- src/Protocol/Protocol18x.h | 2 - src/Protocol/Protocol19x.cpp | 150 +++++++++++++++++++++++++++---------------- src/Protocol/Protocol19x.h | 2 +- 4 files changed, 154 insertions(+), 109 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index ae9571f03..9d692b35e 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -616,7 +616,7 @@ void cProtocol180::SendLogin(const cPlayer & a_Player, const cWorld & a_World) { // Send the Join Game packet: { - cServer * Server = cRoot::Get()->GetServer(); + auto Server = cRoot::Get()->GetServer(); cPacketizer Pkt(*this, 0x01); // Join Game packet Pkt.WriteBEUInt32(a_Player.GetUniqueID()); Pkt.WriteBEUInt8(static_cast(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 @@ -926,15 +926,11 @@ void cProtocol180::SendPlayerListUpdatePing(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? - auto ClientHandle = a_Player.GetClientHandlePtr(); - if (ClientHandle != nullptr) - { - cPacketizer Pkt(*this, 0x38); // Playerlist Item packet - Pkt.WriteVarInt32(2); - Pkt.WriteVarInt32(1); - Pkt.WriteUUID(a_Player.GetUUID()); - Pkt.WriteVarInt32(static_cast(ClientHandle->GetPing())); - } + cPacketizer Pkt(*this, 0x38); // Playerlist Item packet + Pkt.WriteVarInt32(2); + Pkt.WriteVarInt32(1); + Pkt.WriteUUID(a_Player.GetUUID()); + Pkt.WriteVarInt32(static_cast(a_Player.GetClientHandle()->GetPing())); } @@ -2236,7 +2232,7 @@ void cProtocol180::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) void cProtocol180::HandlePacketAnimation(cByteBuffer & a_ByteBuffer) { - m_Client->HandleAnimation(0); // Packet exists solely for arm-swing notification + m_Client->QueueDataCommit(&cClientHandle::HandleAnimation, m_Client, 0); // Packet exists solely for arm-swing notification } @@ -2245,6 +2241,11 @@ void cProtocol180::HandlePacketAnimation(cByteBuffer & a_ByteBuffer) void cProtocol180::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer) { + if (!m_Client->EnforceBlockInteractionsRate()) + { + return; + } + HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Status); int BlockX, BlockY, BlockZ; @@ -2254,7 +2255,7 @@ void cProtocol180::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer) } HANDLE_READ(a_ByteBuffer, ReadBEInt8, Int8, Face); - m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), Status); + m_Client->QueueDataCommit(&cClientHandle::HandleLeftClick, m_Client, BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), Status); } @@ -2263,6 +2264,11 @@ void cProtocol180::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer) void cProtocol180::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer) { + if (!m_Client->EnforceBlockInteractionsRate()) + { + return; + } + int BlockX, BlockY, BlockZ; if (!a_ByteBuffer.ReadPosition64(BlockX, BlockY, BlockZ)) { @@ -2277,7 +2283,7 @@ void cProtocol180::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer) 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()); + m_Client->QueueDataCommit(&cClientHandle::HandleRightClick, m_Client, BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), CursorX, CursorY, CursorZ, Item); } @@ -2287,7 +2293,7 @@ void cProtocol180::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer) void cProtocol180::HandlePacketChatMessage(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Message); - m_Client->HandleChat(Message); + m_Client->QueueDataCommit(&cClientHandle::HandleChat, m_Client, Message); } @@ -2314,26 +2320,22 @@ void cProtocol180::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer) void cProtocol180::HandlePacketClientStatus(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, ActionID); + switch (ActionID) { case 0: - { - // Respawn - m_Client->HandleRespawn(); + { // Respawn + m_Client->QueueDataCommit(&cClientHandle::HandleRespawn, m_Client); break; } case 1: - { - // Request stats - const cStatManager & Manager = m_Client->GetPlayer()->GetStatManager(); - SendStatistics(Manager); - + { // Request stats + m_Client->QueueDataCommit(&cClientHandle::SendStatistics, m_Client, m_Client->GetPlayer()->GetStatManager()); break; } case 2: - { - // Open Inventory achievement - m_Client->GetPlayer()->AwardAchievement(achOpenInv); + { // Open Inventory achievement + m_Client->QueueDataCommit(&cPlayer::AwardAchievement, m_Client->GetPlayer(), achOpenInv); break; } } @@ -2351,7 +2353,7 @@ void cProtocol180::HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffe { return; } - m_Client->HandleCreativeInventory(SlotNum, Item, (SlotNum == -1) ? caLeftClickOutside : caLeftClick); + m_Client->QueueDataCommit(&cClientHandle::HandleCreativeInventory, m_Client, SlotNum, Item, (SlotNum == -1) ? caLeftClickOutside : caLeftClick); } @@ -2366,11 +2368,11 @@ void cProtocol180::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer) switch (Action) { - case 0: m_Client->HandleEntityCrouch(PlayerID, true); break; // Crouch - case 1: m_Client->HandleEntityCrouch(PlayerID, false); break; // Uncrouch - case 2: m_Client->HandleEntityLeaveBed(PlayerID); break; // Leave Bed - case 3: m_Client->HandleEntitySprinting(PlayerID, true); break; // Start sprinting - case 4: m_Client->HandleEntitySprinting(PlayerID, false); break; // Stop sprinting + case 0: m_Client->QueueDataCommit(&cClientHandle::HandleEntityCrouch, m_Client, PlayerID, true); break; // Crouch + case 1: m_Client->QueueDataCommit(&cClientHandle::HandleEntityCrouch, m_Client, PlayerID, false); break; // Uncrouch + case 2: m_Client->QueueDataCommit(&cClientHandle::HandleEntityLeaveBed, m_Client, PlayerID); break; // Leave Bed + case 3: m_Client->QueueDataCommit(&cClientHandle::HandleEntitySprinting, m_Client, PlayerID, true); break; // Start sprinting + case 4: m_Client->QueueDataCommit(&cClientHandle::HandleEntitySprinting, m_Client, PlayerID, false); break; // Stop sprinting } } @@ -2415,7 +2417,7 @@ void cProtocol180::HandlePacketPlayerAbilities(cByteBuffer & a_ByteBuffer) CanFly = true; } - m_Client->HandlePlayerAbilities(CanFly, IsFlying, FlyingSpeed, WalkingSpeed); + m_Client->QueueDataCommit(&cClientHandle::HandlePlayerAbilities, m_Client, CanFly, IsFlying, FlyingSpeed, WalkingSpeed); } @@ -2427,7 +2429,7 @@ void cProtocol180::HandlePacketPlayerLook(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Yaw); HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Pitch); HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); - m_Client->HandlePlayerLook(Yaw, Pitch, IsOnGround); + m_Client->QueueDataCommit(&cClientHandle::HandlePlayerLook, m_Client, Yaw, Pitch, IsOnGround); } @@ -2440,7 +2442,7 @@ void cProtocol180::HandlePacketPlayerPos(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosY); HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosZ); HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); - m_Client->HandlePlayerPos(PosX, PosY, PosZ, PosY + (m_Client->GetPlayer()->IsCrouched() ? 1.54 : 1.62), IsOnGround); + m_Client->QueueDataCommit(&cClientHandle::HandlePlayerPos, m_Client, PosX, PosY, PosZ, PosY + (m_Client->GetPlayer()->IsCrouched() ? 1.54 : 1.62), IsOnGround); } @@ -2455,7 +2457,7 @@ void cProtocol180::HandlePacketPlayerPosLook(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Yaw); HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Pitch); HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); - m_Client->HandlePlayerMoveLook(PosX, PosY, PosZ, PosY + 1.62, Yaw, Pitch, IsOnGround); + m_Client->QueueDataCommit(&cClientHandle::HandlePlayerMoveLook, m_Client, PosX, PosY, PosZ, PosY + 1.62, Yaw, Pitch, IsOnGround); } @@ -2496,7 +2498,7 @@ void cProtocol180::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) void cProtocol180::HandlePacketSlotSelect(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum); - m_Client->HandleSlotSelected(SlotNum); + m_Client->QueueDataCommit(&cClientHandle::HandleSlotSelected, m_Client, SlotNum); } @@ -2511,7 +2513,7 @@ void cProtocol180::HandlePacketSteerVehicle(cByteBuffer & a_ByteBuffer) if ((Flags & 0x2) != 0) { - m_Client->HandleUnmount(); + m_Client->QueueDataCommit(&cClientHandle::HandleUnmount, m_Client); } else if ((Flags & 0x1) != 0) { @@ -2519,7 +2521,7 @@ void cProtocol180::HandlePacketSteerVehicle(cByteBuffer & a_ByteBuffer) } else { - m_Client->HandleSteerVehicle(Forward, Sideways); + m_Client->QueueDataCommit(&cClientHandle::HandleSteerVehicle, m_Client, Forward, Sideways); } } @@ -2537,7 +2539,7 @@ void cProtocol180::HandlePacketTabComplete(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, Position); } - m_Client->HandleTabCompletion(Text); + m_Client->QueueDataCommit(&cClientHandle::HandleTabCompletion, m_Client, Text); } @@ -2580,12 +2582,12 @@ void cProtocol180::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer) { case 0: { - m_Client->HandleUseEntity(EntityID, false); + m_Client->QueueDataCommit(&cClientHandle::HandleUseEntity, m_Client, EntityID, false); break; } case 1: { - m_Client->HandleUseEntity(EntityID, true); + m_Client->QueueDataCommit(&cClientHandle::HandleUseEntity, m_Client, EntityID, true); break; } case 2: @@ -2614,7 +2616,7 @@ void cProtocol180::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID); HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Enchantment); - m_Client->HandleEnchantItem(WindowID, Enchantment); + m_Client->QueueDataCommit(&cClientHandle::HandleEnchantItem, m_Client, WindowID, Enchantment); } @@ -2666,7 +2668,7 @@ void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer) } } - m_Client->HandleWindowClick(WindowID, SlotNum, Action, Item); + m_Client->QueueDataCommit(&cClientHandle::HandleWindowClick, m_Client, WindowID, SlotNum, Action, Item); } @@ -2676,7 +2678,7 @@ void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer) void cProtocol180::HandlePacketWindowClose(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID); - m_Client->HandleWindowClose(WindowID); + m_Client->QueueDataCommit(&cClientHandle::HandleWindowClose, m_Client, WindowID); } @@ -2696,13 +2698,20 @@ void cProtocol180::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockY); HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ); HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Command); - m_Client->HandleCommandBlockBlockChange(BlockX, BlockY, BlockZ, Command); + m_Client->QueueDataCommit(&cClientHandle::HandleCommandBlockBlockChange, m_Client, BlockX, BlockY, BlockZ, Command); break; } default: { - m_Client->SendChat(Printf("Failure setting command block command; unhandled mode %u (0x%02x)", Mode, Mode), mtFailure); + m_Client->QueueDataCommit( + static_cast(&cClientHandle::SendChat), + m_Client, + Printf("Failure setting command block command; unhandled mode %u (0x%02x)", Mode, Mode), + mtFailure, + "" + ); + LOG("Unhandled MC|AdvCdm packet mode."); return; } @@ -2721,19 +2730,19 @@ void cProtocol180::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const { HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect1); HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect2); - m_Client->HandleBeaconSelection(Effect1, Effect2); + m_Client->QueueDataCommit(&cClientHandle::HandleBeaconSelection, m_Client, Effect1, Effect2); return; } else if (a_Channel == "MC|ItemName") { HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, ItemName); - m_Client->HandleAnvilItemName(ItemName); + m_Client->QueueDataCommit(&cClientHandle::HandleAnvilItemName, m_Client, ItemName); return; } else if (a_Channel == "MC|TrSel") { HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, SlotNum); - m_Client->HandleNPCTrade(SlotNum); + m_Client->QueueDataCommit(&cClientHandle::HandleNPCTrade, m_Client, SlotNum); return; } LOG("Unhandled vanilla plugin channel: \"%s\".", a_Channel.c_str()); @@ -2890,7 +2899,7 @@ void cProtocol180::StartEncryption(const Byte * a_Key) // Prepare the m_AuthServerID: cSha1Checksum Checksum; - cServer * Server = cRoot::Get()->GetServer(); + auto Server = cRoot::Get()->GetServer(); const AString & ServerID = Server->GetServerID(); Checksum.Update(reinterpret_cast(ServerID.c_str()), ServerID.length()); Checksum.Update(a_Key, 16); diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h index 08a51f342..52fb4eb52 100644 --- a/src/Protocol/Protocol18x.h +++ b/src/Protocol/Protocol18x.h @@ -234,8 +234,6 @@ protected: /** Sends the packet to the client. Called by the cPacketizer's destructor. */ virtual void SendPacket(cPacketizer & a_Packet) override; - void SendCompass(const cWorld & a_World); - /** Reads an item out of the received data, sets a_Item to the values read. Returns false if not enough received data. a_KeepRemainingBytes tells the function to keep that many bytes at the end of the buffer. */ diff --git a/src/Protocol/Protocol19x.cpp b/src/Protocol/Protocol19x.cpp index c11e05565..84d522287 100644 --- a/src/Protocol/Protocol19x.cpp +++ b/src/Protocol/Protocol19x.cpp @@ -951,7 +951,7 @@ void cProtocol190::SendPlayerListUpdatePing(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? - auto ClientHandle = a_Player.GetClientHandlePtr(); + auto ClientHandle = a_Player.GetClientHandlePtr().lock(); if (ClientHandle != nullptr) { cPacketizer Pkt(*this, 0x2d); // Playerlist Item packet @@ -2274,7 +2274,7 @@ void cProtocol190::HandlePacketAnimation(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadVarInt, Int32, Hand); - m_Client->HandleAnimation(0); // Packet exists solely for arm-swing notification + m_Client->QueueDataCommit(&cClientHandle::HandleAnimation, m_Client, 0); // Packet exists solely for arm-swing notification } @@ -2292,7 +2292,7 @@ void cProtocol190::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer) } HANDLE_READ(a_ByteBuffer, ReadVarInt, Int32, Face); - m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), Status); + m_Client->QueueDataCommit(&cClientHandle::HandleLeftClick, m_Client, BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), Status); } @@ -2312,7 +2312,13 @@ void cProtocol190::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer) 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()); + + m_Client->QueueDataCommit( + [Client = m_Client, BlockX, BlockY, BlockZ, Face, CursorX, CursorY, CursorZ] + { + Client->HandleRightClick(BlockX, BlockY, BlockZ, cProtocol190::FaceIntToBlockFace(Face), CursorX, CursorY, CursorZ, Client->GetPlayer()->GetEquippedItem()); + } + ); } @@ -2324,18 +2330,24 @@ void cProtocol190::HandlePacketBoatSteer(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBool, bool, RightPaddle); HANDLE_READ(a_ByteBuffer, ReadBool, bool, LeftPaddle); - // Get the players vehicle - cPlayer * Player = m_Client->GetPlayer(); - cEntity * Vehicle = Player->GetAttached(); - - if (Vehicle) - { - if (Vehicle->GetEntityType() == cEntity::etBoat) + m_Client->QueueDataCommit( + [Client = m_Client, RightPaddle, LeftPaddle] { - auto * Boat = reinterpret_cast(Vehicle); - Boat->UpdatePaddles(RightPaddle, LeftPaddle); + // Get the players vehicle + auto Player = Client->GetPlayer(); + auto Vehicle = Player->GetAttached(); + + if (Vehicle == nullptr) + { + return; + } + + if (Vehicle->GetEntityType() == cEntity::etBoat) + { + reinterpret_cast(Vehicle)->UpdatePaddles(RightPaddle, LeftPaddle); + } } - } + ); } @@ -2345,7 +2357,7 @@ void cProtocol190::HandlePacketBoatSteer(cByteBuffer & a_ByteBuffer) void cProtocol190::HandlePacketChatMessage(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Message); - m_Client->HandleChat(Message); + m_Client->QueueDataCommit(&cClientHandle::HandleChat, m_Client, Message); } @@ -2378,21 +2390,25 @@ void cProtocol190::HandlePacketClientStatus(cByteBuffer & a_ByteBuffer) case 0: { // Respawn - m_Client->HandleRespawn(); + m_Client->QueueDataCommit(&cClientHandle::HandleRespawn, m_Client); break; } case 1: { // Request stats - const cStatManager & Manager = m_Client->GetPlayer()->GetStatManager(); - SendStatistics(Manager); + m_Client->QueueDataCommit( + [Client = m_Client] + { + Client->GetProtocol().SendStatistics(Client->GetPlayer()->GetStatManager()); + } + ); break; } case 2: { // Open Inventory achievement - m_Client->GetPlayer()->AwardAchievement(achOpenInv); + m_Client->QueueDataCommit(&cPlayer::AwardAchievement, m_Client->GetPlayer(), achOpenInv); break; } } @@ -2420,7 +2436,7 @@ void cProtocol190::HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffe { return; } - m_Client->HandleCreativeInventory(SlotNum, Item, (SlotNum == -1) ? caLeftClickOutside : caLeftClick); + m_Client->QueueDataCommit(&cClientHandle::HandleCreativeInventory, m_Client, SlotNum, Item, (SlotNum == -1) ? caLeftClickOutside : caLeftClick); } @@ -2435,11 +2451,11 @@ void cProtocol190::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer) switch (Action) { - case 0: m_Client->HandleEntityCrouch(PlayerID, true); break; // Crouch - case 1: m_Client->HandleEntityCrouch(PlayerID, false); break; // Uncrouch - case 2: m_Client->HandleEntityLeaveBed(PlayerID); break; // Leave Bed - case 3: m_Client->HandleEntitySprinting(PlayerID, true); break; // Start sprinting - case 4: m_Client->HandleEntitySprinting(PlayerID, false); break; // Stop sprinting + case 0: m_Client->QueueDataCommit(&cClientHandle::HandleEntityCrouch, m_Client, PlayerID, true); break; // Crouch + case 1: m_Client->QueueDataCommit(&cClientHandle::HandleEntityCrouch, m_Client, PlayerID, false); break; // Uncrouch + case 2: m_Client->QueueDataCommit(&cClientHandle::HandleEntityLeaveBed, m_Client, PlayerID); break; // Leave Bed + case 3: m_Client->QueueDataCommit(&cClientHandle::HandleEntitySprinting, m_Client, PlayerID, true); break; // Start sprinting + case 4: m_Client->QueueDataCommit(&cClientHandle::HandleEntitySprinting, m_Client, PlayerID, false); break; // Stop sprinting } } @@ -2460,7 +2476,7 @@ void cProtocol190::HandlePacketKeepAlive(cByteBuffer & a_ByteBuffer) void cProtocol190::HandlePacketPlayer(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); - // TODO: m_Client->HandlePlayerOnGround(IsOnGround); + // TODO: m_Client->QueueDataCommit(&cClientHandle::HandlePlayerOnGround, m_Client, IsOnGround); } @@ -2484,7 +2500,7 @@ void cProtocol190::HandlePacketPlayerAbilities(cByteBuffer & a_ByteBuffer) CanFly = true; } - m_Client->HandlePlayerAbilities(CanFly, IsFlying, FlyingSpeed, WalkingSpeed); + m_Client->QueueDataCommit(&cClientHandle::HandlePlayerAbilities, m_Client, CanFly, IsFlying, FlyingSpeed, WalkingSpeed); } @@ -2496,7 +2512,7 @@ void cProtocol190::HandlePacketPlayerLook(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Yaw); HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Pitch); HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); - m_Client->HandlePlayerLook(Yaw, Pitch, IsOnGround); + m_Client->QueueDataCommit(&cClientHandle::HandlePlayerLook, m_Client, Yaw, Pitch, IsOnGround); } @@ -2509,7 +2525,12 @@ void cProtocol190::HandlePacketPlayerPos(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosY); HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosZ); HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); - m_Client->HandlePlayerPos(PosX, PosY, PosZ, PosY + (m_Client->GetPlayer()->IsCrouched() ? 1.54 : 1.62), IsOnGround); + m_Client->QueueDataCommit( + [Client = m_Client, PosX, PosY, PosZ, IsOnGround] + { + Client->HandlePlayerPos(PosX, PosY, PosZ, PosY + (Client->GetPlayer()->IsCrouched() ? 1.54 : 1.62), IsOnGround); + } + ); } @@ -2524,7 +2545,7 @@ void cProtocol190::HandlePacketPlayerPosLook(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Yaw); HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Pitch); HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); - m_Client->HandlePlayerMoveLook(PosX, PosY, PosZ, PosY + 1.62, Yaw, Pitch, IsOnGround); + m_Client->QueueDataCommit(&cClientHandle::HandlePlayerMoveLook, m_Client, PosX, PosY, PosZ, PosY + 1.62, Yaw, Pitch, IsOnGround); } @@ -2565,7 +2586,7 @@ void cProtocol190::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) void cProtocol190::HandlePacketSlotSelect(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadBEInt16, Int16, SlotNum); - m_Client->HandleSlotSelected(SlotNum); + m_Client->QueueDataCommit(&cClientHandle::HandleSlotSelected, m_Client, SlotNum); } @@ -2580,7 +2601,7 @@ void cProtocol190::HandlePacketSteerVehicle(cByteBuffer & a_ByteBuffer) if ((Flags & 0x2) != 0) { - m_Client->HandleUnmount(); + m_Client->QueueDataCommit(&cClientHandle::HandleUnmount, m_Client); } else if ((Flags & 0x1) != 0) { @@ -2588,7 +2609,7 @@ void cProtocol190::HandlePacketSteerVehicle(cByteBuffer & a_ByteBuffer) } else { - m_Client->HandleSteerVehicle(Forward, Sideways); + m_Client->QueueDataCommit(&cClientHandle::HandleSteerVehicle, m_Client, Forward, Sideways); } } @@ -2607,7 +2628,7 @@ void cProtocol190::HandlePacketTabComplete(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, Position); } - m_Client->HandleTabCompletion(Text); + m_Client->QueueDataCommit(&cClientHandle::HandleTabCompletion, m_Client, Text); } @@ -2646,12 +2667,12 @@ void cProtocol190::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer) case 0: { HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, Hand) - m_Client->HandleUseEntity(EntityID, false); + m_Client->QueueDataCommit(&cClientHandle::HandleUseEntity, m_Client, EntityID, false); break; } case 1: { - m_Client->HandleUseEntity(EntityID, true); + m_Client->QueueDataCommit(&cClientHandle::HandleUseEntity, m_Client, EntityID, true); break; } case 2: @@ -2680,8 +2701,13 @@ void cProtocol190::HandlePacketUseItem(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt64, Hand); - // Didn't click a block - emulate old values used with place block of -1, -1, -1 (and BLOCK_FACE_NONE). - m_Client->HandleRightClick(-1, 255, -1, BLOCK_FACE_NONE, 0, 0, 0, m_Client->GetPlayer()->GetEquippedItem()); + m_Client->QueueDataCommit( + [Client = m_Client] + { + // Didn't click a block - emulate old values used with place block of -1, -1, -1 (and BLOCK_FACE_NONE). + Client->HandleRightClick(-1, 255, -1, BLOCK_FACE_NONE, 0, 0, 0, Client->GetPlayer()->GetEquippedItem()); + } + ); } @@ -2693,7 +2719,7 @@ void cProtocol190::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID); HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, Enchantment); - m_Client->HandleEnchantItem(WindowID, Enchantment); + m_Client->QueueDataCommit(&cClientHandle::HandleEnchantItem, m_Client, WindowID, Enchantment); } @@ -2709,17 +2735,23 @@ void cProtocol190::HandlePacketVehicleMove(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, yaw); HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, pitch); - // Get the players vehicle - cEntity * Vehicle = m_Client->GetPlayer()->GetAttached(); + m_Client->QueueDataCommit( + [Client = m_Client, xPos, yPos, zPos, yaw, pitch] + { + // Get the player's vehicle + auto Vehicle = Client->GetPlayer()->GetAttached(); + if (Vehicle == nullptr) + { + return; + } - if (Vehicle) - { - Vehicle->SetPosX(xPos); - Vehicle->SetPosY(yPos); - Vehicle->SetPosZ(zPos); - Vehicle->SetYaw(yaw); - Vehicle->SetPitch(pitch); - } + Vehicle->SetPosX(xPos); + Vehicle->SetPosY(yPos); + Vehicle->SetPosZ(zPos); + Vehicle->SetYaw(yaw); + Vehicle->SetPitch(pitch); + } + ); } @@ -2771,7 +2803,7 @@ void cProtocol190::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer) } } - m_Client->HandleWindowClick(WindowID, SlotNum, Action, Item); + m_Client->QueueDataCommit(&cClientHandle::HandleWindowClick, m_Client, WindowID, SlotNum, Action, Item); } @@ -2781,7 +2813,7 @@ void cProtocol190::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer) void cProtocol190::HandlePacketWindowClose(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID); - m_Client->HandleWindowClose(WindowID); + m_Client->QueueDataCommit(&cClientHandle::HandleWindowClose, m_Client, WindowID); } @@ -2801,13 +2833,19 @@ void cProtocol190::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockY); HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, BlockZ); HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Command); - m_Client->HandleCommandBlockBlockChange(BlockX, BlockY, BlockZ, Command); + m_Client->QueueDataCommit(&cClientHandle::HandleCommandBlockBlockChange, m_Client, BlockX, BlockY, BlockZ, Command); break; } default: { - m_Client->SendChat(Printf("Failure setting command block command; unhandled mode %u (0x%02x)", Mode, Mode), mtFailure); + m_Client->QueueDataCommit( + static_cast(&cClientHandle::SendChat), + m_Client, + Printf("Failure setting command block command; unhandled mode %u (0x%02x)", Mode, Mode), + mtFailure, + "" + ); LOG("Unhandled MC|AdvCdm packet mode."); return; } @@ -2826,19 +2864,19 @@ void cProtocol190::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const { HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect1); HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect2); - m_Client->HandleBeaconSelection(Effect1, Effect2); + m_Client->QueueDataCommit(&cClientHandle::HandleBeaconSelection, m_Client, Effect1, Effect2); return; } else if (a_Channel == "MC|ItemName") { HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, ItemName); - m_Client->HandleAnvilItemName(ItemName); + m_Client->QueueDataCommit(&cClientHandle::HandleAnvilItemName, m_Client, ItemName); return; } else if (a_Channel == "MC|TrSel") { HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, SlotNum); - m_Client->HandleNPCTrade(SlotNum); + m_Client->QueueDataCommit(&cClientHandle::HandleNPCTrade, m_Client, SlotNum); return; } LOG("Unhandled vanilla plugin channel: \"%s\".", a_Channel.c_str()); diff --git a/src/Protocol/Protocol19x.h b/src/Protocol/Protocol19x.h index d23653702..7c4a88789 100644 --- a/src/Protocol/Protocol19x.h +++ b/src/Protocol/Protocol19x.h @@ -258,7 +258,7 @@ protected: /** Converts the BlockFace received by the protocol into eBlockFace constants. If the received value doesn't match any of our eBlockFace constants, BLOCK_FACE_NONE is returned. */ - eBlockFace FaceIntToBlockFace(UInt32 a_FaceInt); + static eBlockFace FaceIntToBlockFace(UInt32 a_FaceInt); /** Writes the item data into a packet. */ void WriteItem(cPacketizer & a_Pkt, const cItem & a_Item); -- cgit v1.2.3