From 45d5f647b5439c14948b2ddf0c42a1e7f106e031 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Sun, 10 Jan 2021 09:40:17 +0100 Subject: [PATCH] Core/Packets: converted SMSG_UPDATE_LAST_INSTANCE, SMSG_UPDATE_INSTANCE_OWNERSHIP and SMSG_INSTANCE_INFO to packet class --- src/server/game/Entities/Player/Player.cpp | 64 ++++++++-------- src/server/game/Server/Packets/AllPackets.h | 1 + .../game/Server/Packets/InstancePackets.cpp | 56 ++++++++++++++ .../game/Server/Packets/InstancePackets.h | 73 +++++++++++++++++++ src/server/game/Server/Protocol/Opcodes.cpp | 2 +- src/server/game/Server/Protocol/Opcodes.h | 2 +- 6 files changed, 166 insertions(+), 32 deletions(-) create mode 100644 src/server/game/Server/Packets/InstancePackets.cpp create mode 100644 src/server/game/Server/Packets/InstancePackets.h diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 53b376cf0c..7d181d718d 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -59,6 +59,7 @@ #include "GuildMgr.h" #include "InstanceSaveMgr.h" #include "InstanceScript.h" +#include "InstancePackets.h" #include "ItemPackets.h" #include "KillRewarder.h" #include "Language.h" @@ -19052,12 +19053,7 @@ void Player::SetPendingBind(uint32 instanceId, uint32 bindTimer) void Player::SendRaidInfo() { - uint32 counter = 0; - - WorldPacket data(SMSG_RAID_INSTANCE_INFO, 4); - - size_t p_counter = data.wpos(); - data << uint32(counter); // placeholder + WorldPackets::Instance::InstanceInfo instanceInfo; time_t now = GameTime::GetGameTime(); @@ -19069,30 +19065,38 @@ void Player::SendRaidInfo() if (bind.perm) { InstanceSave* save = bind.save; - bool isHeroic = save->GetDifficulty() == RAID_DIFFICULTY_10MAN_HEROIC || save->GetDifficulty() == RAID_DIFFICULTY_25MAN_HEROIC; - uint32 completedEncounters = 0; + + WorldPackets::Instance::InstanceLock lockInfos; + + Difficulty difficulty = save->GetDifficulty(); + lockInfos.Heroic = (difficulty == RAID_DIFFICULTY_10MAN_HEROIC || difficulty == RAID_DIFFICULTY_25MAN_HEROIC); + + if (lockInfos.Heroic) + lockInfos.Difficulty = difficulty == RAID_DIFFICULTY_10MAN_HEROIC ? RAID_DIFFICULTY_10MAN_NORMAL : RAID_DIFFICULTY_25MAN_NORMAL; + else + lockInfos.Difficulty = difficulty; + + lockInfos.InstanceID = save->GetInstanceId(); + lockInfos.MapID = save->GetMapId(); + if (bind.extendState != EXTEND_STATE_EXTENDED) + lockInfos.TimeRemaining = save->GetResetTime() - now; + else + lockInfos.TimeRemaining = sInstanceSaveMgr->GetSubsequentResetTime(save->GetMapId(), save->GetDifficulty(), save->GetResetTime()) - now; + + lockInfos.CompletedMask = 0; if (Map* map = sMapMgr->FindMap(save->GetMapId(), save->GetInstanceId())) if (InstanceScript* instanceScript = ((InstanceMap*)map)->GetInstanceScript()) - completedEncounters = instanceScript->GetCompletedEncounterMask(); + lockInfos.CompletedMask = instanceScript->GetCompletedEncounterMask(); - data << uint32(save->GetMapId()); // map id - data << uint32(save->GetDifficulty()); // difficulty - data << uint32(isHeroic); // heroic - data << uint64(save->GetInstanceId()); // instance id - data << uint8(bind.extendState != EXTEND_STATE_EXPIRED); // expired = 0 - data << uint8(bind.extendState == EXTEND_STATE_EXTENDED); // extended = 1 - time_t nextReset = save->GetResetTime(); - if (bind.extendState == EXTEND_STATE_EXTENDED) - nextReset = sInstanceSaveMgr->GetSubsequentResetTime(save->GetMapId(), save->GetDifficulty(), save->GetResetTime()); - data << uint32(nextReset - now); // reset time - data << uint32(completedEncounters); // completed encounters mask - ++counter; + lockInfos.Locked = bind.extendState != EXTEND_STATE_EXPIRED; + lockInfos.Extended = bind.extendState == EXTEND_STATE_EXTENDED; + + instanceInfo.LockList.push_back(lockInfos); } } } - data.put(p_counter, counter); - SendDirectMessage(&data); + SendDirectMessage(instanceInfo.Write()); } /* @@ -19115,10 +19119,10 @@ void Player::SendSavedInstances() } } - //Send opcode SMSG_UPDATE_INSTANCE_OWNERSHIP. true or false means, whether you have current raid/heroic instances - data.Initialize(SMSG_UPDATE_INSTANCE_OWNERSHIP, 4); - data << uint32(hasBeenSaved); - SendDirectMessage(&data); + // Send opcode SMSG_UPDATE_INSTANCE_OWNERSHIP. true or false means, whether you have current raid/heroic instances + WorldPackets::Instance::UpdateInstanceOwnership updateInstanceOwnership; + updateInstanceOwnership.IOwnInstance = hasBeenSaved; + SendDirectMessage(updateInstanceOwnership.Write()); if (!hasBeenSaved) return; @@ -19129,9 +19133,9 @@ void Player::SendSavedInstances() { if (itr->second.perm) { - data.Initialize(SMSG_UPDATE_LAST_INSTANCE, 4); - data << uint32(itr->second.save->GetMapId()); - SendDirectMessage(&data); + WorldPackets::Instance::UpdateLastInstance packet; + packet.MapID = itr->second.save->GetMapId(); + SendDirectMessage(packet.Write()); } } } diff --git a/src/server/game/Server/Packets/AllPackets.h b/src/server/game/Server/Packets/AllPackets.h index 4e3ae0d85b..2905786abd 100644 --- a/src/server/game/Server/Packets/AllPackets.h +++ b/src/server/game/Server/Packets/AllPackets.h @@ -24,6 +24,7 @@ #include "CombatLogPackets.h" #include "CombatPackets.h" #include "GuildPackets.h" +#include "InstancePackets.h" #include "ItemPackets.h" #include "LFGPackets.h" #include "MiscPackets.h" diff --git a/src/server/game/Server/Packets/InstancePackets.cpp b/src/server/game/Server/Packets/InstancePackets.cpp new file mode 100644 index 0000000000..d5a838eac5 --- /dev/null +++ b/src/server/game/Server/Packets/InstancePackets.cpp @@ -0,0 +1,56 @@ +/* + * 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 . + */ + +#include "InstancePackets.h" + +WorldPacket const* WorldPackets::Instance::UpdateLastInstance::Write() +{ + _worldPacket << uint32(MapID); + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Instance::UpdateInstanceOwnership::Write() +{ + _worldPacket << int32(IOwnInstance); + + return &_worldPacket; +} + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Instance::InstanceLock const& lockInfos) +{ + data << uint32(lockInfos.MapID); + data << uint32(lockInfos.Difficulty); + data << uint32(lockInfos.Heroic); + data << uint64(lockInfos.InstanceID); + data << uint8(lockInfos.Locked); + data << uint8(lockInfos.Extended); + data << uint32(lockInfos.TimeRemaining); + data << uint32(lockInfos.CompletedMask); + + return data; +} + +WorldPacket const* WorldPackets::Instance::InstanceInfo::Write() +{ + _worldPacket << int32(LockList.size()); + + for (InstanceLock const& instanceLock : LockList) + _worldPacket << instanceLock; + + return &_worldPacket; +} diff --git a/src/server/game/Server/Packets/InstancePackets.h b/src/server/game/Server/Packets/InstancePackets.h new file mode 100644 index 0000000000..e709d505e0 --- /dev/null +++ b/src/server/game/Server/Packets/InstancePackets.h @@ -0,0 +1,73 @@ +/* + * 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 . + */ + +#ifndef InstancePackets_h__ +#define InstancePackets_h__ + +#include "Packet.h" +#include "ObjectGuid.h" + +namespace WorldPackets +{ + namespace Instance + { + class UpdateLastInstance final : public ServerPacket + { + public: + UpdateLastInstance() : ServerPacket(SMSG_UPDATE_LAST_INSTANCE, 4) { } + + WorldPacket const* Write() override; + + uint32 MapID = 0; + }; + + class UpdateInstanceOwnership final : public ServerPacket + { + public: + UpdateInstanceOwnership() : ServerPacket(SMSG_UPDATE_INSTANCE_OWNERSHIP, 4) { } + + WorldPacket const* Write() override; + + int32 IOwnInstance = 0; // Used to control whether "Reset all instances" button appears on the UI - Script_CanShowResetInstances() + // but it has been deperecated in favor of simply checking group leader, being inside an instance or using dungeon finder + }; + + struct InstanceLock + { + uint64 InstanceID = 0u; + uint32 MapID = 0u; + uint32 Difficulty = 0u; + int32 TimeRemaining = 0; + uint32 CompletedMask = 0u; + bool Heroic = false; + bool Locked = false; + bool Extended = false; + }; + + class InstanceInfo final : public ServerPacket + { + public: + InstanceInfo() : ServerPacket(SMSG_INSTANCE_INFO, 4) { } + + WorldPacket const* Write() override; + + std::vector LockList; + }; + } +} + +#endif // InstancePackets_h__ diff --git a/src/server/game/Server/Protocol/Opcodes.cpp b/src/server/game/Server/Protocol/Opcodes.cpp index 6be0de280c..5ebd92a13d 100644 --- a/src/server/game/Server/Protocol/Opcodes.cpp +++ b/src/server/game/Server/Protocol/Opcodes.cpp @@ -941,6 +941,7 @@ void OpcodeTable::Initialize() DEFINE_SERVER_OPCODE_HANDLER(SMSG_INSPECT_RATED_BG_STATS, STATUS_UNHANDLED, CONNECTION_TYPE_REALM); DEFINE_SERVER_OPCODE_HANDLER(SMSG_INSPECT_RESULTS_UPDATE, STATUS_UNHANDLED, CONNECTION_TYPE_REALM); DEFINE_SERVER_OPCODE_HANDLER(SMSG_INSPECT_TALENT, STATUS_NEVER, CONNECTION_TYPE_REALM); + DEFINE_SERVER_OPCODE_HANDLER(SMSG_INSTANCE_INFO, STATUS_NEVER, CONNECTION_TYPE_REALM); DEFINE_SERVER_OPCODE_HANDLER(SMSG_INSTANCE_LOCK_WARNING_QUERY, STATUS_NEVER, CONNECTION_TYPE_REALM); DEFINE_SERVER_OPCODE_HANDLER(SMSG_INSTANCE_RESET, STATUS_NEVER, CONNECTION_TYPE_REALM); DEFINE_SERVER_OPCODE_HANDLER(SMSG_INSTANCE_RESET_FAILED, STATUS_NEVER, CONNECTION_TYPE_REALM); @@ -1155,7 +1156,6 @@ void OpcodeTable::Initialize() DEFINE_SERVER_OPCODE_HANDLER(SMSG_QUEST_POI_QUERY_RESPONSE, STATUS_NEVER, CONNECTION_TYPE_REALM); DEFINE_SERVER_OPCODE_HANDLER(SMSG_QUEST_QUERY_RESPONSE, STATUS_NEVER, CONNECTION_TYPE_REALM); DEFINE_SERVER_OPCODE_HANDLER(SMSG_RAID_GROUP_ONLY, STATUS_NEVER, CONNECTION_TYPE_REALM); - DEFINE_SERVER_OPCODE_HANDLER(SMSG_RAID_INSTANCE_INFO, STATUS_NEVER, CONNECTION_TYPE_REALM); DEFINE_SERVER_OPCODE_HANDLER(SMSG_RAID_INSTANCE_MESSAGE, STATUS_NEVER, CONNECTION_TYPE_REALM); DEFINE_SERVER_OPCODE_HANDLER(SMSG_RAID_MARKERS_CHANGED, STATUS_NEVER, CONNECTION_TYPE_REALM); DEFINE_SERVER_OPCODE_HANDLER(SMSG_RAID_READY_CHECK_THROTTLED_ERROR, STATUS_UNHANDLED, CONNECTION_TYPE_REALM); diff --git a/src/server/game/Server/Protocol/Opcodes.h b/src/server/game/Server/Protocol/Opcodes.h index 21db11309f..b04c67eed5 100644 --- a/src/server/game/Server/Protocol/Opcodes.h +++ b/src/server/game/Server/Protocol/Opcodes.h @@ -886,6 +886,7 @@ enum OpcodeServer SMSG_INSPECT_RATED_BG_STATS = 0x19A5, SMSG_INSPECT_RESULTS_UPDATE = 0x0C14, SMSG_INSPECT_TALENT = 0x4014, + SMSG_INSTANCE_INFO = 0x6626, SMSG_INSTANCE_LOCK_WARNING_QUERY = 0x4F17, SMSG_INSTANCE_RESET = 0x6F05, SMSG_INSTANCE_RESET_FAILED = 0x4725, @@ -1113,7 +1114,6 @@ enum OpcodeServer SMSG_QUEST_POI_QUERY_RESPONSE = 0x6304, SMSG_QUEST_QUERY_RESPONSE = 0x6936, SMSG_RAID_GROUP_ONLY = 0x0837, - SMSG_RAID_INSTANCE_INFO = 0x6626, SMSG_RAID_INSTANCE_MESSAGE = 0x6E15, SMSG_RAID_MARKERS_CHANGED = 0x10A1, SMSG_RAID_READY_CHECK_THROTTLED_ERROR = 0x2607,