ChatChannel

Named channel that holds a buffer of ChatMessage entries and notifies listeners when new messages arrive. Channels are managed by the Chat singleton and identified by name.

Definition

Namespace: Paragon.Townskeep.ChatSystem Assembly: Townskeep.dll

public class ChatChannel

Remarks

ChatChannel wraps a ChatBuffer — a fixed-capacity (256) ring buffer that stores messages in insertion order and iterates newest-first. When the buffer is full, the oldest message is overwritten.

Channels are created and accessed via the Chat singleton (Chat.AddChannel(), Chat.GetChannel()). Two default channels are created on initialization: "General" and "System".

The MessageSent event fires after each message is pushed to the buffer, allowing UI or logging systems to react immediately.

Quick Lookup

Goal
How

Send a message

channel.SendMessage(chatMessage)

Get a message by index

channel.GetMessage(index)

Get all messages (newest first)

channel.GetAllMessages()

Listen for new messages

channel.MessageSent += OnMessage

Check message count

channel.MessageCount

Get channel via singleton

Chat.GetChannel("General")

Properties

ID

Unique identifier for the channel.

Name

The display name of the channel.

MessageCount

The number of messages currently stored in the buffer (max 256).

Events

MessageSent

Fired after a message is pushed to the buffer.

Parameter
Type
Description

message

ChatMessage

The message that was just sent

Methods

Constructor

Creates a new channel with the given name and an empty buffer.

Parameter
Type
Description

name

string

Display name for the channel

SendMessage

Pushes a message to the buffer and fires the MessageSent event.

Parameter
Type
Description

message

ChatMessage

The message to send

GetMessage

Retrieves a message by index. Supports System.Index (e.g., ^1 for the last message).

Parameter
Type
Description

index

Index

Position in the buffer

Returns: The ChatMessage at the given index.

GetAllMessages

Returns all messages in the buffer, iterated newest-first.

Returns: Enumerable of all stored ChatMessage entries (newest first).

Common Pitfalls

circle-exclamation
circle-exclamation

Examples

Listening for Messages

Sending a Message Directly to a Channel

See Also

Last updated