diff options
author | ForesterDev <11771800+ForesterDev@users.noreply.github.com> | 2020-03-12 20:06:15 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-12 17:06:15 +0100 |
commit | af6d207addfef177fb5ac3e7fa61ec93ced83d16 (patch) | |
tree | b13c33d01ada684127a9576c8a60b9352d590dde /src | |
parent | 535206594ce10c1d2f5547fc70bec3b715020dfa (diff) |
Core/PacketIO: update some combat packets to new system (#24236)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 36 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 25 | ||||
-rw-r--r-- | src/server/game/Handlers/CombatHandler.cpp | 34 | ||||
-rw-r--r-- | src/server/game/Server/Packets/AllPackets.h | 1 | ||||
-rw-r--r-- | src/server/game/Server/Packets/CombatPackets.cpp | 59 | ||||
-rw-r--r-- | src/server/game/Server/Packets/CombatPackets.h | 124 | ||||
-rw-r--r-- | src/server/game/Server/Protocol/Opcodes.cpp | 16 | ||||
-rw-r--r-- | src/server/game/Server/Protocol/Opcodes.h | 16 | ||||
-rw-r--r-- | src/server/game/Server/WorldSession.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Server/WorldSession.h | 9 |
10 files changed, 243 insertions, 79 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index e2f7fe49d91..244489628c0 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -34,6 +34,7 @@ #include "CharacterDatabaseCleaner.h" #include "Chat.h" #include "CinematicMgr.h" +#include "CombatPackets.h" #include "Common.h" #include "ConditionMgr.h" #include "CreatureAI.h" @@ -20300,12 +20301,6 @@ void Player::UpdateSpeakTime() /*** LOW LEVEL FUNCTIONS:Notifiers ***/ /*********************************************************/ -void Player::SendAttackSwingNotInRange() const -{ - WorldPacket data(SMSG_ATTACKSWING_NOTINRANGE, 0); - SendDirectMessage(&data); -} - void Player::SavePositionInDB(WorldLocation const& loc, uint16 zoneId, ObjectGuid guid, SQLTransaction& trans) { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHARACTER_POSITION); @@ -20347,35 +20342,36 @@ void Player::Customize(CharacterCustomizeInfo const* customizeInfo, SQLTransacti CharacterDatabase.ExecuteOrAppend(trans, stmt); } -void Player::SendAttackSwingDeadTarget() const +void Player::SendAttackSwingCantAttack() const { - WorldPacket data(SMSG_ATTACKSWING_DEADTARGET, 0); - SendDirectMessage(&data); + SendDirectMessage(WorldPackets::Combat::AttackSwingCantAttack().Write()); } -void Player::SendAttackSwingCantAttack() const +void Player::SendAttackSwingCancelAttack() const { - WorldPacket data(SMSG_ATTACKSWING_CANT_ATTACK, 0); - SendDirectMessage(&data); + SendDirectMessage(WorldPackets::Combat::CancelCombat().Write()); } -void Player::SendAttackSwingCancelAttack() const +void Player::SendAttackSwingDeadTarget() const { - WorldPacket data(SMSG_CANCEL_COMBAT, 0); - SendDirectMessage(&data); + SendDirectMessage(WorldPackets::Combat::AttackSwingDeadTarget().Write()); +} + +void Player::SendAttackSwingNotInRange() const +{ + SendDirectMessage(WorldPackets::Combat::AttackSwingNotInRange().Write()); } void Player::SendAttackSwingBadFacingAttack() const { - WorldPacket data(SMSG_ATTACKSWING_BADFACING, 0); - SendDirectMessage(&data); + SendDirectMessage(WorldPackets::Combat::AttackSwingBadFacing().Write()); } void Player::SendAutoRepeatCancel(Unit* target) { - WorldPacket data(SMSG_CANCEL_AUTO_REPEAT, target->GetPackGUID().size()); - data << target->GetPackGUID(); // may be it's target guid - SendMessageToSet(&data, true); + WorldPackets::Combat::CancelAutoRepeat cancelAutoRepeat; + cancelAutoRepeat.Guid = target->GetPackGUID(); // may be it's target guid + SendMessageToSet(cancelAutoRepeat.Write(), true); } void Player::SendExplorationExperience(uint32 Area, uint32 Experience) const diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 7518977c4e1..627d0c7228e 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -26,6 +26,7 @@ #include "Chat.h" #include "ChatPackets.h" #include "ChatTextBuilder.h" +#include "CombatPackets.h" #include "Common.h" #include "ConditionMgr.h" #include "CreatureAI.h" @@ -2275,30 +2276,20 @@ float Unit::CalculateSpellpowerCoefficientLevelPenalty(SpellInfo const* spellInf void Unit::SendMeleeAttackStart(Unit* victim) { - WorldPacket data(SMSG_ATTACKSTART, 8 + 8); - data << uint64(GetGUID()); - data << uint64(victim->GetGUID()); - SendMessageToSet(&data, true); - TC_LOG_DEBUG("entities.unit", "WORLD: Sent SMSG_ATTACKSTART"); + WorldPackets::Combat::AttackStart packet; + packet.Attacker = GetGUID(); + packet.Victim = victim->GetGUID(); + SendMessageToSet(packet.Write(), true); } void Unit::SendMeleeAttackStop(Unit* victim) { - WorldPacket data(SMSG_ATTACKSTOP, (8+8+4)); - data << GetPackGUID(); - if (victim) - data << victim->GetPackGUID(); - else - data << uint8(0); - - data << uint32(0); //! Can also take the value 0x01, which seems related to updating rotation - SendMessageToSet(&data, true); - TC_LOG_DEBUG("entities.unit", "WORLD: Sent SMSG_ATTACKSTOP"); + SendMessageToSet(WorldPackets::Combat::SAttackStop(this, victim).Write(), true); if (victim) - TC_LOG_DEBUG("entities.unit", "%s %u stopped attacking %s %u", (GetTypeId() == TYPEID_PLAYER ? "Player" : "Creature"), GetGUID().GetCounter(), (victim->GetTypeId() == TYPEID_PLAYER ? "player" : "creature"), victim->GetGUID().GetCounter()); + TC_LOG_DEBUG("entities.unit", "%s stopped attacking %s", GetGUID().ToString().c_str(), victim->GetGUID().ToString().c_str()); else - TC_LOG_DEBUG("entities.unit", "%s %u stopped attacking", (GetTypeId() == TYPEID_PLAYER ? "Player" : "Creature"), GetGUID().GetCounter()); + TC_LOG_DEBUG("entities.unit", "%s stopped attacking", GetGUID().ToString().c_str()); } bool Unit::isSpellBlocked(Unit* victim, SpellInfo const* spellProto, WeaponAttackType attackType) diff --git a/src/server/game/Handlers/CombatHandler.cpp b/src/server/game/Handlers/CombatHandler.cpp index 0d28d86da5a..2e768bb85f2 100644 --- a/src/server/game/Handlers/CombatHandler.cpp +++ b/src/server/game/Handlers/CombatHandler.cpp @@ -16,6 +16,7 @@ */ #include "WorldSession.h" +#include "CombatPackets.h" #include "Common.h" #include "CreatureAI.h" #include "DBCStructure.h" @@ -25,30 +26,25 @@ #include "Vehicle.h" #include "WorldPacket.h" -void WorldSession::HandleAttackSwingOpcode(WorldPacket& recvData) +void WorldSession::HandleAttackSwingOpcode(WorldPackets::Combat::AttackSwing& packet) { - ObjectGuid guid; - recvData >> guid; + Unit* enemy = ObjectAccessor::GetUnit(*_player, packet.Victim); - TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_ATTACKSWING Message %s", guid.ToString().c_str()); - - Unit* pEnemy = ObjectAccessor::GetUnit(*_player, guid); - - if (!pEnemy) + if (!enemy) { // stop attack state at client SendAttackStop(nullptr); return; } - if (!_player->IsValidAttackTarget(pEnemy)) + if (!_player->IsValidAttackTarget(enemy)) { // stop attack state at client - SendAttackStop(pEnemy); + SendAttackStop(enemy); return; } - //! Client explicitly checks the following before sending CMSG_ATTACKSWING packet, + //! Client explicitly checks the following before sending CMSG_ATTACK_SWING packet, //! so we'll place the same check here. Note that it might be possible to reuse this snippet //! in other places as well. if (Vehicle* vehicle = _player->GetVehicle()) @@ -57,15 +53,15 @@ void WorldSession::HandleAttackSwingOpcode(WorldPacket& recvData) ASSERT(seat); if (!(seat->m_flags & VEHICLE_SEAT_FLAG_CAN_ATTACK)) { - SendAttackStop(pEnemy); + SendAttackStop(enemy); return; } } - _player->Attack(pEnemy, true); + _player->Attack(enemy, true); } -void WorldSession::HandleAttackStopOpcode(WorldPacket & /*recvData*/) +void WorldSession::HandleAttackStopOpcode(WorldPackets::Combat::AttackStop& /*packet*/) { GetPlayer()->AttackStop(); } @@ -88,13 +84,5 @@ void WorldSession::HandleSetSheathedOpcode(WorldPacket& recvData) void WorldSession::SendAttackStop(Unit const* enemy) { - WorldPacket data(SMSG_ATTACKSTOP, (8+8+4)); // we guess size - data << GetPlayer()->GetPackGUID(); - if (enemy) - data << enemy->GetPackGUID(); - else - data << uint8(0); - - data << uint32(0); // unk, can be 1 also - SendPacket(&data); + SendPacket(WorldPackets::Combat::SAttackStop(GetPlayer(), enemy).Write()); } diff --git a/src/server/game/Server/Packets/AllPackets.h b/src/server/game/Server/Packets/AllPackets.h index c161bc8d871..e377bb07215 100644 --- a/src/server/game/Server/Packets/AllPackets.h +++ b/src/server/game/Server/Packets/AllPackets.h @@ -19,6 +19,7 @@ #define AllPackets_h__ #include "ChatPackets.h" +#include "CombatPackets.h" #include "NPCPackets.h" #include "MiscPackets.h" #include "QueryPackets.h" diff --git a/src/server/game/Server/Packets/CombatPackets.cpp b/src/server/game/Server/Packets/CombatPackets.cpp new file mode 100644 index 00000000000..fa9d0370dd2 --- /dev/null +++ b/src/server/game/Server/Packets/CombatPackets.cpp @@ -0,0 +1,59 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "CombatPackets.h" +#include "Unit.h" + +void WorldPackets::Combat::AttackSwing::Read() +{ + _worldPacket >> Victim; +} + +WorldPacket const* WorldPackets::Combat::AttackStart::Write() +{ + _worldPacket << Attacker; + _worldPacket << Victim; + + return &_worldPacket; +} + +WorldPackets::Combat::SAttackStop::SAttackStop(Unit const* attacker, Unit const* victim) : ServerPacket(SMSG_ATTACK_STOP, 8 + 8 + 4) +{ + Attacker = attacker->GetPackGUID(); + if (victim) + { + Victim = victim->GetPackGUID(); + NowDead = victim->isDead(); + } +} + +WorldPacket const* WorldPackets::Combat::SAttackStop::Write() +{ + _worldPacket << Attacker; + _worldPacket << Victim; + _worldPacket << uint32(NowDead); + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Combat::CancelAutoRepeat::Write() +{ + _worldPacket << Guid; + + return &_worldPacket; +} + diff --git a/src/server/game/Server/Packets/CombatPackets.h b/src/server/game/Server/Packets/CombatPackets.h new file mode 100644 index 00000000000..6b6fc7c85ee --- /dev/null +++ b/src/server/game/Server/Packets/CombatPackets.h @@ -0,0 +1,124 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef CombatPackets_h__ +#define CombatPackets_h__ + +#include "Packet.h" +#include "ObjectGuid.h" + +class Unit; + +namespace WorldPackets +{ + namespace Combat + { + class AttackSwing final : public ClientPacket + { + public: + AttackSwing(WorldPacket&& packet) : ClientPacket(CMSG_ATTACK_SWING, std::move(packet)) { } + + void Read() override; + + ObjectGuid Victim; + }; + + class AttackSwingNotInRange final : public ServerPacket + { + public: + AttackSwingNotInRange() : ServerPacket(SMSG_ATTACK_SWING_NOT_IN_RANGE, 0) { } + + WorldPacket const* Write() override { return &_worldPacket; } + }; + + class AttackSwingBadFacing final : public ServerPacket + { + public: + AttackSwingBadFacing() : ServerPacket(SMSG_ATTACK_SWING_BAD_FACING, 0) { } + + WorldPacket const* Write() override { return &_worldPacket; } + }; + + class AttackSwingDeadTarget final : public ServerPacket + { + public: + AttackSwingDeadTarget() : ServerPacket(SMSG_ATTACK_SWING_DEAD_TARGET, 0) { } + + WorldPacket const* Write() override { return &_worldPacket; } + }; + + class AttackSwingCantAttack final : public ServerPacket + { + public: + AttackSwingCantAttack() : ServerPacket(SMSG_ATTACK_SWING_CANT_ATTACK, 0) { } + + WorldPacket const* Write() override { return &_worldPacket; } + }; + + class AttackStop final : public ClientPacket + { + public: + AttackStop(WorldPacket&& packet) : ClientPacket(CMSG_ATTACK_STOP, std::move(packet)) { } + + void Read() override { } + }; + + class AttackStart final : public ServerPacket + { + public: + AttackStart() : ServerPacket(SMSG_ATTACK_START, 8 + 8) { } + + WorldPacket const* Write() override; + + ObjectGuid Attacker; + ObjectGuid Victim; + }; + + class SAttackStop final : public ServerPacket + { + public: + SAttackStop() : ServerPacket(SMSG_ATTACK_STOP, 8 + 8 + 4) { } + SAttackStop(Unit const* attacker, Unit const* victim); + + WorldPacket const* Write() override; + + PackedGuid Attacker; + PackedGuid Victim; + bool NowDead = false; + }; + + class CancelCombat final : public ServerPacket + { + public: + CancelCombat() : ServerPacket(SMSG_CANCEL_COMBAT, 0) { } + + WorldPacket const* Write() override { return &_worldPacket; } + }; + + class CancelAutoRepeat final : public ServerPacket + { + public: + CancelAutoRepeat() : ServerPacket(SMSG_CANCEL_AUTO_REPEAT, 8) { } + + WorldPacket const* Write() override; + + PackedGuid Guid; + }; + } +} + +#endif // CombatPackets_h__ diff --git a/src/server/game/Server/Protocol/Opcodes.cpp b/src/server/game/Server/Protocol/Opcodes.cpp index fa8b1ecfbde..8dffc86d4c3 100644 --- a/src/server/game/Server/Protocol/Opcodes.cpp +++ b/src/server/game/Server/Protocol/Opcodes.cpp @@ -449,15 +449,15 @@ void OpcodeTable::Initialize() /*0x13E*/ DEFINE_HANDLER(CMSG_DELETEEQUIPMENT_SET, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleEquipmentSetDelete ); /*0x13F*/ DEFINE_HANDLER(CMSG_INSTANCE_LOCK_RESPONSE, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleInstanceLockResponse ); /*0x140*/ DEFINE_HANDLER(CMSG_DEBUG_PASSIVE_AURA, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL ); - /*0x141*/ DEFINE_HANDLER(CMSG_ATTACKSWING, STATUS_LOGGEDIN, PROCESS_INPLACE, &WorldSession::HandleAttackSwingOpcode ); - /*0x142*/ DEFINE_HANDLER(CMSG_ATTACKSTOP, STATUS_LOGGEDIN, PROCESS_INPLACE, &WorldSession::HandleAttackStopOpcode ); - /*0x143*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACKSTART, STATUS_NEVER); - /*0x144*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACKSTOP, STATUS_NEVER); - /*0x145*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACKSWING_NOTINRANGE, STATUS_NEVER); - /*0x146*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACKSWING_BADFACING, STATUS_NEVER); + /*0x141*/ DEFINE_HANDLER(CMSG_ATTACK_SWING, STATUS_LOGGEDIN, PROCESS_INPLACE, &WorldSession::HandleAttackSwingOpcode ); + /*0x142*/ DEFINE_HANDLER(CMSG_ATTACK_STOP, STATUS_LOGGEDIN, PROCESS_INPLACE, &WorldSession::HandleAttackStopOpcode ); + /*0x143*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACK_START, STATUS_NEVER); + /*0x144*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACK_STOP, STATUS_NEVER); + /*0x145*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACK_SWING_NOT_IN_RANGE, STATUS_NEVER); + /*0x146*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACK_SWING_BAD_FACING, STATUS_NEVER); /*0x147*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_INSTANCE_LOCK_WARNING_QUERY, STATUS_NEVER); - /*0x148*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACKSWING_DEADTARGET, STATUS_NEVER); - /*0x149*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACKSWING_CANT_ATTACK, STATUS_NEVER); + /*0x148*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACK_SWING_DEAD_TARGET, STATUS_NEVER); + /*0x149*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACK_SWING_CANT_ATTACK, STATUS_NEVER); /*0x14A*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_ATTACKERSTATEUPDATE, STATUS_NEVER); /*0x14B*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_BATTLEFIELD_PORT_DENIED, STATUS_NEVER); /*0x14C*/ DEFINE_HANDLER(CMSG_PERFORM_ACTION_SET, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL ); diff --git a/src/server/game/Server/Protocol/Opcodes.h b/src/server/game/Server/Protocol/Opcodes.h index ac4fde65eca..6f09e5d1561 100644 --- a/src/server/game/Server/Protocol/Opcodes.h +++ b/src/server/game/Server/Protocol/Opcodes.h @@ -347,15 +347,15 @@ enum Opcodes : uint16 CMSG_DELETEEQUIPMENT_SET = 0x13E, CMSG_INSTANCE_LOCK_RESPONSE = 0x13F, CMSG_DEBUG_PASSIVE_AURA = 0x140, - CMSG_ATTACKSWING = 0x141, - CMSG_ATTACKSTOP = 0x142, - SMSG_ATTACKSTART = 0x143, - SMSG_ATTACKSTOP = 0x144, - SMSG_ATTACKSWING_NOTINRANGE = 0x145, - SMSG_ATTACKSWING_BADFACING = 0x146, + CMSG_ATTACK_SWING = 0x141, + CMSG_ATTACK_STOP = 0x142, + SMSG_ATTACK_START = 0x143, + SMSG_ATTACK_STOP = 0x144, + SMSG_ATTACK_SWING_NOT_IN_RANGE = 0x145, + SMSG_ATTACK_SWING_BAD_FACING = 0x146, SMSG_INSTANCE_LOCK_WARNING_QUERY = 0x147, - SMSG_ATTACKSWING_DEADTARGET = 0x148, - SMSG_ATTACKSWING_CANT_ATTACK = 0x149, + SMSG_ATTACK_SWING_DEAD_TARGET = 0x148, + SMSG_ATTACK_SWING_CANT_ATTACK = 0x149, SMSG_ATTACKERSTATEUPDATE = 0x14A, SMSG_BATTLEFIELD_PORT_DENIED = 0x14B, CMSG_PERFORM_ACTION_SET = 0x14C, diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index df5197be094..765efafd344 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -1359,7 +1359,7 @@ uint32 WorldSession::DosProtection::GetMaxPacketCounterAllowed(uint16 opcode) co case CMSG_NAME_QUERY: // 0 1 case CMSG_PET_NAME_QUERY: // 0 1 case CMSG_NPC_TEXT_QUERY: // 0 1 - case CMSG_ATTACKSTOP: // 0 1 + case CMSG_ATTACK_STOP: // 0 1 case CMSG_QUERY_QUESTS_COMPLETED: // 0 1 case CMSG_QUERY_TIME: // 0 1 case CMSG_CORPSE_MAP_POSITION_QUERY: // 0 1 diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index 641e902ac55..6e8379b994b 100644 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -82,6 +82,11 @@ namespace WorldPackets { class EmoteClient; } + namespace Combat + { + class AttackSwing; + class AttackStop; + } namespace NPC { class Hello; @@ -748,8 +753,8 @@ class TC_GAME_API WorldSession void HandleAutoStoreBankItemOpcode(WorldPacket& recvPacket); void HandleWrapItemOpcode(WorldPacket& recvPacket); - void HandleAttackSwingOpcode(WorldPacket& recvPacket); - void HandleAttackStopOpcode(WorldPacket& recvPacket); + void HandleAttackSwingOpcode(WorldPackets::Combat::AttackSwing& packet); + void HandleAttackStopOpcode(WorldPackets::Combat::AttackStop& packet); void HandleSetSheathedOpcode(WorldPacket& recvPacket); void HandleUseItemOpcode(WorldPacket& recvPacket); |