/// <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 InternalCacheProperties(Hashtable properties) { if (properties == null || properties.Count == 0 || this.CustomProperties.Equals(properties)) { return; } if (properties.ContainsKey(ActorProperties.PlayerName)) { string nameInServersProperties = (string)properties[ActorProperties.PlayerName]; if (nameInServersProperties != null) { if (this.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(this.nickName)) { this.SetPlayerNameProperty(); } } else { this.NickName = nameInServersProperties; } } } if (properties.ContainsKey(ActorProperties.UserId)) { this.UserId = (string)properties[ActorProperties.UserId]; } if (properties.ContainsKey(ActorProperties.IsInactive)) { this.IsInactive = (bool)properties[ActorProperties.IsInactive]; //TURNBASED new well-known propery for players } this.CustomProperties.MergeStringKeys(properties); this.CustomProperties.StripKeysWithNullValues(); }
/// <summary>Copies "well known" properties to fields (IsVisible, etc) and caches the custom properties (string-keys only) in a local hashtable.</summary> /// <param name="propertiesToCache">New or updated properties to store in this RoomInfo.</param> protected internal virtual void InternalCacheProperties(Hashtable propertiesToCache) { if (propertiesToCache == null || propertiesToCache.Count == 0 || this.customProperties.Equals(propertiesToCache)) { return; } // check of this game was removed from the list. in that case, we don't // need to read any further properties // list updates will remove this game from the game listing if (propertiesToCache.ContainsKey(GamePropertyKey.Removed)) { this.removedFromList = (bool)propertiesToCache[GamePropertyKey.Removed]; if (this.removedFromList) { return; } } // fetch the "well known" properties of the room, if available if (propertiesToCache.ContainsKey(GamePropertyKey.MaxPlayers)) { this.maxPlayers = (byte)propertiesToCache[GamePropertyKey.MaxPlayers]; } if (propertiesToCache.ContainsKey(GamePropertyKey.IsOpen)) { this.isOpen = (bool)propertiesToCache[GamePropertyKey.IsOpen]; } if (propertiesToCache.ContainsKey(GamePropertyKey.IsVisible)) { this.isVisible = (bool)propertiesToCache[GamePropertyKey.IsVisible]; } if (propertiesToCache.ContainsKey(GamePropertyKey.PlayerCount)) { this.PlayerCount = (int)((byte)propertiesToCache[GamePropertyKey.PlayerCount]); } if (propertiesToCache.ContainsKey(GamePropertyKey.CleanupCacheOnLeave)) { this.autoCleanUp = (bool)propertiesToCache[GamePropertyKey.CleanupCacheOnLeave]; } if (propertiesToCache.ContainsKey(GamePropertyKey.MasterClientId)) { this.masterClientId = (int)propertiesToCache[GamePropertyKey.MasterClientId]; } if (propertiesToCache.ContainsKey(GamePropertyKey.PropsListedInLobby)) { this.propertiesListedInLobby = propertiesToCache[GamePropertyKey.PropsListedInLobby] as string[]; } if (propertiesToCache.ContainsKey((byte)GamePropertyKey.ExpectedUsers)) { this.expectedUsers = (string[])propertiesToCache[GamePropertyKey.ExpectedUsers]; } // merge the custom properties (from your application) to the cache (only string-typed keys will be kept) this.customProperties.MergeStringKeys(propertiesToCache); this.customProperties.StripKeysWithNullValues(); }