Files
sbox-public/engine/Sandbox.Engine/Scene/Events/IChatEvent.cs
Tony Ferguson 06f7a33e73 Platform chat system (#4857)
* Added a platform level chatbox that games can use
* Published games do not have this
* Newly published projects have it enabled by default, if the game is networked
* Check out the Platform page in Project Settings to turn it off
* Party chat uses this, you can also switch between party / game chat if eligible using TAB

You can use `Sandbox.Platform.Chat.AddText( ... )` to add system text for notifications or other things. This has blocking behaviour built-in, and you can disable the chat in your settings menu.

You can listen to chat messages using `IChatEvent.OnChatMessage`, so if you want to filter for stuff like team chat, add commands to your game, you can do that. We have potential plans for first-party commands / chat channels in the future.
2026-05-20 10:53:10 +00:00

41 lines
1.2 KiB
C#

namespace Sandbox;
/// <summary>
/// A chat message event. Handlers can set <see cref="Suppress"/> to true
/// to prevent the message from being delivered, or set <see cref="RecipientFilter"/>
/// to control per-connection visibility.
/// </summary>
public class ChatMessageEvent
{
/// <summary>
/// The chat message text.
/// </summary>
public string Message { get; set; }
/// <summary>
/// The connection that sent this message. Null for system messages.
/// </summary>
public Connection Sender { get; init; }
/// <summary>
/// Set to true to prevent this message from being delivered.
/// </summary>
public bool Suppress { get; set; } = false;
/// <summary>
/// Optional per-connection visibility predicate. Return false to
/// prevent a specific connection from receiving the message.
/// </summary>
public Func<Connection, bool> RecipientFilter { get; set; }
}
public interface IChatEvent : ISceneEvent<IChatEvent>
{
/// <summary>
/// Called when a chat message is received. Set <paramref name="e"/>.Suppress to true
/// to prevent the message from being shown or relayed, or set <paramref name="e"/>.RecipientFilter
/// to control per-connection visibility.
/// </summary>
void OnChatMessage( ChatMessageEvent e ) { }
}