Skip to content

Commit

Permalink
Stop empty audio system filters from playing sounds for all players (#…
Browse files Browse the repository at this point in the history
…5444)

* Fix audio system empty filter bug

* The nullable attributes are lying
  • Loading branch information
ElectroJr committed Sep 18, 2024
1 parent 19a87fb commit afffb33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ END TEMPLATE-->

### Bugfixes

* Fixed filtered AudioSystem methods playing a sound for all players when given an empty filter.
* Fixed equality checks for `MarkupNode` not properly handling attributes.
* Fixed `MarkupNode` not having a `GetHashCode()` implementation.
* Fixed a PVS error that could occur when trying to delete the first entity that gets created in a round.
Expand Down
22 changes: 8 additions & 14 deletions Robust.Server/Audio/AudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,26 @@ public override void SetMapAudio(Entity<AudioComponent>? audio)

private void AddAudioFilter(EntityUid uid, AudioComponent component, Filter filter)
{
var count = filter.Count;
DebugTools.Assert(component.IncludedEntities == null);
component.IncludedEntities = new();

if (count == 0)
if (filter.Count == 0)
return;

_pvs.AddSessionOverrides(uid, filter);

var ents = new HashSet<EntityUid>(count);

foreach (var session in filter.Recipients)
{
var ent = session.AttachedEntity;

if (ent == null)
continue;

ents.Add(ent.Value);
if (session.AttachedEntity is {} ent)
component.IncludedEntities.Add(ent);
}

DebugTools.Assert(component.IncludedEntities == null);
component.IncludedEntities = ents;
}

/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null)
{
if (string.IsNullOrEmpty(filename))
return null;

var entity = SetupAudio(filename, audioParams);
AddAudioFilter(entity, entity.Comp, playerFilter);
entity.Comp.Global = true;
Expand Down

0 comments on commit afffb33

Please sign in to comment.