Interface IChatSystemRuntimeData
- Namespace
- FishMMO.Server.Core.World.SceneServer
- Assembly
- FishMMO.Server.dll
Runtime data container for chat message synchronization state. Tracks database polling position for chat message pump.
public interface IChatSystemRuntimeData : IRuntimeDataContainer, IServerComponent
Properties
ChannelCommandMap
Maps each ChatChannel to its corresponding handler delegate. Populated during initialization; used for OCP-compliant channel dispatch.
Dictionary<ChatChannel, ChatCommand> ChannelCommandMap { get; set; }
Property Value
CharacterBroadcastBuffer
Reusable scratch list for character broadcast iteration, avoiding per-message allocation. Only used from the main thread.
List<IPlayerCharacter> CharacterBroadcastBuffer { get; }
Property Value
ConnectionBroadcastBuffer
Reusable scratch list for connection broadcast iteration, avoiding per-message allocation. Only used from the main thread.
List<NetworkConnection> ConnectionBroadcastBuffer { get; }
Property Value
- List<NetworkConnection>
IncomingChatQueue
Lock-free queue for incoming chat broadcasts from the network layer. The networking callback enqueues stamped messages; the main-thread OnUpdate drains up to N per frame for processing. Prevents network spikes from freezing gameplay.
ConcurrentQueue<(NetworkConnection Connection, ChatBroadcast Message)> IncomingChatQueue { get; }
Property Value
- ConcurrentQueue<(NetworkConnection Connection, ChatBroadcast Message)>
IncomingQueueSize
Current approximate size of the incoming queue (via atomic counter, O(1)).
int IncomingQueueSize { get; }
Property Value
IsShuttingDown
Set to true when the server begins its shutdown sequence. Async flush paths check this flag and exit early to prevent duplicate writes against the synchronous shutdown flush.
bool IsShuttingDown { get; set; }
Property Value
LastFetchPosition
Position (ID) of the last fetched chat message in the database.
long LastFetchPosition { get; set; }
Property Value
LastFetchTime
Timestamp of the last successful database fetch for chat messages.
DateTime LastFetchTime { get; set; }
Property Value
OutboundWorldBroadcastBuffer
Accumulates outbound world/trade broadcasts per world ID for batched sending. Flushed on a periodic callback to reduce per-message network overhead. Main-thread only.
Dictionary<long, List<ChatBroadcast>> OutboundWorldBroadcastBuffer { get; }
Property Value
OutboundWorldFlushKeyBuffer
Reusable scratch list for outbound world broadcast flush, avoiding per-flush allocation. Main-thread only.
List<long> OutboundWorldFlushKeyBuffer { get; }
Property Value
PendingPersistQueue
Lock-free queue for chat messages pending batch DB persistence. Channel handlers enqueue persistence entries; a periodic callback flushes them to the database in batches via PersistBatchAsync. Reduces per-message DB writes from O(N) to ~O(N/batchSize) round-trips.
ConcurrentQueue<PendingChatPersist> PendingPersistQueue { get; }
Property Value
PersistBatchBuffer
Reusable scratch list for batch DB persistence, avoiding per-flush allocation. Cleared and reused each flush cycle. Only used from a single flush path (async worker or sync shutdown).
List<(long characterId, string characterName, string accountName, long worldServerId, long sceneServerId, ChatChannel channel, string message, DateTime serverReceivedTime)> PersistBatchBuffer { get; }
Property Value
- List<(long characterId, string characterName, string accountName, long worldServerId, long sceneServerId, ChatChannel channel, string message, DateTime serverReceivedTime)>
Methods
DecrementIncomingQueueSize()
Atomically decrements the incoming queue size counter and returns the new value. Called on the main thread after each successful TryDequeue.
int DecrementIncomingQueueSize()
Returns
EndMessagePump()
Atomically transitions the message pump from in-flight back to idle.
void EndMessagePump()
IncrementIncomingQueueSize()
Atomically increments the incoming queue size counter and returns the new value. O(1) replacement for ConcurrentQueue.Count (which is O(N)).
int IncrementIncomingQueueSize()
Returns
TryBeginMessagePump()
Atomically transitions the message pump from idle to in-flight. Returns true if this call won the race; false if a pump is already in flight.
bool TryBeginMessagePump()