Class ChatSystemRuntimeData
- Namespace
- FishMMO.Server.Implementation.World.SceneServer
- Assembly
- FishMMO.Server.dll
Runtime data container for chat message synchronization state. Manages chat database polling state separately from ChatSystem logic.
public class ChatSystemRuntimeData : RuntimeDataContainer, IRuntimeDataContainer<INetworkManagerWrapper, ServerManager, NetworkConnection, IRuntimeDataContainer>, IServerComponent<INetworkManagerWrapper, ServerManager, NetworkConnection, IRuntimeDataContainer>, IChatSystemRuntimeData, IRuntimeDataContainer, IServerComponent
- Inheritance
-
ChatSystemRuntimeData
- Implements
-
IRuntimeDataContainer<INetworkManagerWrapper, ServerManager, NetworkConnection, IRuntimeDataContainer>
- Inherited Members
Properties
ChannelCommandMap
Maps each ChatChannel to its corresponding handler delegate. Populated during initialization; used for OCP-compliant channel dispatch.
public 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.
public List<IPlayerCharacter> CharacterBroadcastBuffer { get; }
Property Value
ConnectionBroadcastBuffer
Reusable scratch list for connection broadcast iteration, avoiding per-message allocation. Only used from the main thread.
public 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.
public 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)).
public 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.
public bool IsShuttingDown { get; set; }
Property Value
LastFetchPosition
Position (ID) of the last fetched chat message in the database.
public long LastFetchPosition { get; set; }
Property Value
LastFetchTime
Timestamp of the last successful database fetch for chat messages.
public 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.
public Dictionary<long, List<ChatBroadcast>> OutboundWorldBroadcastBuffer { get; }
Property Value
OutboundWorldFlushKeyBuffer
Reusable scratch list for outbound world broadcast flush, avoiding per-flush allocation. Main-thread only.
public 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.
public 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).
public 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
Clear()
Clears the chat message queue state.
public override void Clear()
DecrementIncomingQueueSize()
Atomically decrements the incoming queue size counter and returns the new value. Called on the main thread after each successful TryDequeue.
public int DecrementIncomingQueueSize()
Returns
EndMessagePump()
Atomically transitions the message pump from in-flight back to idle.
public 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)).
public int IncrementIncomingQueueSize()
Returns
InitializeOnce()
Initializes the chat message queue data container.
public override ServerComponentInitializationStatus InitializeOnce()
Returns
OnDeinitialize()
Deinitializes the chat message queue data container.
protected override void OnDeinitialize()
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.
public bool TryBeginMessagePump()