Skip to content

Commit

Permalink
Core/Chat: Send broadcast text id in sound packets to allow playing e…
Browse files Browse the repository at this point in the history
…ncrypted sound files
  • Loading branch information
Shauren committed Dec 27, 2020
1 parent 88301ec commit 2e4609f
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
{
if (IsUnit(target))
{
target->PlayDirectSound(e.action.sound.sound, e.action.sound.onlySelf ? target->ToPlayer() : nullptr);
target->PlayDirectSound(e.action.sound.sound, e.action.sound.onlySelf ? target->ToPlayer() : nullptr, e.action.sound.keyBroadcastTextId);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SOUND: target: %s (%s), sound: %u, onlyself: %u",
target->GetName().c_str(), target->GetGUID().ToString().c_str(), e.action.sound.sound, e.action.sound.onlySelf);
}
Expand Down
2 changes: 2 additions & 0 deletions src/server/game/AI/SmartScripts/SmartScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ struct SmartAction
{
uint32 sound;
uint32 onlySelf;
uint32 distance; // NYI: awaiting cherry-pick
uint32 keyBroadcastTextId;
} sound;

struct
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Battlefield/Battlefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void Battlefield::EndBattle(bool endByTimer)

void Battlefield::DoPlaySoundToAll(uint32 soundID)
{
BroadcastPacketToWar(WorldPackets::Misc::PlaySound(ObjectGuid::Empty, soundID).Write());
BroadcastPacketToWar(WorldPackets::Misc::PlaySound(ObjectGuid::Empty, soundID, 0).Write());
}

bool Battlefield::HasPlayer(Player* player) const
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Battlegrounds/Battleground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,12 @@ void Battleground::SendBroadcastText(uint32 id, ChatMsg msgType, WorldObject con

void Battleground::PlaySoundToAll(uint32 soundID)
{
SendPacketToAll(WorldPackets::Misc::PlaySound(ObjectGuid::Empty, soundID).Write());
SendPacketToAll(WorldPackets::Misc::PlaySound(ObjectGuid::Empty, soundID, 0).Write());
}

void Battleground::PlaySoundToTeam(uint32 soundID, uint32 teamID)
{
SendPacketToTeam(teamID, WorldPackets::Misc::PlaySound(ObjectGuid::Empty, soundID).Write());
SendPacketToTeam(teamID, WorldPackets::Misc::PlaySound(ObjectGuid::Empty, soundID, 0).Write());
}

void Battleground::CastSpellOnTeam(uint32 SpellID, uint32 TeamID)
Expand Down
6 changes: 3 additions & 3 deletions src/server/game/Entities/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,12 +2212,12 @@ void WorldObject::PlayDistanceSound(uint32 soundId, Player* target /*= nullptr*/
SendMessageToSet(WorldPackets::Misc::PlaySpeakerbotSound(GetGUID(), soundId).Write(), true);
}

void WorldObject::PlayDirectSound(uint32 soundId, Player* target /*= nullptr*/)
void WorldObject::PlayDirectSound(uint32 soundId, Player* target /*= nullptr*/, uint32 broadcastTextId /*= 0*/)
{
if (target)
target->SendDirectMessage(WorldPackets::Misc::PlaySound(GetGUID(), soundId).Write());
target->SendDirectMessage(WorldPackets::Misc::PlaySound(GetGUID(), soundId, broadcastTextId).Write());
else
SendMessageToSet(WorldPackets::Misc::PlaySound(GetGUID(), soundId).Write(), true);
SendMessageToSet(WorldPackets::Misc::PlaySound(GetGUID(), soundId, broadcastTextId).Write(), true);
}

void WorldObject::PlayDirectMusic(uint32 musicId, Player* target /*= nullptr*/)
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Object/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
virtual uint8 GetLevelForTarget(WorldObject const* /*target*/) const { return 1; }

void PlayDistanceSound(uint32 soundId, Player* target = nullptr);
void PlayDirectSound(uint32 soundId, Player* target = nullptr);
void PlayDirectSound(uint32 soundId, Player* target = nullptr, uint32 broadcastTextId = 0);
void PlayDirectMusic(uint32 musicId, Player* target = nullptr);

virtual void SaveRespawnTime(uint32 /*forceDelay*/ = 0, bool /*saveToDB*/ = true) { }
Expand Down
3 changes: 2 additions & 1 deletion src/server/game/Server/Packets/MiscPackets.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,8 @@ namespace WorldPackets
{
public:
PlaySound() : ServerPacket(SMSG_PLAY_SOUND, 20) { }
PlaySound(ObjectGuid sourceObjectGuid, int32 soundKitID) : ServerPacket(SMSG_PLAY_SOUND, 20), SourceObjectGuid(sourceObjectGuid), SoundKitID(soundKitID) { }
PlaySound(ObjectGuid sourceObjectGuid, int32 soundKitID, int32 broadcastTextId) : ServerPacket(SMSG_PLAY_SOUND, 20),
SourceObjectGuid(sourceObjectGuid), SoundKitID(soundKitID), BroadcastTextID(broadcastTextId) { }

WorldPacket const* Write() override;

Expand Down
7 changes: 4 additions & 3 deletions src/server/game/Texts/CreatureTextMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject
range = iter->TextRange;

if (finalSound)
SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly);
SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly, iter->BroadcastTextId);

Unit* finalSource = source;
if (srcPlr)
Expand Down Expand Up @@ -302,12 +302,13 @@ float CreatureTextMgr::GetRangeForChatType(ChatMsg msgType)
return dist;
}

void CreatureTextMgr::SendSound(Creature* source, uint32 sound, ChatMsg msgType, WorldObject const* whisperTarget /*= nullptr*/, CreatureTextRange range /*= TEXT_RANGE_NORMAL*/, Team team /*= TEAM_OTHER*/, bool gmOnly /*= false*/)
void CreatureTextMgr::SendSound(Creature* source, uint32 sound, ChatMsg msgType, WorldObject const* whisperTarget /*= nullptr*/, CreatureTextRange range /*= TEXT_RANGE_NORMAL*/,
Team team /*= TEAM_OTHER*/, bool gmOnly /*= false*/, uint32 keyBroadcastTextId /*= 0*/)
{
if (!sound || !source)
return;

SendNonChatPacket(source, WorldPackets::Misc::PlaySound(source->GetGUID(), sound).Write(), msgType, whisperTarget, range, team, gmOnly);
SendNonChatPacket(source, WorldPackets::Misc::PlaySound(source->GetGUID(), sound, keyBroadcastTextId).Write(), msgType, whisperTarget, range, team, gmOnly);
}

void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket const* data, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly)
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Texts/CreatureTextMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TC_GAME_API CreatureTextMgr
void LoadCreatureTextLocales();
CreatureTextMap const& GetTextMap() const { return mTextMap; }

static void SendSound(Creature* source, uint32 sound, ChatMsg msgType, WorldObject const* whisperTarget = nullptr, CreatureTextRange range = TEXT_RANGE_NORMAL, Team team = TEAM_OTHER, bool gmOnly = false);
static void SendSound(Creature* source, uint32 sound, ChatMsg msgType, WorldObject const* whisperTarget = nullptr, CreatureTextRange range = TEXT_RANGE_NORMAL, Team team = TEAM_OTHER, bool gmOnly = false, uint32 keyBroadcastTextId = 0);
static void SendEmote(Unit* source, uint32 emote);

//if sent, returns the 'duration' of the text else 0 if error
Expand Down
11 changes: 9 additions & 2 deletions src/server/scripts/Commands/cs_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2686,7 +2686,9 @@ class misc_commandscript : public CommandScript
if (!*args)
return false;

uint32 soundId = atoul(args);
char const* soundIdToken = strtok((char*)args, " ");

uint32 soundId = atoul(soundIdToken);

if (!sSoundKitStore.LookupEntry(soundId))
{
Expand All @@ -2695,7 +2697,12 @@ class misc_commandscript : public CommandScript
return false;
}

sWorld->SendGlobalMessage(WorldPackets::Misc::PlaySound(handler->GetSession()->GetPlayer()->GetGUID(), soundId).Write());
uint32 broadcastTextId = 0;
char const* broadcastTextIdToken = strtok(nullptr, " ");
if (broadcastTextIdToken)
broadcastTextId = atoul(broadcastTextIdToken);

sWorld->SendGlobalMessage(WorldPackets::Misc::PlaySound(handler->GetSession()->GetPlayer()->GetGUID(), soundId, broadcastTextId).Write());

handler->PSendSysMessage(LANG_COMMAND_PLAYED_TO_ALL, soundId);
return true;
Expand Down

0 comments on commit 2e4609f

Please sign in to comment.