A partial component implementing IChatEvent to route incoming chat messages to the current session runtime chat observer, or to a fallback Platform.UnavailableChat when no runtime chat exists and running on a dedicated server or in-editor testing is allowed.
using Sandbox;
namespace SboxSuperuser.Components;
public sealed partial class SuperuserBootstrap : IChatEvent
{
void IChatEvent.OnChatMessage( ChatMessageEvent message )
{
var chat = _session?.GetRuntime()?.Chat;
if ( chat is not null ) chat.Observe( message );
else if ( Application.IsDedicatedServer || Game.IsEditor && AllowEditorTesting )
Engine.ChatIntegration.Platform.UnavailableChat.Observe( message );
}
}