public static ChannelState Deserialize(Stream stream, ChannelState instance, long limit)
 {
     if (instance.FieldOperation == null)
     {
         instance.FieldOperation = new List <FieldOperation>();
     }
     instance.Healing = false;
     while (limit < 0L || stream.Position < limit)
     {
         int num = stream.ReadByte();
         if (num == -1)
         {
             if (limit >= 0L)
             {
                 throw new EndOfStreamException();
             }
             return(instance);
         }
         else if (num != 10)
         {
             if (num != 18)
             {
                 if (num != 24)
                 {
                     Key  key   = ProtocolParser.ReadKey((byte)num, stream);
                     uint field = key.Field;
                     if (field == 0u)
                     {
                         throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                     }
                     ProtocolParser.SkipKey(stream, key);
                 }
                 else
                 {
                     instance.Healing = ProtocolParser.ReadBool(stream);
                 }
             }
             else
             {
                 instance.FieldOperation.Add(bnet.protocol.presence.FieldOperation.DeserializeLengthDelimited(stream));
             }
         }
         else if (instance.EntityId == null)
         {
             instance.EntityId = EntityId.DeserializeLengthDelimited(stream);
         }
         else
         {
             EntityId.DeserializeLengthDelimited(stream, instance.EntityId);
         }
     }
     if (stream.Position == limit)
     {
         return(instance);
     }
     throw new ProtocolBufferException("Read past max limit");
 }
Exemple #2
0
        private void HandleChannelSubscriber_NotifyAdd(RPCContext context)
        {
            AddNotification addNotification = AddNotification.ParseFrom(context.Payload);

            ChannelAPI.ChannelReferenceObject channelReferenceObject = this.GetChannelReferenceObject(context.Header.ObjectId);
            if (channelReferenceObject == null)
            {
                base.ApiLog.LogError("HandleChannelSubscriber_NotifyAdd had unexpected traffic for objectId : " + context.Header.ObjectId);
                return;
            }
            base.ApiLog.LogDebug("HandleChannelSubscriber_NotifyAdd: " + addNotification);
            ChannelAPI.ChannelType channelType = channelReferenceObject.m_channelData.m_channelType;
            switch (channelType)
            {
            case ChannelAPI.ChannelType.PRESENCE_CHANNEL:
                if (addNotification.ChannelState.HasPresence)
                {
                    bnet.protocol.presence.ChannelState presence = addNotification.ChannelState.Presence;
                    this.m_battleNet.Presence.HandlePresenceUpdates(presence, channelReferenceObject);
                }
                goto IL_16E;
            }
            ChannelAPI.ChannelData channelData = (ChannelAPI.ChannelData)channelReferenceObject.m_channelData;
            if (channelData != null)
            {
                channelData.m_channelState = addNotification.ChannelState;
                using (List <Member> .Enumerator enumerator = addNotification.MemberList.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Member   current       = enumerator.get_Current();
                        EntityId gameAccountId = current.Identity.GameAccountId;
                        channelData.m_members.Add(gameAccountId, current);
                        if (!this.m_battleNet.GameAccountId.Equals(gameAccountId))
                        {
                            this.m_battleNet.Presence.PresenceSubscribe(current.Identity.GameAccountId);
                        }
                    }
                }
            }
IL_16E:
            if (channelType == ChannelAPI.ChannelType.PARTY_CHANNEL)
            {
                this.m_battleNet.Party.PartyJoined(channelReferenceObject, addNotification);
            }
        }
 public static void Serialize(Stream stream, ChannelState instance)
 {
     if (instance.HasEntityId)
     {
         stream.WriteByte(10);
         ProtocolParser.WriteUInt32(stream, instance.EntityId.GetSerializedSize());
         EntityId.Serialize(stream, instance.EntityId);
     }
     if (instance.FieldOperation.Count > 0)
     {
         foreach (FieldOperation fieldOperation in instance.FieldOperation)
         {
             stream.WriteByte(18);
             ProtocolParser.WriteUInt32(stream, fieldOperation.GetSerializedSize());
             bnet.protocol.presence.FieldOperation.Serialize(stream, fieldOperation);
         }
     }
     if (instance.HasHealing)
     {
         stream.WriteByte(24);
         ProtocolParser.WriteBool(stream, instance.Healing);
     }
 }
Exemple #4
0
 public void SetPresence(bnet.protocol.presence.ChannelState val)
 {
     this.Presence = val;
 }
 public void Serialize(Stream stream)
 {
     ChannelState.Serialize(stream, this);
 }
 public static ChannelState Deserialize(Stream stream, ChannelState instance)
 {
     return(ChannelState.Deserialize(stream, instance, -1L));
 }
Exemple #7
0
        private void HandleChannelSubscriber_NotifyUpdateChannelState(RPCContext context)
        {
            UpdateChannelStateNotification updateChannelStateNotification = UpdateChannelStateNotification.ParseFrom(context.Payload);

            base.ApiLog.LogDebug("HandleChannelSubscriber_NotifyUpdateChannelState: " + updateChannelStateNotification);
            ChannelAPI.ChannelReferenceObject channelReferenceObject = this.GetChannelReferenceObject(context.Header.ObjectId);
            if (channelReferenceObject == null)
            {
                base.ApiLog.LogError("HandleChannelSubscriber_NotifyUpdateChannelState had unexpected traffic for objectId : " + context.Header.ObjectId);
                return;
            }
            ChannelAPI.ChannelType channelType = channelReferenceObject.m_channelData.m_channelType;
            switch (channelType)
            {
            case ChannelAPI.ChannelType.PRESENCE_CHANNEL:
                if (updateChannelStateNotification.StateChange.HasPresence)
                {
                    bnet.protocol.presence.ChannelState presence = updateChannelStateNotification.StateChange.Presence;
                    this.m_battleNet.Presence.HandlePresenceUpdates(presence, channelReferenceObject);
                }
                return;

            case ChannelAPI.ChannelType.CHAT_CHANNEL:
            case ChannelAPI.ChannelType.GAME_CHANNEL:
                break;

            case ChannelAPI.ChannelType.PARTY_CHANNEL:
                this.m_battleNet.Party.PreprocessPartyChannelUpdated(channelReferenceObject, updateChannelStateNotification);
                break;

            default:
                return;
            }
            ChannelAPI.ChannelData channelData = (ChannelAPI.ChannelData)channelReferenceObject.m_channelData;
            if (channelData != null)
            {
                bool flag  = channelType == ChannelAPI.ChannelType.PARTY_CHANNEL;
                bool flag2 = false;
                Map <string, Variant> map = null;
                bnet.protocol.channel.ChannelState channelState = channelData.m_channelState;
                bnet.protocol.channel.ChannelState stateChange  = updateChannelStateNotification.StateChange;
                if (stateChange.HasMaxMembers)
                {
                    channelState.MaxMembers = stateChange.MaxMembers;
                }
                if (stateChange.HasMinMembers)
                {
                    channelState.MinMembers = stateChange.MinMembers;
                }
                if (stateChange.HasMaxInvitations)
                {
                    channelState.MaxInvitations = stateChange.MaxInvitations;
                }
                if (stateChange.HasPrivacyLevel && channelState.PrivacyLevel != stateChange.PrivacyLevel)
                {
                    channelState.PrivacyLevel = stateChange.PrivacyLevel;
                    flag2 = true;
                }
                if (stateChange.HasName)
                {
                    channelState.Name = stateChange.Name;
                }
                if (stateChange.HasDelegateName)
                {
                    channelState.DelegateName = stateChange.DelegateName;
                }
                if (stateChange.HasChannelType)
                {
                    if (!flag)
                    {
                        channelState.ChannelType = stateChange.ChannelType;
                    }
                    if (flag && stateChange.ChannelType != PartyAPI.PARTY_TYPE_DEFAULT)
                    {
                        channelState.ChannelType = stateChange.ChannelType;
                        int num = -1;
                        for (int i = 0; i < channelState.AttributeList.get_Count(); i++)
                        {
                            if (channelState.AttributeList.get_Item(i).Name == "WTCG.Party.Type")
                            {
                                num = i;
                                break;
                            }
                        }
                        Attribute attribute = ProtocolHelper.CreateAttribute("WTCG.Party.Type", channelState.ChannelType);
                        if (num >= 0)
                        {
                            channelState.AttributeList.set_Item(num, attribute);
                        }
                        else
                        {
                            channelState.AttributeList.Add(attribute);
                        }
                    }
                }
                if (stateChange.HasProgram)
                {
                    channelState.Program = stateChange.Program;
                }
                if (stateChange.HasAllowOfflineMembers)
                {
                    channelState.AllowOfflineMembers = stateChange.AllowOfflineMembers;
                }
                if (stateChange.HasSubscribeToPresence)
                {
                    channelState.SubscribeToPresence = stateChange.SubscribeToPresence;
                }
                if (stateChange.AttributeCount > 0 && map == null)
                {
                    map = new Map <string, Variant>();
                }
                for (int j = 0; j < stateChange.AttributeCount; j++)
                {
                    Attribute attribute2 = stateChange.AttributeList.get_Item(j);
                    int       num2       = -1;
                    for (int k = 0; k < channelState.AttributeList.get_Count(); k++)
                    {
                        Attribute attribute3 = channelState.AttributeList.get_Item(k);
                        if (attribute3.Name == attribute2.Name)
                        {
                            num2 = k;
                            break;
                        }
                    }
                    if (attribute2.Value.IsNone())
                    {
                        if (num2 >= 0)
                        {
                            channelState.AttributeList.RemoveAt(num2);
                        }
                    }
                    else if (num2 >= 0)
                    {
                        channelState.Attribute.set_Item(num2, attribute2);
                    }
                    else
                    {
                        channelState.AddAttribute(attribute2);
                    }
                    map.Add(attribute2.Name, attribute2.Value);
                }
                if (stateChange.HasReason)
                {
                    IList <Invitation> invitationList  = stateChange.InvitationList;
                    IList <Invitation> invitationList2 = channelState.InvitationList;
                    for (int l = 0; l < invitationList.get_Count(); l++)
                    {
                        Invitation invitation = invitationList.get_Item(l);
                        for (int m = 0; m < invitationList2.get_Count(); m++)
                        {
                            Invitation invitation2 = invitationList2.get_Item(m);
                            if (invitation2.Id == invitation.Id)
                            {
                                channelState.InvitationList.RemoveAt(m);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    channelState.Invitation.AddRange(stateChange.InvitationList);
                }
                channelData.m_channelState = channelState;
                if (flag)
                {
                    if (flag2)
                    {
                        this.m_battleNet.Party.PartyPrivacyChanged(channelData.m_channelId, channelState.PrivacyLevel);
                    }
                    if (stateChange.InvitationList.get_Count() > 0)
                    {
                        uint?removeReason = default(uint?);
                        if (stateChange.HasReason)
                        {
                            removeReason = new uint?(stateChange.Reason);
                        }
                        using (List <Invitation> .Enumerator enumerator = stateChange.InvitationList.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                Invitation current = enumerator.get_Current();
                                this.m_battleNet.Party.PartyInvitationDelta(channelData.m_channelId, current, removeReason);
                            }
                        }
                    }
                    if (map != null)
                    {
                        foreach (KeyValuePair <string, Variant> current2 in map)
                        {
                            this.m_battleNet.Party.PartyAttributeChanged(channelData.m_channelId, current2.get_Key(), current2.get_Value());
                        }
                    }
                }
            }
        }