From 144b0ca9a4058e54f937bf0ff3725fcb29481f70 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Mon, 2 Sep 2019 20:54:03 +0200 Subject: [PATCH] Core/Packets: updated SMSG_GUILD_EVENT, SMSG_GUILD_MEMBER_DAILY_RESET, SMSG_GUILD_REPUTATION_WEEKLY_CAP and SMSG_GUILD_XP to packet class --- src/server/game/Entities/Player/Player.cpp | 2 +- src/server/game/Entities/Player/Player.h | 2 +- src/server/game/Guilds/Guild.cpp | 74 +++++++++---------- src/server/game/Guilds/Guild.h | 6 +- .../game/Server/Packets/GuildPackets.cpp | 29 ++++++++ src/server/game/Server/Packets/GuildPackets.h | 44 +++++++++++ 6 files changed, 113 insertions(+), 44 deletions(-) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index e90263ca91e..5a379ca9ec1 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -6435,7 +6435,7 @@ void Player::SendMessageToSet(WorldPacket* data, Player const* skipped_rcvr) Cell::VisitWorldObjects(this, notifier, GetVisibilityRange()); } -void Player::SendDirectMessage(WorldPacket* data) const +void Player::SendDirectMessage(WorldPacket const* data) const { m_session->SendPacket(data); } diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index abbd663a736..4064fe1010c 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -2049,7 +2049,7 @@ class TC_GAME_API Player : public Unit, public GridObject void SendInitWorldStates(uint32 zone, uint32 area); void SendUpdateWorldState(uint32 Field, uint32 Value) const; - void SendDirectMessage(WorldPacket* data) const; + void SendDirectMessage(WorldPacket const* data) const; void SendBGWeekendWorldStates() const; void SendBattlefieldWorldStates() const; diff --git a/src/server/game/Guilds/Guild.cpp b/src/server/game/Guilds/Guild.cpp index c60c2df9657..f1c7972879d 100644 --- a/src/server/game/Guilds/Guild.cpp +++ b/src/server/game/Guilds/Guild.cpp @@ -2501,11 +2501,10 @@ void Guild::SendLoginInfo(WorldSession* session) SMSG_GUILD_MEMBER_DAILY_RESET // bank withdrawal reset */ - WorldPacket data(SMSG_GUILD_EVENT, 1 + 1 + m_motd.size() + 1); - data << uint8(GE_MOTD); - data << uint8(1); - data << m_motd; - session->SendPacket(&data); + WorldPackets::Guild::GuildEvent motd; + motd.EventType = GE_MOTD; + motd.Param.push_back(m_motd); + session->SendPacket(motd.Write()); TC_LOG_DEBUG("guild", "SMSG_GUILD_EVENT [%s] MOTD", session->GetPlayerInfo().c_str()); @@ -2513,15 +2512,14 @@ void Guild::SendLoginInfo(WorldSession* session) _BroadcastEvent(GE_SIGNED_ON, player->GetGUID(), player->GetName().c_str()); // Send to self separately, player is not in world yet and is not found by _BroadcastEvent - data.Initialize(SMSG_GUILD_EVENT, 1 + 1 + player->GetName().size() + 8); - data << uint8(GE_SIGNED_ON); - data << uint8(1); - data << player->GetName(); - data << uint64(player->GetGUID()); - session->SendPacket(&data); + WorldPackets::Guild::GuildEvent signedOn; + signedOn.EventType = GE_SIGNED_ON; + signedOn.Param.push_back(player->GetName()); + signedOn.GUID = player->GetGUID(); + session->SendPacket(signedOn.Write()); - data.Initialize(SMSG_GUILD_MEMBER_DAILY_RESET, 0); // tells the client to request bank withdrawal limit - session->SendPacket(&data); + WorldPackets::Guild::GuildMemberDailyReset packet; // tells the client to request bank withdrawal limit + session->SendPacket(packet.Write()); if (!sWorld->getBoolConfig(CONFIG_GUILD_LEVELING_ENABLED)) return; @@ -2829,7 +2827,7 @@ void Guild::BroadcastAddonToGuild(WorldSession* session, bool officerOnly, std:: } } -void Guild::BroadcastPacketToRank(WorldPacket* packet, uint8 rankId) const +void Guild::BroadcastPacketToRank(WorldPacket const* packet, uint8 rankId) const { for (auto itr = m_members.begin(); itr != m_members.end(); ++itr) if (itr->second->IsRank(rankId)) @@ -2837,14 +2835,14 @@ void Guild::BroadcastPacketToRank(WorldPacket* packet, uint8 rankId) const player->SendDirectMessage(packet); } -void Guild::BroadcastPacket(WorldPacket* packet) const +void Guild::BroadcastPacket(WorldPacket const* packet) const { for (auto itr = m_members.begin(); itr != m_members.end(); ++itr) if (Player* player = itr->second->FindPlayer()) player->SendDirectMessage(packet); } -void Guild::BroadcastPacketIfTrackingAchievement(WorldPacket* packet, uint32 criteriaId) const +void Guild::BroadcastPacketIfTrackingAchievement(WorldPacket const* packet, uint32 criteriaId) const { for (Members::const_iterator itr = m_members.begin(); itr != m_members.end(); ++itr) if (itr->second->IsTrackingCriteriaId(criteriaId)) @@ -3656,23 +3654,21 @@ void Guild::_SendBankContentUpdate(uint8 tabId, SlotIds slots) const void Guild::_BroadcastEvent(GuildEvents guildEvent, ObjectGuid guid, char const* param1, char const* param2, char const* param3) const { - uint8 count = !param3 ? (!param2 ? (!param1 ? 0 : 1) : 2) : 3; + WorldPackets::Guild::GuildEvent packet; + packet.EventType = guildEvent; + if (param1) + packet.Param.push_back(param1); - WorldPacket data(SMSG_GUILD_EVENT, 1 + 1 + count + (guid ? 8 : 0)); - data << uint8(guildEvent); - data << uint8(count); + if (param2) + packet.Param.push_back(param2); if (param3) - data << param1 << param2 << param3; - else if (param2) - data << param1 << param2; - else if (param1) - data << param1; + packet.Param.push_back(param3); if (guid) - data << uint64(guid); + packet.GUID = guid; - BroadcastPacket(&data); + BroadcastPacket(packet.Write()); if (sLog->ShouldLog("guild", LOG_LEVEL_DEBUG)) TC_LOG_DEBUG("guild", "SMSG_GUILD_EVENT [Broadcast] Event: %s (%u)", _GetGuildEventString(guildEvent).c_str(), guildEvent); @@ -3969,25 +3965,25 @@ void Guild::GiveXP(uint32 xp, Player* source, bool rewardedByChallenge) SendGuildXP(player->GetSession()); } -void Guild::SendGuildXP(WorldSession* session /* = nullptr */) const +void Guild::SendGuildXP(WorldSession* session /*= nullptr*/) const { Member const* member = GetMember(session->GetPlayer()->GetGUID()); - WorldPacket data(SMSG_GUILD_XP, 40); - data << uint64(member ? member->GetTotalActivity() : 0); - data << uint64(sGuildMgr->GetXPForGuildLevel(GetLevel()) - GetExperience()); // XP missing for next level - data << uint64(GetTodayExperience()); - data << uint64(member ? member->GetWeekActivity() : 0); - data << uint64(GetExperience()); - session->SendPacket(&data); + WorldPackets::Guild::GuildXP packet; + packet.TotalXP = uint64(member ? member->GetTotalActivity() : 0); + packet.GuildRemainingXP = uint64(sGuildMgr->GetXPForGuildLevel(GetLevel()) - GetExperience()); + packet.GuildTodayXP = uint64(GetTodayExperience()); + packet.WeeklyXP = uint64(member ? member->GetWeekActivity() : 0); + packet.GuildCurrentXP = uint64(GetExperience()); + session->SendPacket(packet.Write()); } void Guild::SendGuildReputationWeeklyCap(WorldSession* session, uint32 reputation) const { - uint32 cap = sWorld->getIntConfig(CONFIG_GUILD_WEEKLY_REP_CAP) - reputation; - WorldPacket data(SMSG_GUILD_REPUTATION_WEEKLY_CAP, 4); - data << uint32(cap); - session->SendPacket(&data); + uint32 cap = std::max(0, sWorld->getIntConfig(CONFIG_GUILD_WEEKLY_REP_CAP) - reputation); + WorldPackets::Guild::GuildReputationWeeklyCap packet; + packet.Cap = cap; + session->SendPacket(packet.Write()); TC_LOG_DEBUG("guild", "SMSG_GUILD_REPUTATION_WEEKLY_CAP [%s]: Left: %u", session->GetPlayerInfo().c_str(), cap); } diff --git a/src/server/game/Guilds/Guild.h b/src/server/game/Guilds/Guild.h index 920e9984c78..40fad8c2460 100644 --- a/src/server/game/Guilds/Guild.h +++ b/src/server/game/Guilds/Guild.h @@ -822,9 +822,9 @@ public: // Broadcasts void BroadcastToGuild(WorldSession* session, bool officerOnly, std::string const& msg, uint32 language = LANG_UNIVERSAL) const; void BroadcastAddonToGuild(WorldSession* session, bool officerOnly, std::string const& msg, std::string const& prefix) const; - void BroadcastPacketToRank(WorldPacket* packet, uint8 rankId) const; - void BroadcastPacket(WorldPacket* packet) const; - void BroadcastPacketIfTrackingAchievement(WorldPacket* packet, uint32 criteriaId) const; + void BroadcastPacketToRank(WorldPacket const* packet, uint8 rankId) const; + void BroadcastPacket(WorldPacket const* packet) const; + void BroadcastPacketIfTrackingAchievement(WorldPacket const* packet, uint32 criteriaId) const; void MassInviteToEvent(WorldSession* session, uint32 minLevel, uint32 maxLevel, uint32 minRank); diff --git a/src/server/game/Server/Packets/GuildPackets.cpp b/src/server/game/Server/Packets/GuildPackets.cpp index f35abf5e7db..311e9b80ab2 100644 --- a/src/server/game/Server/Packets/GuildPackets.cpp +++ b/src/server/game/Server/Packets/GuildPackets.cpp @@ -185,3 +185,32 @@ WorldPacket const* WorldPackets::Guild::GuildBankQueryResults::Write() return &_worldPacket; } + +WorldPacket const* WorldPackets::Guild::GuildEvent::Write() +{ + _worldPacket << uint8(EventType); + _worldPacket << uint8(Param.size()); + for (std::string param : Param) + _worldPacket << param; + _worldPacket << GUID; + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Guild::GuildReputationWeeklyCap::Write() +{ + _worldPacket << uint32(Cap); + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Guild::GuildXP::Write() +{ + _worldPacket << uint64(TotalXP); + _worldPacket << uint64(GuildRemainingXP); + _worldPacket << uint64(GuildTodayXP); + _worldPacket << uint64(WeeklyXP); + _worldPacket << uint64(GuildCurrentXP); + + return &_worldPacket; +} diff --git a/src/server/game/Server/Packets/GuildPackets.h b/src/server/game/Server/Packets/GuildPackets.h index 10135c6d084..f3daf32f03b 100644 --- a/src/server/game/Server/Packets/GuildPackets.h +++ b/src/server/game/Server/Packets/GuildPackets.h @@ -219,6 +219,50 @@ namespace WorldPackets uint64 Money = 0; bool FullUpdate = false; }; + + class GuildEvent final : public ServerPacket + { + public: + GuildEvent() : ServerPacket(SMSG_GUILD_EVENT, 3) { } + + WorldPacket const* Write() override; + + uint8 EventType = 0; + std::vector Param; + ObjectGuid GUID; + }; + + class GuildMemberDailyReset final : public ServerPacket + { + public: + GuildMemberDailyReset() : ServerPacket(SMSG_GUILD_MEMBER_DAILY_RESET, 0) { } + + WorldPacket const* Write() override { return &_worldPacket; } + }; + + class GuildReputationWeeklyCap final : public ServerPacket + { + public: + GuildReputationWeeklyCap() : ServerPacket(SMSG_GUILD_REPUTATION_WEEKLY_CAP, 4) { } + + WorldPacket const* Write() override; + + uint32 Cap = 0; + }; + + class GuildXP final : public ServerPacket + { + public: + GuildXP() : ServerPacket(SMSG_GUILD_XP, 40) { } + + WorldPacket const* Write() override; + + int64 WeeklyXP = 0; + int64 TotalXP = 0; + int64 GuildTodayXP = 0; + int64 GuildRemainingXP = 0; + int64 GuildCurrentXP; + }; } }