diff options
author | joschiwald <joschiwald.trinity@gmail.com> | 2015-07-26 15:09:00 +0200 |
---|---|---|
committer | joschiwald <joschiwald.trinity@gmail.com> | 2015-07-26 15:09:00 +0200 |
commit | 5c813f6f028aa36c374d7039fd1186802bc8e8af (patch) | |
tree | a2bd214f21e305a0bccbe2b0369199326166911c /src | |
parent | 7db5f65f03c87978440f49dc4c0a744883977d82 (diff) |
Core/PacketIO: updated totem packets
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Totem/Totem.cpp | 24 | ||||
-rw-r--r-- | src/server/game/Handlers/SpellHandler.cpp | 33 | ||||
-rw-r--r-- | src/server/game/Server/Packets/TotemPackets.cpp | 43 | ||||
-rw-r--r-- | src/server/game/Server/Packets/TotemPackets.h | 66 | ||||
-rw-r--r-- | src/server/game/Server/Protocol/Opcodes.cpp | 7 | ||||
-rw-r--r-- | src/server/game/Server/WorldSession.h | 9 |
6 files changed, 145 insertions, 37 deletions
diff --git a/src/server/game/Entities/Totem/Totem.cpp b/src/server/game/Entities/Totem/Totem.cpp index 81232bf23d8..3dea9368bf8 100644 --- a/src/server/game/Entities/Totem/Totem.cpp +++ b/src/server/game/Entities/Totem/Totem.cpp @@ -19,12 +19,11 @@ #include "Totem.h" #include "Group.h" #include "ObjectMgr.h" -#include "Opcodes.h" #include "Player.h" #include "SpellHistory.h" #include "SpellMgr.h" #include "SpellInfo.h" -#include "WorldPacket.h" +#include "TotemPackets.h" Totem::Totem(SummonPropertiesEntry const* properties, Unit* owner) : Minion(properties, owner, false) { @@ -55,19 +54,20 @@ void Totem::Update(uint32 time) void Totem::InitStats(uint32 duration) { // client requires SMSG_TOTEM_CREATED to be sent before adding to world and before removing old totem - if (GetOwner()->GetTypeId() == TYPEID_PLAYER - && m_Properties->Slot >= SUMMON_SLOT_TOTEM - && m_Properties->Slot < MAX_TOTEM_SLOT) + if (Player* owner = GetOwner()->ToPlayer()) { - WorldPacket data(SMSG_TOTEM_CREATED, 1 + 8 + 4 + 4); - data << uint8(m_Properties->Slot - 1); - data << GetGUID(); - data << uint32(duration); - data << uint32(GetUInt32Value(UNIT_CREATED_BY_SPELL)); - GetOwner()->ToPlayer()->SendDirectMessage(&data); + if (m_Properties->Slot >= SUMMON_SLOT_TOTEM && m_Properties->Slot < MAX_TOTEM_SLOT) + { + WorldPackets::Totem::TotemCreated data; + data.Totem = GetGUID(); + data.Slot = m_Properties->Slot - SUMMON_SLOT_TOTEM; + data.Duration = duration; + data.SpellID = GetUInt32Value(UNIT_CREATED_BY_SPELL); + owner->SendDirectMessage(data.Write()); + } // set display id depending on caster's race - SetDisplayId(GetOwner()->GetModelForTotem(PlayerTotemType(m_Properties->ID))); + SetDisplayId(owner->GetModelForTotem(PlayerTotemType(m_Properties->ID))); } Minion::InitStats(duration); diff --git a/src/server/game/Handlers/SpellHandler.cpp b/src/server/game/Handlers/SpellHandler.cpp index 7655d2766f3..ce6abe2fdd5 100644 --- a/src/server/game/Handlers/SpellHandler.cpp +++ b/src/server/game/Handlers/SpellHandler.cpp @@ -16,25 +16,23 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "WorldSession.h" #include "Common.h" +#include "Config.h" #include "DBCStores.h" -#include "WorldPacket.h" -#include "WorldSession.h" -#include "ObjectMgr.h" +#include "GameObjectAI.h" +#include "GameObjectPackets.h" #include "GuildMgr.h" -#include "SpellMgr.h" #include "Log.h" -#include "Opcodes.h" -#include "Spell.h" -#include "Totem.h" -#include "SpellAuras.h" +#include "Player.h" +#include "ObjectMgr.h" #include "ScriptMgr.h" -#include "GameObjectAI.h" +#include "Spell.h" #include "SpellAuraEffects.h" -#include "Player.h" -#include "Config.h" +#include "SpellMgr.h" #include "SpellPackets.h" -#include "GameObjectPackets.h" +#include "Totem.h" +#include "TotemPackets.h" void WorldSession::HandleUseItemOpcode(WorldPackets::Spells::UseItem& packet) { @@ -444,18 +442,15 @@ void WorldSession::HandleCancelChanneling(WorldPacket& recvData) mover->InterruptSpell(CURRENT_CHANNELED_SPELL); } -void WorldSession::HandleTotemDestroyed(WorldPacket& recvPacket) +void WorldSession::HandleTotemDestroyed(WorldPackets::Totem::TotemDestroyed& totemDestroyed) { // ignore for remote control state if (_player->m_mover != _player) return; - uint8 slotId; - ObjectGuid guid; - recvPacket >> slotId; - recvPacket >> guid; + uint8 slotId = totemDestroyed.Slot; + slotId += SUMMON_SLOT_TOTEM; - ++slotId; if (slotId >= MAX_TOTEM_SLOT) return; @@ -463,7 +458,7 @@ void WorldSession::HandleTotemDestroyed(WorldPacket& recvPacket) return; Creature* totem = GetPlayer()->GetMap()->GetCreature(_player->m_SummonSlot[slotId]); - if (totem && totem->IsTotem() && totem->GetGUID() == guid) + if (totem && totem->IsTotem() && totem->GetGUID() == totemDestroyed.TotemGUID) totem->ToTotem()->UnSummon(); } diff --git a/src/server/game/Server/Packets/TotemPackets.cpp b/src/server/game/Server/Packets/TotemPackets.cpp new file mode 100644 index 00000000000..150e88812ed --- /dev/null +++ b/src/server/game/Server/Packets/TotemPackets.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/> + * + * 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 "TotemPackets.h" + +void WorldPackets::Totem::TotemDestroyed::Read() +{ + _worldPacket >> Slot; + _worldPacket >> TotemGUID; +} + +WorldPacket const* WorldPackets::Totem::TotemCreated::Write() +{ + _worldPacket << Slot; + _worldPacket << Totem; + _worldPacket << int32(Duration); + _worldPacket << int32(SpellID); + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Totem::TotemMoved::Write() +{ + _worldPacket << uint8(Slot); + _worldPacket << uint8(NewSlot); + _worldPacket << Totem; + + return &_worldPacket; +} diff --git a/src/server/game/Server/Packets/TotemPackets.h b/src/server/game/Server/Packets/TotemPackets.h new file mode 100644 index 00000000000..519025d4cba --- /dev/null +++ b/src/server/game/Server/Packets/TotemPackets.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/> + * + * 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 TotemPackets_h__ +#define TotemPackets_h__ + +#include "Packet.h" +#include "ObjectGuid.h" + +namespace WorldPackets +{ + namespace Totem + { + class TotemDestroyed final : public ClientPacket + { + public: + TotemDestroyed(WorldPacket&& packet) : ClientPacket(CMSG_TOTEM_DESTROYED, std::move(packet)) { } + + void Read() override; + + ObjectGuid TotemGUID; + uint8 Slot = 0; + }; + + class TotemCreated final : public ServerPacket + { + public: + TotemCreated() : ServerPacket(SMSG_TOTEM_CREATED, 25) { } + + WorldPacket const* Write() override; + + ObjectGuid Totem; + int32 SpellID = 0; + int32 Duration = 0; + int8 Slot = 0; + }; + + class TotemMoved final : public ServerPacket + { + public: + TotemMoved() : ServerPacket(SMSG_TOTEM_MOVED, 18) { } + + WorldPacket const* Write() override; + + ObjectGuid Totem; + uint8 Slot = 0; + uint8 NewSlot = 0; + }; + } +} + +#endif // TotemPackets_h__ diff --git a/src/server/game/Server/Protocol/Opcodes.cpp b/src/server/game/Server/Protocol/Opcodes.cpp index 84df89eddf6..bc2df0d7956 100644 --- a/src/server/game/Server/Protocol/Opcodes.cpp +++ b/src/server/game/Server/Protocol/Opcodes.cpp @@ -52,6 +52,7 @@ #include "Packets/TalentPackets.h" #include "Packets/TicketPackets.h" #include "Packets/TokenPackets.h" +#include "Packets/TotemPackets.h" #include "Packets/TradePackets.h" #include "Packets/VehiclePackets.h" #include "Packets/VoidStoragePackets.h" @@ -783,7 +784,7 @@ void OpcodeTable::Initialize() DEFINE_HANDLER(CMSG_TIME_SYNC_RESPONSE_FAILED, STATUS_UNHANDLED, PROCESS_INPLACE, WorldPackets::Null, &WorldSession::Handle_NULL); DEFINE_HANDLER(CMSG_TOGGLE_DIFFICULTY, STATUS_UNHANDLED, PROCESS_INPLACE, WorldPackets::Null, &WorldSession::Handle_NULL); DEFINE_OPCODE_HANDLER_OLD(CMSG_TOGGLE_PVP, STATUS_UNHANDLED, PROCESS_THREADUNSAFE, &WorldSession::HandleTogglePvP ); - DEFINE_OPCODE_HANDLER_OLD(CMSG_TOTEM_DESTROYED, STATUS_UNHANDLED, PROCESS_THREADUNSAFE, &WorldSession::HandleTotemDestroyed ); + DEFINE_HANDLER(CMSG_TOTEM_DESTROYED, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, WorldPackets::Totem::TotemDestroyed, &WorldSession::HandleTotemDestroyed); DEFINE_HANDLER(CMSG_TOY_SET_FAVORITE, STATUS_UNHANDLED, PROCESS_INPLACE, WorldPackets::Null, &WorldSession::Handle_NULL); DEFINE_HANDLER(CMSG_TRAINER_BUY_SPELL, STATUS_UNHANDLED, PROCESS_THREADUNSAFE, WorldPackets::NPC::TrainerBuySpell, &WorldSession::HandleTrainerBuySpellOpcode); DEFINE_HANDLER(CMSG_TRAINER_LIST, STATUS_UNHANDLED, PROCESS_THREADUNSAFE, WorldPackets::NPC::Hello, &WorldSession::HandleTrainerListOpcode); @@ -1682,8 +1683,8 @@ void OpcodeTable::Initialize() DEFINE_SERVER_OPCODE_HANDLER(SMSG_TIME_SYNC_REQUEST, STATUS_NEVER, CONNECTION_TYPE_INSTANCE); DEFINE_SERVER_OPCODE_HANDLER(SMSG_TITLE_EARNED, STATUS_NEVER, CONNECTION_TYPE_REALM); DEFINE_SERVER_OPCODE_HANDLER(SMSG_TITLE_LOST, STATUS_NEVER, CONNECTION_TYPE_REALM); - DEFINE_SERVER_OPCODE_HANDLER(SMSG_TOTEM_CREATED, STATUS_UNHANDLED, CONNECTION_TYPE_REALM); - DEFINE_SERVER_OPCODE_HANDLER(SMSG_TOTEM_MOVED, STATUS_UNHANDLED, CONNECTION_TYPE_REALM); + DEFINE_SERVER_OPCODE_HANDLER(SMSG_TOTEM_CREATED, STATUS_NEVER, CONNECTION_TYPE_REALM); + DEFINE_SERVER_OPCODE_HANDLER(SMSG_TOTEM_MOVED, STATUS_NEVER, CONNECTION_TYPE_REALM); DEFINE_SERVER_OPCODE_HANDLER(SMSG_TRADE_STATUS, STATUS_UNHANDLED, CONNECTION_TYPE_INSTANCE); DEFINE_SERVER_OPCODE_HANDLER(SMSG_TRADE_UPDATED, STATUS_UNHANDLED, CONNECTION_TYPE_INSTANCE); DEFINE_SERVER_OPCODE_HANDLER(SMSG_TRAINER_BUY_FAILED, STATUS_UNHANDLED, CONNECTION_TYPE_REALM); diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index 888bbc522b6..9c092ec98a1 100644 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -28,10 +28,8 @@ #include "AddonMgr.h" #include "DatabaseEnv.h" #include "World.h" -#include "Opcodes.h" #include "Packet.h" #include "Cryptography/BigNumber.h" -#include "Opcodes.h" #include "AccountMgr.h" #include <unordered_set> @@ -525,6 +523,11 @@ namespace WorldPackets class RequestWowTokenMarketPrice; } + namespace Totem + { + class TotemDestroyed; + } + namespace Trade { class AcceptTrade; @@ -1350,7 +1353,7 @@ class WorldSession void HandleSetActionBarToggles(WorldPackets::Character::SetActionBarToggles& packet); - void HandleTotemDestroyed(WorldPacket& recvData); + void HandleTotemDestroyed(WorldPackets::Totem::TotemDestroyed& totemDestroyed); void HandleDismissCritter(WorldPacket& recvData); //Battleground |