using System; using System.Collections.Generic; using GameNetworkLayer.Shared; namespace CLre.API.Synergy { public static class Message { internal const NetworkDispatcherCode CLre_MESSAGE_NETCODE = (NetworkDispatcherCode) 219; private static readonly Dictionary> handlers = new Dictionary>(); private static readonly ClientMessagingEngine msgEngine = new ClientMessagingEngine(); public static void SendCLreMessage(ref SerializedCLreMessage message) { msgEngine.EnqueueMessage(ref message); } public static void RegisterListener(uint id, Action handler) { if (handlers.TryGetValue(id, out Action existing)) { existing += handler; handlers[id] = existing; } else { handlers[id] = handler; } } internal static void HandleMessageReceive(ref SerializedCLreMessage msg) { ReceiveMessageArgs payload = new ReceiveMessageArgs { Message = msg, }; if (handlers.TryGetValue(msg.Id, out Action h)) { h(payload); } } } public struct ReceiveMessageArgs { public SerializedCLreMessage Message; } }