Ejemplo n.º 1
0
        /// <summary>
        /// Removes a previously registered delegate from the handler map
        /// </summary>
        public void UnregisterHandler(int eventTypeID, int eventSubTypeID, Action <INetworkConnection, Packet> handlerMethod)
        {
            Action <INetworkConnection, Packet> handler = GetHandlerDelegate(eventTypeID);

            if (handler == null)
            {
                return;
            }

            handler -= handlerMethod;

            if (eventSubTypeID == 0)
            {
                lock (PrimaryHandlerMap)
                {
                    PrimaryHandlerMap.Remove(eventTypeID);
                    if (handler.GetInvocationList().Length > 0)
                    {
                        PrimaryHandlerMap.Add(eventTypeID, handler);
                    }
                }
            }
            else
            {
                lock (SubtypeHandlerMap)
                {
                    Dictionary <int, Action <INetworkConnection, Packet> > map;
                    if (SubtypeHandlerMap.TryGetValue(eventTypeID, out map))
                    {
                        map.Remove(eventSubTypeID);
                        if (handler.GetInvocationList().Length > 0)
                        {
                            map.Add(eventSubTypeID, handler);
                        }

                        if (map.Count < 1)
                        {
                            SubtypeHandlerMap.Remove(eventTypeID);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes a previously registered delegate from the handler map
        /// </summary>
        public void UnregisterHandler(int typeID, int subTypeID, PacketCreationDelegate handlerMethod)
        {
            PacketCreationDelegate handler = GetHandlerDelegate(typeID);

            if (handler == null)
            {
                return;
            }

            handler -= handlerMethod;

            if (subTypeID == 0)
            {
                lock (PrimaryHandlerMap)
                {
                    PrimaryHandlerMap.Remove(typeID);
                    if (handler.GetInvocationList().Length > 0)
                    {
                        PrimaryHandlerMap.Add(typeID, handler);
                    }
                }
            }
            else
            {
                lock (SubtypeHandlerMap)
                {
                    Dictionary <int, PacketCreationDelegate> map;
                    if (SubtypeHandlerMap.TryGetValue(typeID, out map))
                    {
                        map.Remove(subTypeID);
                        if (handler.GetInvocationList().Length > 0)
                        {
                            map.Add(subTypeID, handler);
                        }

                        if (map.Count < 1)
                        {
                            SubtypeHandlerMap.Remove(typeID);
                        }
                    }
                }
            }
        }