/// <summary> /// Registers a handler for a message, if another handler is already registered it will log an error. /// </summary> /// <param name="msgType">Type of the <see cref="ITinyNetMessage"/>.</param> /// <param name="handler">The delegate.</param> internal void RegisterHandlerSafe(ushort msgType, TinyNetMessageDelegate handler) { if (handler == null) { if (TinyNetLogLevel.logError) { TinyLogger.LogError("RegisterHandlerSafe id:" + msgType + " handler is null"); } return; } if (TinyNetLogLevel.logDebug) { TinyLogger.Log("RegisterHandlerSafe id:" + msgType + " handler:" + handler.Method.Name); } if (_msgHandlers.ContainsKey(msgType)) { if (TinyNetLogLevel.logError) { TinyLogger.LogError("RegisterHandlerSafe id:" + msgType + " handler:" + handler.Method.Name + " conflict"); } return; } _msgHandlers.Add(msgType, handler); }
/// <summary> /// Registers a handler for a message, it will not check for conflicts, but cannot be used for system messages. /// </summary> /// <param name="msgType">Type of the <see cref="ITinyNetMessage"/>.</param> /// <param name="handler">The delegate.</param> public void RegisterHandler(ushort msgType, TinyNetMessageDelegate handler) { if (handler == null) { if (TinyNetLogLevel.logError) { TinyLogger.LogError("RegisterHandler id:" + msgType + " handler is null"); } return; } if (msgType <= TinyNetMsgType.InternalHighest) { if (TinyNetLogLevel.logError) { TinyLogger.LogError("RegisterHandler: Cannot replace system message handler " + msgType); } return; } if (_msgHandlers.ContainsKey(msgType)) { if (TinyNetLogLevel.logDebug) { TinyLogger.Log("RegisterHandler replacing " + msgType); } _msgHandlers.Remove(msgType); } if (TinyNetLogLevel.logDebug) { TinyLogger.Log("RegisterHandler id:" + msgType + " handler:" + handler.Method.Name); } _msgHandlers.Add(msgType, handler); }
/// <summary> /// Registers a message handler safely. /// </summary> /// <param name="msgType">Type of the message.</param> /// <param name="handler">The handler.</param> public void RegisterHandlerSafe(ushort msgType, TinyNetMessageDelegate handler) { _tinyMessageHandlers.RegisterHandlerSafe(msgType, handler); }