Code/SboxSuperuser/Components/SuperuserBootstrap.Voice.cs

Partial of the SuperuserBootstrap component. Implements IHostVoiceEvent so the host can suppress relayed voice packets from senders that the session runtime does not allow to talk.

Really Bad Code
using Sandbox;

namespace SboxSuperuser.Components;

public sealed partial class SuperuserBootstrap : IHostVoiceEvent
{
	// Runs on the host for every relayed voice packet, so it stays allocation-free.
	void IHostVoiceEvent.OnHostVoice( HostVoiceEvent message )
	{
		if ( message.Suppress || _session?.GetRuntime() is not { } runtime ) return;
		if ( !runtime.AllowsVoice( message.Sender ) ) message.Suppress = true;
	}
}