/// <summary>
        /// Used to communicate channel properties between the client and the server.
        /// Sent by the server during the login process or when channel properties are updated.
        /// </summary>
        /// <param name="channelState"></param>
        public virtual void ChannelState(ChannelState channelState)
        {
            if (!channelState.ShouldSerializeChannelId())
            {
                throw new InvalidOperationException($"{nameof(ChannelState)} must provide a {channelState.ChannelId}.");
            }

            var channel = ChannelDictionary.AddOrUpdate(channelState.ChannelId, i =>
            {
                //Add new channel to the dictionary
                return(new Channel(this, channelState.ChannelId, channelState.Name, channelState.Parent)
                {
                    Temporary = channelState.Temporary,
                    Description = channelState.Description,
                    Position = channelState.Position
                });
            },
                                                        (i, c) => c);

            //Update channel in the dictionary
            if (channelState.ShouldSerializeName())
            {
                channel.Name = channelState.Name;
            }
            if (channelState.ShouldSerializeParent())
            {
                channel.Parent = channelState.Parent;
            }
            if (channelState.ShouldSerializeTemporary())
            {
                channel.Temporary = channelState.Temporary;
            }
            if (channelState.ShouldSerializeDescription())
            {
                channel.Description = channelState.Description;
            }
            if (channelState.ShouldSerializePosition())
            {
                channel.Position = channelState.Position;
            }

            if (channel.Id == 0)
            {
                RootChannel = channel;
            }

            ChannelJoined(channel);

            Extensions.Log.Info("Chanel State", channelState);
        }
Esempio n. 2
0
        internal void UpdateFromState(ChannelState deltaState)
        {
            if (deltaState.ShouldSerializeParent())
            {
                _channelState.Parent = deltaState.Parent;
            }
            if (deltaState.ShouldSerializeDescription())
            {
                _channelState.Description = deltaState.Description;
            }
            if (deltaState.ShouldSerializeName())
            {
                _channelState.Name = deltaState.Name;
            }
            if (deltaState.ShouldSerializeDescriptionHash())
            {
                _channelState.DescriptionHash = deltaState.DescriptionHash;
            }
            if (deltaState.ShouldSerializeMaxUsers())
            {
                _channelState.MaxUsers = deltaState.MaxUsers;
            }
            if (deltaState.ShouldSerializePosition())
            {
                _channelState.Position = deltaState.Position;
            }

            // Link updates happen in a sorta weird way
            if (deltaState.Links != null)
            {
                _channelState.Links = deltaState.Links;
            }
            UpdateLinks(deltaState.LinksAdds, deltaState.LinksRemoves);
            //Debug.LogWarning("Updated channel: " + Name);
            //Debug.Log("Set: " + (deltaState.Links == null ? 0 : deltaState.Links.Length));
            //Debug.Log("Added: " + (deltaState.LinksAdds == null ? 0 : deltaState.LinksAdds.Length));
            //Debug.Log("Removed: " + (deltaState.LinksRemoves == null ? 0 : deltaState.LinksRemoves.Length));
        }