Ejemplo n.º 1
0
 protected internal void CacheProperties(Hashtable propertiesToCache)
 {
     if (((propertiesToCache != null) && (propertiesToCache.Count != 0)) && !CustomProperties.Equals(propertiesToCache))
     {
         if (propertiesToCache.CheckKey(RoomProperty.RemovedFromList, out bool removed, true))
         {
             RemovedFromList = removed;
         }
         if (propertiesToCache.CheckKey(RoomProperty.MaxPlayers, out byte max, true))
         {
             maxPlayersField = max;
         }
         if (propertiesToCache.CheckKey(RoomProperty.Visibility, out bool visible, true))
         {
             visibleField = visible;
         }
         if (propertiesToCache.CheckKey(RoomProperty.Joinable, out bool joinable, true))
         {
             openField = joinable;
         }
         if (propertiesToCache.CheckKey(RoomProperty.PlayerCount, out byte players, true))
         {
             PlayerCount = players;
         }
         if (propertiesToCache.CheckKey(RoomProperty.CleanUpCacheOnLeave, out bool cleanup, true))
         {
             autoCleanUpField = cleanup;
         }
         CustomProperties.MergeStringKeys(propertiesToCache);
     }
 }
Ejemplo n.º 2
0
        /// <summary>Caches properties for new Players or when updates of remote players are received. Use SetCustomProperties() for a synced update.</summary>
        /// <remarks>
        /// This only updates the CustomProperties and doesn't send them to the server.
        /// Mostly used when creating new remote players, where the server sends their properties.
        /// </remarks>
        public virtual void CacheProperties(Hashtable properties)
        {
            if (properties == null || properties.Count == 0 || CustomProperties.Equals(properties))
            {
                return;
            }

            if (properties.ContainsKey(ActorProperties.PlayerName))
            {
                var nameInServersProperties = (string)properties[ActorProperties.PlayerName];
                if (nameInServersProperties != null)
                {
                    if (IsLocal)
                    {
                        // the local playername is different than in the properties coming from the server
                        // so the local nickName was changed and the server is outdated -> update server
                        // update property instead of using the outdated nickName coming from server
                        if (!nameInServersProperties.Equals(nickName))
                        {
                            SetPlayerNameProperty();
                        }
                    }
                    else
                    {
                        NickName = nameInServersProperties;
                    }
                }
            }

            if (properties.ContainsKey(ActorProperties.IsInactive))
            {
                IsInactive = (bool)properties[ActorProperties.IsInactive];
                //TURNBASED new well-known propery for players
            }

            CustomProperties.MergeStringKeys(properties);
        }