コード例 #1
0
ファイル: FactoryMap.cs プロジェクト: Amitkapadi/WISP
        /// <summary>
        /// Retrieves the creation delegate for a particular event type and subtype ID
        /// </summary>
        public PacketCreationDelegate GetHandlerDelegate(int typeID, int subTypeID)
        {
            PacketCreationDelegate handler = null;
            Dictionary <int, PacketCreationDelegate> map; // the map we look in for the handler
            int type = typeID;

            if (subTypeID == 0 || typeID == (int)PacketType.PacketGenericMessage) // then this handler is found in the main map
            {
                map = m_HandlerMap;
            }
            else if (m_HandlerSubtypeMaps.TryGetValue(typeID, out map)) //this handler sb found in the sub types map
            {
                type = subTypeID;
            }
            else
            {
                return(null);
            }

            if (map.TryGetValue(type, out handler))
            {
                return(handler);
            }

            return(null);
        }
コード例 #2
0
ファイル: FactoryMap.cs プロジェクト: Amitkapadi/WISP
        /// <summary>
        ///  Registers an action handler, based on a event type ID and subtype ID
        /// </summary>
        public bool RegisterHandler(int typeID, int subType, PacketCreationDelegate handlerMethod)
        {
            Dictionary <int, PacketCreationDelegate> map; // the map we store the handler in
            PacketCreationDelegate handler = GetHandlerDelegate(typeID, subType);

            if (handler == null)
            {
                handler = handlerMethod;
                if (subType == 0)
                {
                    lock (PrimaryHandlerMap)
                    {
                        PrimaryHandlerMap.Add(typeID, handlerMethod);
                    }
                }
                else
                {
                    lock (SubtypeHandlerMap)
                    {
                        if (!SubtypeHandlerMap.TryGetValue(typeID, out map))
                        {
                            map = new Dictionary <int, PacketCreationDelegate>();
                            // map doesnt exist yet. add it.
                            SubtypeHandlerMap.Add(typeID, map);
                        }
                        map.Add(subType, handler);
                    }
                }
                return(true);
            }

            return(false);
        }
コード例 #3
0
ファイル: FactoryMap.cs プロジェクト: Amitkapadi/WISP
        /// <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);
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: FactoryMap.cs プロジェクト: kamilion/WISP
        /// <summary>
        ///  Registers an action handler, based on a event type ID and subtype ID
        /// </summary>
        public bool RegisterHandler(int typeID, int subType, PacketCreationDelegate handlerMethod)
        {
            Dictionary<int, PacketCreationDelegate> map; // the map we store the handler in
            PacketCreationDelegate handler = GetHandlerDelegate(typeID, subType);

            if (handler == null)
            {
                handler = handlerMethod;
                if (subType == 0)
                {
                    lock (PrimaryHandlerMap)
                    {
                        PrimaryHandlerMap.Add(typeID, handlerMethod);
                    }
                }
                else
                {
                    lock (SubtypeHandlerMap)
                    {
                        if (!SubtypeHandlerMap.TryGetValue(typeID, out map))
                        {
                            map = new Dictionary<int, PacketCreationDelegate>();
                            // map doesnt exist yet. add it.
                            SubtypeHandlerMap.Add(typeID, map);
                        }
                        map.Add(subType, handler);
                    }
                }
                return true;
            }

            return false;
        }
コード例 #5
0
ファイル: FactoryMap.cs プロジェクト: kamilion/WISP
 /// <summary>
 ///  Registers an action handler, based on a type ID
 /// </summary>
 public bool RegisterHandler(int eventTypeID, PacketCreationDelegate handlerMethod)
 {
     return RegisterHandler(eventTypeID, 0, handlerMethod);
 }
コード例 #6
0
ファイル: FactoryMap.cs プロジェクト: kamilion/WISP
        /// <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);
                        }
                    }
                }
            }
        }
コード例 #7
0
ファイル: FactoryMap.cs プロジェクト: kamilion/WISP
 /// <summary>
 /// Removes a previously registered delegate from the handler map
 /// </summary>
 public void UnregisterHandler(int typeID, PacketCreationDelegate handlerMethod)
 {
     UnregisterHandler(typeID, 0, handlerMethod);
 }
コード例 #8
0
ファイル: FactoryMap.cs プロジェクト: Amitkapadi/WISP
 /// <summary>
 ///  Registers an action handler, based on a type ID
 /// </summary>
 public bool RegisterHandler(int eventTypeID, PacketCreationDelegate handlerMethod)
 {
     return(RegisterHandler(eventTypeID, 0, handlerMethod));
 }
コード例 #9
0
ファイル: FactoryMap.cs プロジェクト: Amitkapadi/WISP
 /// <summary>
 /// Removes a previously registered delegate from the handler map
 /// </summary>
 public void UnregisterHandler(int typeID, PacketCreationDelegate handlerMethod)
 {
     UnregisterHandler(typeID, 0, handlerMethod);
 }
コード例 #10
0
ファイル: NetworkConnection.cs プロジェクト: kamilion/WISP
 /// <summary>
 /// Packets contain a PType (packet type) ID in the header.  Based on this ID, incoming (and sometimes outgoing) the appropriate packet objects
 /// are instantiated.  New packet type IDs must be registered with this method before the system knows about them.  A quick way to do this is via
 /// this method as such:
 /// <para>Example Usage: RegisterPacketCreationDelegate((int)PacketType.ServerGreeting, delegate { return new PacketServerGreeting(); });</para>
 /// </summary>
 /// <returns>false, if @packetType ID is already registered for another delegate</returns>
 public static bool RegisterPacketCreationDelegate(int packetType, int packetSubType, PacketCreationDelegate packetContructionMethod)
 {
     return PacketCreationMap.RegisterHandler(packetType, packetSubType, packetContructionMethod);
 }
コード例 #11
0
ファイル: NetworkConnection.cs プロジェクト: kamilion/WISP
 /// <summary>
 /// Packets contain a PType (packet type) ID in the header.  Based on this ID, incoming (and sometimes outgoing) the appropriate packet objects
 /// are instantiated.  New packet type IDs must be registered with this method before the system knows about them.  A quick way to do this is via
 /// this method as such:
 /// <para>Example Usage: RegisterPacketCreationDelegate((int)PacketType.ServerGreeting, delegate { return new PacketServerGreeting(); });</para>
 /// </summary>
 /// <returns>false, if @packetType ID is already registered for another delegate</returns>
 public static bool RegisterPacketCreationDelegate(int packetType, PacketCreationDelegate packetContructionMethod)
 {
     return RegisterPacketCreationDelegate(packetType, 0, packetContructionMethod);
 }