Beispiel #1
0
        /// <summary>
        /// Replaces a handler for a particular message type.
        /// <para>See also <see cref="RegisterHandler{T}(Action{NetworkConnection, T}, bool)">RegisterHandler(T)(Action(NetworkConnection, T), bool)</see></para>
        /// </summary>
        /// <typeparam name="T">Message type</typeparam>
        /// <param name="handler">Function handler which will be invoked when this message type is received.</param>
        /// <param name="requireAuthentication">True if the message requires an authenticated connection</param>
        public static void ReplaceHandler <T>(Action <NetworkConnection, T> handler, bool requireAuthentication = true)
            where T : struct, NetworkMessage
        {
            int msgType = MessagePacker.GetId <T>();

            handlers[msgType] = MessagePacker.MessageHandler(handler, requireAuthentication);
        }
Beispiel #2
0
        /// <summary>
        /// Register a handler for a particular message type.
        /// <para>There are several system message types which you can add handlers for. You can also add your own message types.</para>
        /// </summary>
        /// <typeparam name="T">Message type</typeparam>
        /// <param name="handler">Function handler which will be invoked when this message type is received.</param>
        /// <param name="requireAuthentication">True if the message requires an authenticated connection</param>
        public static void RegisterHandler <T>(Action <NetworkConnection, T> handler, bool requireAuthentication = true) where T : NetworkMessage
        {
            int msgType = MessagePacker.GetId <T>();

            if (handlers.ContainsKey(msgType))
            {
                logger.LogWarning($"NetworkClient.RegisterHandler replacing handler for {typeof(T).FullName}, id={msgType}. If replacement is intentional, use ReplaceHandler instead to avoid this warning.");
            }
            handlers[msgType] = MessagePacker.MessageHandler(handler, requireAuthentication);
        }
Beispiel #3
0
        public static void RegisterHandler <T>(Action <NetworkConnection, T> handler) where T : IMessageBase, new()
        {
            int msgType = MessagePacker.GetId <T>();

            if (handlers.ContainsKey(msgType))
            {
                if (LogFilter.Debug)
                {
                    Debug.Log("NetworkServer.RegisterHandler replacing " + msgType);
                }
            }
            handlers[msgType] = MessagePacker.MessageHandler <T>(handler);
        }
Beispiel #4
0
        /// <summary>
        /// Register a handler for a particular message type.
        /// <para>There are several system message types which you can add handlers for. You can also add your own message types.</para>
        /// </summary>
        /// <typeparam name="T">The message type to unregister.</typeparam>
        /// <param name="handler"></param>
        /// <param name="requireAuthentication">true if the message requires an authenticated connection</param>
        public static void RegisterHandler <T>(Action <NetworkConnection, T> handler, bool requireAuthentication = true) where T : IMessageBase, new()
        {
            int msgType = MessagePacker.GetId <T>();

            if (handlers.ContainsKey(msgType))
            {
                if (LogFilter.Debug)
                {
                    Debug.Log("NetworkClient.RegisterHandler replacing " + handler + " - " + msgType);
                }
            }
            handlers[msgType] = MessagePacker.MessageHandler <T>(handler, requireAuthentication);
        }