Skip to content

Commit

Permalink
[Core/Packet] Split SMSG_PLAY_SOUND to MiscPackets (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
leelf00 authored Sep 29, 2024
1 parent 0fd9c0c commit bffdcdd
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 168 deletions.
6 changes: 5 additions & 1 deletion src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
{
if (IsUnit(*itr))
{
(*itr)->SendPlaySound(e.action.sound.sound, e.action.sound.onlySelf > 0);
// if (e.action.sound.distance == 1)
// target->PlayDistanceSound(e.action.sound.sound, e.action.sound.onlySelf ? target->ToPlayer() : nullptr);
// else
(*itr)->PlayDirectSound(e.action.sound.sound, e.action.sound.onlySelf ? (*itr)->ToPlayer() : nullptr);

TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SOUND: target: %s (GuidLow: %u), sound: %u, onlyself: %u",
(*itr)->GetName().c_str(), (*itr)->GetGUID().GetCounter(), e.action.sound.sound, e.action.sound.onlySelf);
}
Expand Down
26 changes: 12 additions & 14 deletions src/server/game/Battlefield/Battlefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@

#include "Battlefield.h"
#include "BattlefieldMgr.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "Map.h"
#include "MapManager.h"
#include "Group.h"
#include "WorldPacket.h"
#include "CellImpl.h"
#include "CreatureTextMgr.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "CellImpl.h"
#include "CreatureTextMgr.h"
#include "Group.h"
#include "GroupMgr.h"
#include "Map.h"
#include "MapManager.h"
#include "MiscPackets.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "WorldPacket.h"

Battlefield::Battlefield()
{
Expand Down Expand Up @@ -353,10 +354,7 @@ void Battlefield::EndBattle(bool endByTimer)

void Battlefield::DoPlaySoundToAll(uint32 SoundID)
{
for (int team = 0; team < BG_TEAMS_COUNT; team++)
for (GuidSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(*itr))
player->SendPlaySound(SoundID, true);
BroadcastPacketToWar(WorldPackets::Misc::PlaySound(ObjectGuid::Empty, SoundID).Write());
}

bool Battlefield::HasPlayer(Player* player) const
Expand Down Expand Up @@ -431,12 +429,12 @@ void Battlefield::BroadcastPacketToQueue(WorldPacket& data) const
player->GetSession()->SendPacket(&data);
}

void Battlefield::BroadcastPacketToWar(WorldPacket& data) const
void Battlefield::BroadcastPacketToWar(WorldPacket const* data) const
{
for (uint8 team = 0; team < BG_TEAMS_COUNT; ++team)
for (GuidSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(*itr))
player->GetSession()->SendPacket(&data);
player->SendDirectMessage(data);
}

WorldPacket Battlefield::BuildWarningAnnPacket(std::string const& msg)
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Battlefield/Battlefield.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of the Pandaria 5.4.8 Project. See THANKS file for Copyright information
* This file is part of the Legends of Azeroth Pandaria Project. See THANKS 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
Expand Down Expand Up @@ -408,7 +408,7 @@ class Battlefield : public ZoneScript
// use for send a packet for all player list
void BroadcastPacketToZone(WorldPacket& data) const;
void BroadcastPacketToQueue(WorldPacket& data) const;
void BroadcastPacketToWar(WorldPacket& data) const;
void BroadcastPacketToWar(WorldPacket const* data) const;

// CapturePoint system
void AddCapturePoint(BfCapturePoint* cp) { m_capturePoints[cp->GetCapturePointEntry()] = cp; }
Expand Down
10 changes: 4 additions & 6 deletions src/server/game/Battlegrounds/Battleground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "Guild.h"
#include "GuildMgr.h"
#include "MapManager.h"
#include "MiscPackets.h"
#include "Object.h"
#include "ObjectMgr.h"
#include "Player.h"
Expand Down Expand Up @@ -824,7 +825,7 @@ void Battleground::SetTeamStartLoc(uint32 TeamID, float X, float Y, float Z, flo
m_TeamStartLocO[idx] = O;
}

void Battleground::SendPacketToAll(WorldPacket* packet)
void Battleground::SendPacketToAll(WorldPacket const* packet)
{
for (BattlegroundPlayerMap::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
if (Player* player = _GetPlayer(itr, "SendPacketToAll"))
Expand All @@ -845,17 +846,14 @@ void Battleground::SendPacketToTeam(uint32 TeamID, WorldPacket* packet, Player*

void Battleground::PlaySoundToAll(uint32 SoundID)
{
for (BattlegroundPlayerMap::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
if (Player* player = _GetPlayer(itr, "SendPacketToAll"))
player->SendPlaySound(SoundID, true);
SendPacketToAll(WorldPackets::Misc::PlaySound(ObjectGuid::Empty, SoundID).Write());
}

void Battleground::PlaySoundToTeam(uint32 SoundID, uint32 TeamID)
{
WorldPacket data;
for (BattlegroundPlayerMap::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
if (Player* player = _GetPlayerForTeam(TeamID, itr, "PlaySoundToTeam"))
player->SendPlaySound(SoundID, true);
player->SendDirectMessage(WorldPackets::Misc::PlaySound(ObjectGuid::Empty, SoundID).Write());
}

void Battleground::CastSpellOnTeam(uint32 SpellID, uint32 TeamID)
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Battlegrounds/Battleground.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ class Battleground
// method that should fill worldpacket with actual world states (not yet implemented for all battlegrounds!)
virtual void FillInitialWorldStates(WorldStateBuilder& /*builder*/) { }
void SendPacketToTeam(uint32 TeamID, WorldPacket* packet, Player* sender = NULL, bool self = true);
void SendPacketToAll(WorldPacket* packet);
void SendPacketToAll(WorldPacket const* packet);

template<class Do>
void BroadcastWorker(Do& _do);
Expand Down
57 changes: 6 additions & 51 deletions src/server/game/Entities/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2461,34 +2461,6 @@ bool WorldObject::CanDetectStealthOf(WorldObject const* obj) const
return true;
}

void WorldObject::SendPlaySound(uint32 Sound, bool OnlySelf)
{
ObjectGuid guid = GetGUID();

WorldPacket data(SMSG_PLAY_SOUND, 4 + 9);
data.WriteBit(guid[2]);
data.WriteBit(guid[3]);
data.WriteBit(guid[7]);
data.WriteBit(guid[6]);
data.WriteBit(guid[0]);
data.WriteBit(guid[5]);
data.WriteBit(guid[4]);
data.WriteBit(guid[1]);
data << uint32(Sound);
data.WriteByteSeq(guid[3]);
data.WriteByteSeq(guid[2]);
data.WriteByteSeq(guid[4]);
data.WriteByteSeq(guid[7]);
data.WriteByteSeq(guid[5]);
data.WriteByteSeq(guid[0]);
data.WriteByteSeq(guid[6]);
data.WriteByteSeq(guid[1]);
if (OnlySelf && GetTypeId() == TYPEID_PLAYER)
this->ToPlayer()->GetSession()->SendPacket(&data);
else
SendMessageToSet(&data, true); // ToSelf ignored in this case
}

void Object::ForceValuesUpdateAtIndex(uint32 i)
{
_changesMask.SetBit(i);
Expand Down Expand Up @@ -3752,32 +3724,15 @@ void WorldObject::PlayDistanceSound(uint32 sound_id, Player* target /*= NULL*/)
SendMessageToSet(&data, true);
}

void WorldObject::PlayDirectSound(uint32 sound_id, Player* target /*= NULL*/)
void WorldObject::PlayDirectSound(uint32 sound_id, Player* target /*= nullptr*/)
{
ObjectGuid guid = target ? target->GetGUID() : ObjectGuid::Empty;

WorldPacket data(SMSG_PLAY_SOUND, 4);
data.WriteBit(guid[2]);
data.WriteBit(guid[3]);
data.WriteBit(guid[7]);
data.WriteBit(guid[6]);
data.WriteBit(guid[0]);
data.WriteBit(guid[5]);
data.WriteBit(guid[4]);
data.WriteBit(guid[1]);
data << uint32(sound_id);
data.WriteByteSeq(guid[3]);
data.WriteByteSeq(guid[2]);
data.WriteByteSeq(guid[4]);
data.WriteByteSeq(guid[7]);
data.WriteByteSeq(guid[5]);
data.WriteByteSeq(guid[0]);
data.WriteByteSeq(guid[6]);
data.WriteByteSeq(guid[1]);
WorldPackets::Misc::PlaySound packet;
packet.SourceObjectGUID = GetGUID();
packet.SoundKitID = sound_id;
if (target)
target->SendDirectMessage(&data);
target->SendDirectMessage(packet.Write());
else
SendMessageToSet(&data, true);
SendMessageToSet(packet.Write(), true);
}

void WorldObject::PlayDirectMusic(uint32 musicId, Player* target /*= nullptr*/)
Expand Down
3 changes: 0 additions & 3 deletions src/server/game/Entities/Object/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,6 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
FlaggedValuesArray32<int32, uint32, ServerSideVisibilityType, TOTAL_SERVERSIDE_VISIBILITY_TYPES> m_serverSideVisibility;
FlaggedValuesArray32<int32, uint32, ServerSideVisibilityType, TOTAL_SERVERSIDE_VISIBILITY_TYPES> m_serverSideVisibilityDetect;

// Low Level Packets
void SendPlaySound(uint32 Sound, bool OnlySelf);

virtual void SetMap(Map* map);
virtual void ResetMap();
Map* GetMap() const { ASSERT(m_currMap); return m_currMap; }
Expand Down
23 changes: 23 additions & 0 deletions src/server/game/Server/Packets/MiscPackets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ WorldPacket const* WorldPackets::Misc::PlayMusic::Write()
return &_worldPacket;
}

WorldPacket const* WorldPackets::Misc::PlaySound::Write()
{
_worldPacket.WriteBit(SourceObjectGUID[2]);
_worldPacket.WriteBit(SourceObjectGUID[3]);
_worldPacket.WriteBit(SourceObjectGUID[7]);
_worldPacket.WriteBit(SourceObjectGUID[6]);
_worldPacket.WriteBit(SourceObjectGUID[0]);
_worldPacket.WriteBit(SourceObjectGUID[5]);
_worldPacket.WriteBit(SourceObjectGUID[4]);
_worldPacket.WriteBit(SourceObjectGUID[1]);
_worldPacket << SoundKitID;
_worldPacket.WriteByteSeq(SourceObjectGUID[3]);
_worldPacket.WriteByteSeq(SourceObjectGUID[2]);
_worldPacket.WriteByteSeq(SourceObjectGUID[4]);
_worldPacket.WriteByteSeq(SourceObjectGUID[7]);
_worldPacket.WriteByteSeq(SourceObjectGUID[5]);
_worldPacket.WriteByteSeq(SourceObjectGUID[0]);
_worldPacket.WriteByteSeq(SourceObjectGUID[6]);
_worldPacket.WriteByteSeq(SourceObjectGUID[1]);

return &_worldPacket;
}

WorldPacket const* WorldPackets::Misc::StartMirrorTimer::Write()
{
_worldPacket << MaxValue;
Expand Down
12 changes: 12 additions & 0 deletions src/server/game/Server/Packets/MiscPackets.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ namespace WorldPackets
uint32 SoundKitID = 0;
};

class TC_GAME_API PlaySound final : public ServerPacket
{
public:
PlaySound() : ServerPacket(SMSG_PLAY_SOUND, 4 + 8) { }
PlaySound(ObjectGuid sourceObjectGuid, uint32 soundKitID) : ServerPacket(SMSG_PLAY_SOUND, 4 + 8), SourceObjectGUID(sourceObjectGuid), SoundKitID(soundKitID) { }

WorldPacket const* Write() override;

ObjectGuid SourceObjectGUID;
uint32 SoundKitID = 0;
};

class StartMirrorTimer final : public ServerPacket
{
public:
Expand Down
30 changes: 7 additions & 23 deletions src/server/game/Spells/SpellEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6707,13 +6707,17 @@ void Spell::EffectPlaySound(SpellEffIndex effIndex)
if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
return;

if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
if (!unitTarget)
return;

Player* player = unitTarget->ToPlayer();
if (!player)
return;

switch (m_spellInfo->Id)
{
case 91604: // Restricted Flight Area
unitTarget->ToPlayer()->GetSession()->SendNotification(LANG_ZONE_NOFLYZONE);
player->GetSession()->SendNotification(LANG_ZONE_NOFLYZONE);
break;
default:
break;
Expand All @@ -6727,27 +6731,7 @@ void Spell::EffectPlaySound(SpellEffIndex effIndex)
return;
}

ObjectGuid guid = m_caster->GetGUID();

WorldPacket data(SMSG_PLAY_SOUND, 4 + 9);
data.WriteBit(guid[2]);
data.WriteBit(guid[3]);
data.WriteBit(guid[7]);
data.WriteBit(guid[6]);
data.WriteBit(guid[0]);
data.WriteBit(guid[5]);
data.WriteBit(guid[4]);
data.WriteBit(guid[1]);
data << uint32(soundId);
data.WriteByteSeq(guid[3]);
data.WriteByteSeq(guid[2]);
data.WriteByteSeq(guid[4]);
data.WriteByteSeq(guid[7]);
data.WriteByteSeq(guid[5]);
data.WriteByteSeq(guid[0]);
data.WriteByteSeq(guid[6]);
data.WriteByteSeq(guid[1]);
unitTarget->ToPlayer()->GetSession()->SendPacket(&data);
player->PlayDirectSound(soundId, player);
}

void Spell::EffectRemoveAura(SpellEffIndex effIndex)
Expand Down
40 changes: 10 additions & 30 deletions src/server/game/Texts/CreatureTextMgr.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of the Pandaria 5.4.8 Project. See THANKS file for Copyright information
* This file is part of the Legends of Azeroth Pandaria Project. See THANKS 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
Expand All @@ -15,17 +15,18 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "Common.h"
#include "DatabaseEnv.h"
#include "ObjectMgr.h"
#include "Cell.h"
#include "Chat.h"
#include "CellImpl.h"
#include "Chat.h"
#include "Common.h"
#include "CreatureTextMgr.h"
#include "DatabaseEnv.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "CreatureTextMgr.h"
#include "SharedDefines.h"
#include "Group.h"
#include "MiscPackets.h"
#include "ObjectMgr.h"
#include "SharedDefines.h"

class CreatureTextBuilder
{
Expand Down Expand Up @@ -310,31 +311,10 @@ void CreatureTextMgr::SendSound(Creature* source, uint32 sound, ChatMsg msgType,
if (!sound || !source)
return;

ObjectGuid guid = source->GetGUID();

WorldPacket data(SMSG_PLAY_SOUND, 4 + 9);
data.WriteBit(guid[2]);
data.WriteBit(guid[3]);
data.WriteBit(guid[7]);
data.WriteBit(guid[6]);
data.WriteBit(guid[0]);
data.WriteBit(guid[5]);
data.WriteBit(guid[4]);
data.WriteBit(guid[1]);

data << uint32(sound);
data.WriteByteSeq(guid[3]);
data.WriteByteSeq(guid[2]);
data.WriteByteSeq(guid[4]);
data.WriteByteSeq(guid[7]);
data.WriteByteSeq(guid[5]);
data.WriteByteSeq(guid[0]);
data.WriteByteSeq(guid[6]);
data.WriteByteSeq(guid[1]);
SendNonChatPacket(source, &data, msgType, whisperTarget, range, team, gmOnly);
SendNonChatPacket(source, WorldPackets::Misc::PlaySound(source->GetGUID(), sound).Write(), msgType, whisperTarget, range, team, gmOnly);
}

void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket* data, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly) const
void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket const* data, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly) const
{
float dist = GetRangeForChatType(msgType);

Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Texts/CreatureTextMgr.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of the Pandaria 5.4.8 Project. See THANKS file for Copyright information
* This file is part of the Legends of Azeroth Pandaria Project. See THANKS 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
Expand Down Expand Up @@ -115,7 +115,7 @@ class CreatureTextMgr
template<class Builder>
void SendChatPacket(WorldObject* source, Builder const& builder, ChatMsg msgType, WorldObject const* whisperTarget = nullptr, CreatureTextRange range = TEXT_RANGE_NORMAL, Team team = TEAM_OTHER, bool gmOnly = false) const;
private:
void SendNonChatPacket(WorldObject* source, WorldPacket* data, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly) const;
void SendNonChatPacket(WorldObject* source, WorldPacket const* data, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly) const;
float GetRangeForChatType(ChatMsg msgType) const;

CreatureTextMap mTextMap;
Expand Down
Loading

0 comments on commit bffdcdd

Please sign in to comment.