Example #1
0
        public Priority GetPriority(BncsPacketId packetToSearch)
        {
            if (m_priorityMap.ContainsKey(packetToSearch))
            {
                return(m_priorityMap[packetToSearch]);
            }
            else
            {
                lock (syncObject)
                {
                    // do a double lookup; gain speed on cache hits by sacrificing a double-check
                    // on cache misses.
                    if (!m_priorityMap.ContainsKey(packetToSearch))
                    {
                        Priority result = default(Priority);
                        for (int i = m_providerList.Count - 1; i >= 0; i--)
                        {
                            IPacketPriorityProvider provider = m_providerList[i];
                            if (provider.Defines(packetToSearch))
                            {
                                result = provider.GetPriority(packetToSearch);
                                break;
                            }
                        }

                        m_priorityMap[packetToSearch] = result;
                        return(result);
                    }
                    else
                    {
                        return(m_priorityMap[packetToSearch]);
                    }
                }
            }
        }
Example #2
0
        public virtual IBattleNetEvents RegisterCustomPacketHandler(BncsPacketId packetID, ParseCallback parser, out ParseCallback previousParser)
        {
            if (object.ReferenceEquals(null, parser))
            {
                throw new ArgumentNullException("parser");
            }

            if (packetID == BncsPacketId.Warden)
            {
                throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for the Warden packet.  Use the WardenHandler property instead.");
            }

            if (packetID > (BncsPacketId)255 || packetID < BncsPacketId.Null)
            {
                throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for a packet ID greater than 255 or less than 0.");
            }

            if (m_packetToParserMap.ContainsKey(packetID))
            {
                previousParser = m_packetToParserMap[packetID];
            }
            else
            {
                previousParser = null;
            }
            m_packetToParserMap[packetID] = parser;

            return(m_customEventSink);
        }
        public Priority GetPriority(BncsPacketId packetToSearch)
        {
            if (m_priorityMap.ContainsKey(packetToSearch))
            {
                return m_priorityMap[packetToSearch];
            }
            else
            {
                lock (syncObject)
                {
                    // do a double lookup; gain speed on cache hits by sacrificing a double-check 
                    // on cache misses.
                    if (!m_priorityMap.ContainsKey(packetToSearch))
                    {
                        Priority result = default(Priority);
                        for (int i = m_providerList.Count - 1; i >= 0; i--)
                        {
                            IPacketPriorityProvider provider = m_providerList[i];
                            if (provider.Defines(packetToSearch))
                            {
                                result = provider.GetPriority(packetToSearch);
                                break;
                            }
                        }

                        m_priorityMap[packetToSearch] = result;
                        return result;
                    }
                    else
                    {
                        return m_priorityMap[packetToSearch];
                    }
                }
            }
        }
Example #4
0
        internal ParseCallback RegisterParseCallback(BncsPacketId packetId, ParseCallback callback)
        {
            ParseCallback current;

            _packetToParserMap.TryGetValue(packetId, out current);
            _packetToParserMap[packetId] = callback;
            return(current);
        }
Example #5
0
 /// <summary>
 /// Creates a new BNCS packet with the specified packet ID.
 /// </summary>
 /// <param name="id">The BNCS packet ID.</param>
 public BncsPacket(BncsPacketId id, NetworkBuffer backingStore)
     : base(backingStore)
 {
     _id = (byte)id;
     InsertByte(0xff);
     InsertByte((byte)id);
     InsertInt16(0);
 }
Example #6
0
 /// <summary>
 /// Creates a new BNCS packet with the specified packet ID.
 /// </summary>
 /// <param name="id">The BNCS packet ID.</param>
 public BncsPacket(BncsPacketId id, NetworkBuffer backingStore)
     : base(backingStore)
 {
     _id = (byte)id;
     InsertByte(0xff);
     InsertByte((byte)id);
     InsertInt16(0);
 }
        private Priority DeterminePriority(BncsPacketId bncsPacketId)
        {
            Priority p = Priority.Normal;

            if (m_packetToPriorityMap.ContainsKey(bncsPacketId))
            {
                p = m_packetToPriorityMap[bncsPacketId];
            }

            return(p);
        }
Example #8
0
        /// <summary>
        /// Creates a new data reader with the specified byte data.
        /// </summary>
        /// <param name="data">The data to read.</param>
        /// <exception cref="ArgumentNullException">Thrown if <b>data</b> is 
        /// <b>null</b> (<b>Nothing</b> in Visual Basic).</exception>
        public BncsReader(NetworkBuffer buffer)
            : base(buffer)
        {
            if (buffer == null)
                throw new ArgumentNullException("buffer");

            if (this.ReadByte() != 0xff)
                throw new InvalidDataException("The buffer was invalid.");
            PacketID = (BncsPacketId)this.ReadByte();
            _len = this.ReadUInt16();
            if (_len > 8192)
                throw new InvalidDataException("The buffer was invalid.");
        }
        public virtual void UnregisterCustomPacketHandler(BncsPacketId packetID, ParseCallback previousParser)
        {
            if (packetID == BncsPacketId.Warden)
                throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for the Warden packet.  Use the WardenHandler property instead.");

            if (packetID > (BncsPacketId)255 || packetID < BncsPacketId.Null)
                throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for a packet ID greater than 255 or less than 0.");

            if (object.ReferenceEquals(previousParser, null))
            {
                m_packetToParserMap.Remove(packetID);
            }
            else
            {
                m_packetToParserMap[packetID] = previousParser;
            }
        }
Example #10
0
        /// <summary>
        /// Creates a new data reader with the specified byte data.
        /// </summary>
        /// <param name="data">The data to read.</param>
        /// <exception cref="ArgumentNullException">Thrown if <b>data</b> is
        /// <b>null</b> (<b>Nothing</b> in Visual Basic).</exception>
        public BncsReader(NetworkBuffer buffer)
            : base(buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (this.ReadByte() != 0xff)
            {
                throw new InvalidDataException("The buffer was invalid.");
            }
            PacketID = (BncsPacketId)this.ReadByte();
            _len     = this.ReadUInt16();
            if (_len > 8192)
            {
                throw new InvalidDataException("The buffer was invalid.");
            }
        }
Example #11
0
        public virtual void UnregisterCustomPacketHandler(BncsPacketId packetID, ParseCallback previousParser)
        {
            if (packetID == BncsPacketId.Warden)
            {
                throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for the Warden packet.  Use the WardenHandler property instead.");
            }

            if (packetID > (BncsPacketId)255 || packetID < BncsPacketId.Null)
            {
                throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for a packet ID greater than 255 or less than 0.");
            }

            if (object.ReferenceEquals(previousParser, null))
            {
                m_packetToParserMap.Remove(packetID);
            }
            else
            {
                m_packetToParserMap[packetID] = previousParser;
            }
        }
        public virtual IBattleNetEvents RegisterCustomPacketHandler(BncsPacketId packetID, ParseCallback parser, out ParseCallback previousParser)
        {
            if (object.ReferenceEquals(null, parser))
                throw new ArgumentNullException("parser");

            if (packetID == BncsPacketId.Warden)
                throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for the Warden packet.  Use the WardenHandler property instead.");

            if (packetID > (BncsPacketId)255 || packetID < BncsPacketId.Null)
                throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for a packet ID greater than 255 or less than 0.");

            if (m_packetToParserMap.ContainsKey(packetID))
            {
                previousParser = m_packetToParserMap[packetID];
            }
            else
            {
                previousParser = null;
            }
            m_packetToParserMap[packetID] = parser;

            return m_customEventSink;
        }
 public Priority GetPriority(BncsPacketId packetToSearch)
 {
     return Priority.Normal;
 }
 public bool Defines(BncsPacketId packetToSearch)
 {
     return true;
 }
 internal ParseData(byte packetID, ushort len, byte[] data)
 {
     PacketID = (BncsPacketId)packetID;
     Length = len;
     Data = data;
 }
 public Priority GetPriority(BncsPacketId packetToSearch)
 {
     return(Priority.Normal);
 }
 public bool Defines(BncsPacketId packetToSearch)
 {
     return(true);
 }
Example #18
0
 private BncsPacket CreatePacket(BncsPacketId id)
 {
     return new BncsPacket(id, _connection.NetworkBuffers.Acquire());
 }
Example #19
0
        private Priority DeterminePriority(BncsPacketId bncsPacketId)
        {
            Priority p = Priority.Normal;
            if (m_packetToPriorityMap.ContainsKey(bncsPacketId))
                p = m_packetToPriorityMap[bncsPacketId];

            return p;
        }
 private BncsPacket CreatePacket(BncsPacketId id)
 {
     return(new BncsPacket(id, _connection.NetworkBuffers.Acquire()));
 }