예제 #1
0
        public void OnNotification(string notificationType, Notification notification)
        {
            if (notification.AttributeCount <= 0)
            {
                return;
            }
            BnetNotification bnetNotification = new BnetNotification(notificationType);
            SortedDictionary <string, int> sortedDictionary = new SortedDictionary <string, int>();
            int num = 0;

            bnetNotification.MessageType = 0;
            bnetNotification.MessageSize = 0;
            for (int i = 0; i < notification.AttributeCount; i++)
            {
                Attribute attribute = notification.Attribute.get_Item(i);
                if (attribute.Name == "message_type")
                {
                    bnetNotification.MessageType = (int)attribute.Value.IntValue;
                }
                else if (attribute.Name == "message_size")
                {
                    bnetNotification.MessageSize = (int)attribute.Value.IntValue;
                }
                else if (attribute.Name.StartsWith("fragment_"))
                {
                    num += attribute.Value.BlobValue.Length;
                    sortedDictionary.Add(attribute.Name, i);
                }
            }
            if (bnetNotification.MessageType == 0)
            {
                BattleNet.Log.LogError(string.Format("Missing notification type {0} of size {1}", bnetNotification.MessageType, bnetNotification.MessageSize));
                return;
            }
            if (0 < num)
            {
                bnetNotification.BlobMessage = new byte[num];
                SortedDictionary <string, int> .Enumerator enumerator = sortedDictionary.GetEnumerator();
                int num2 = 0;
                while (enumerator.MoveNext())
                {
                    List <Attribute>           arg_158_0 = notification.Attribute;
                    KeyValuePair <string, int> current   = enumerator.get_Current();
                    byte[] blobValue = arg_158_0.get_Item(current.get_Value()).Value.BlobValue;
                    Array.Copy(blobValue, 0, bnetNotification.BlobMessage, num2, blobValue.Length);
                    num2 += blobValue.Length;
                }
            }
            if (bnetNotification.MessageSize != num)
            {
                BattleNet.Log.LogError(string.Format("Message size mismatch for notification type {0} - {1} != {2}", bnetNotification.MessageType, bnetNotification.MessageSize, num));
                return;
            }
            this.m_notifications.Add(bnetNotification);
        }
        public void OnNotification(string notificationType, Notification notification)
        {
            if (notification.AttributeCount <= 0)
            {
                return;
            }
            BnetNotification bnetNotification   = new BnetNotification(notificationType);
            SortedDictionary <string, int> strs = new SortedDictionary <string, int>();
            int length = 0;

            bnetNotification.MessageType = 0;
            bnetNotification.MessageSize = 0;
            for (int i = 0; i < notification.AttributeCount; i++)
            {
                bnet.protocol.attribute.Attribute item = notification.Attribute[i];
                if (item.Name == "message_type")
                {
                    bnetNotification.MessageType = (int)item.Value.IntValue;
                }
                else if (item.Name == "message_size")
                {
                    bnetNotification.MessageSize = (int)item.Value.IntValue;
                }
                else if (item.Name.StartsWith("fragment_"))
                {
                    length += (int)item.Value.BlobValue.Length;
                    strs.Add(item.Name, i);
                }
            }
            if (bnetNotification.MessageType == 0)
            {
                BattleNet.Log.LogError(string.Format("Missing notification type {0} of size {1}", bnetNotification.MessageType, bnetNotification.MessageSize));
                return;
            }
            if (0 < length)
            {
                bnetNotification.BlobMessage = new byte[length];
                SortedDictionary <string, int> .Enumerator enumerator = strs.GetEnumerator();
                int num = 0;
                while (enumerator.MoveNext())
                {
                    byte[] blobValue = notification.Attribute[enumerator.Current.Value].Value.BlobValue;
                    Array.Copy(blobValue, 0, bnetNotification.BlobMessage, num, (int)blobValue.Length);
                    num += (int)blobValue.Length;
                }
            }
            if (bnetNotification.MessageSize == length)
            {
                this.m_notifications.Add(bnetNotification);
                return;
            }
            BattleNet.Log.LogError(string.Format("Message size mismatch for notification type {0} - {1} != {2}", bnetNotification.MessageType, bnetNotification.MessageSize, length));
        }