From f8057144dca4b619937234066e4b134f7afce7e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Cor=C3=A9n?= Date: Tue, 17 Apr 2018 10:18:30 +0200 Subject: [PATCH] Added further duplication checks to netconfig --- .../MonoBehaviours/Core/NetworkingManager.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/MLAPI/MonoBehaviours/Core/NetworkingManager.cs b/MLAPI/MonoBehaviours/Core/NetworkingManager.cs index bcdf548..f8e8cdb 100644 --- a/MLAPI/MonoBehaviours/Core/NetworkingManager.cs +++ b/MLAPI/MonoBehaviours/Core/NetworkingManager.cs @@ -155,7 +155,7 @@ namespace MLAPI.MonoBehaviours.Core { if (NetworkConfig == null) return; //May occur when the component is added - + if(NetworkConfig.EnableSceneSwitching && !NetworkConfig.RegisteredScenes.Contains(SceneManager.GetActiveScene().name)) { Debug.LogWarning("MLAPI: The active scene is not registered as a networked scene. The MLAPI has added it"); @@ -252,10 +252,17 @@ namespace MLAPI.MonoBehaviours.Core NetworkConfig.NetworkPrefabIds = new Dictionary(); NetworkConfig.NetworkPrefabNames = new Dictionary(); NetworkConfig.NetworkedPrefabs.OrderBy(x => x.name); + HashSet networkedPrefabName = new HashSet(); for (int i = 0; i < NetworkConfig.NetworkedPrefabs.Count; i++) { + if (networkedPrefabName.Contains(NetworkConfig.NetworkedPrefabs[i].name)) + { + Debug.LogWarning("MLAPI: Duplicate NetworkedPrefabName " + NetworkConfig.NetworkedPrefabs[i].name); + continue; + } NetworkConfig.NetworkPrefabIds.Add(NetworkConfig.NetworkedPrefabs[i].name, i); NetworkConfig.NetworkPrefabNames.Add(i, NetworkConfig.NetworkedPrefabs[i].name); + networkedPrefabName.Add(NetworkConfig.NetworkedPrefabs[i].name); } if (NetworkConfig.EnableSceneSwitching) { @@ -321,22 +328,38 @@ namespace MLAPI.MonoBehaviours.Core if (NetworkConfig.EnableEncryption) { + HashSet addedEncryptedChannels = new HashSet(); for (int i = 0; i < NetworkConfig.Channels.Count; i++) { + if (addedEncryptedChannels.Contains(NetworkConfig.Channels[i].Name)) + { + Debug.LogWarning("MLAPI: Duplicate encrypted channel name " + NetworkConfig.Channels[i].Name); + continue; + } if (NetworkConfig.Channels[i].Encrypted) { NetworkConfig.EncryptedChannels.Add(NetworkConfig.Channels[i].Name); NetworkConfig.EncryptedChannelsHashSet.Add(NetworkConfig.Channels[i].Name); } + addedEncryptedChannels.Add(NetworkConfig.Channels[i].Name); } } if (NetworkConfig.AllowPassthroughMessages) { + HashSet addedPassthroughMessages = new HashSet(); for (int i = 0; i < NetworkConfig.MessageTypes.Count; i++) { + if (addedPassthroughMessages.Contains(NetworkConfig.MessageTypes[i].Name)) + { + Debug.LogWarning("MLAPI: Duplicate passthrough message type " + NetworkConfig.MessageTypes[i].Name); + continue; + } if (NetworkConfig.MessageTypes[i].Passthrough) + { NetworkConfig.PassthroughMessageHashSet.Add(MessageManager.messageTypes[NetworkConfig.MessageTypes[i].Name]); + addedPassthroughMessages.Add(NetworkConfig.MessageTypes[i].Name); + } } }