Skip to content

Commit f805714

Browse files
committed
Added further duplication checks to netconfig
1 parent 21b5942 commit f805714

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private void OnValidate()
155155
{
156156
if (NetworkConfig == null)
157157
return; //May occur when the component is added
158-
158+
159159
if(NetworkConfig.EnableSceneSwitching && !NetworkConfig.RegisteredScenes.Contains(SceneManager.GetActiveScene().name))
160160
{
161161
Debug.LogWarning("MLAPI: The active scene is not registered as a networked scene. The MLAPI has added it");
@@ -252,10 +252,17 @@ private ConnectionConfig Init(bool server)
252252
NetworkConfig.NetworkPrefabIds = new Dictionary<string, int>();
253253
NetworkConfig.NetworkPrefabNames = new Dictionary<int, string>();
254254
NetworkConfig.NetworkedPrefabs.OrderBy(x => x.name);
255+
HashSet<string> networkedPrefabName = new HashSet<string>();
255256
for (int i = 0; i < NetworkConfig.NetworkedPrefabs.Count; i++)
256257
{
258+
if (networkedPrefabName.Contains(NetworkConfig.NetworkedPrefabs[i].name))
259+
{
260+
Debug.LogWarning("MLAPI: Duplicate NetworkedPrefabName " + NetworkConfig.NetworkedPrefabs[i].name);
261+
continue;
262+
}
257263
NetworkConfig.NetworkPrefabIds.Add(NetworkConfig.NetworkedPrefabs[i].name, i);
258264
NetworkConfig.NetworkPrefabNames.Add(i, NetworkConfig.NetworkedPrefabs[i].name);
265+
networkedPrefabName.Add(NetworkConfig.NetworkedPrefabs[i].name);
259266
}
260267
if (NetworkConfig.EnableSceneSwitching)
261268
{
@@ -321,22 +328,38 @@ private ConnectionConfig Init(bool server)
321328

322329
if (NetworkConfig.EnableEncryption)
323330
{
331+
HashSet<string> addedEncryptedChannels = new HashSet<string>();
324332
for (int i = 0; i < NetworkConfig.Channels.Count; i++)
325333
{
334+
if (addedEncryptedChannels.Contains(NetworkConfig.Channels[i].Name))
335+
{
336+
Debug.LogWarning("MLAPI: Duplicate encrypted channel name " + NetworkConfig.Channels[i].Name);
337+
continue;
338+
}
326339
if (NetworkConfig.Channels[i].Encrypted)
327340
{
328341
NetworkConfig.EncryptedChannels.Add(NetworkConfig.Channels[i].Name);
329342
NetworkConfig.EncryptedChannelsHashSet.Add(NetworkConfig.Channels[i].Name);
330343
}
344+
addedEncryptedChannels.Add(NetworkConfig.Channels[i].Name);
331345
}
332346
}
333347

334348
if (NetworkConfig.AllowPassthroughMessages)
335349
{
350+
HashSet<string> addedPassthroughMessages = new HashSet<string>();
336351
for (int i = 0; i < NetworkConfig.MessageTypes.Count; i++)
337352
{
353+
if (addedPassthroughMessages.Contains(NetworkConfig.MessageTypes[i].Name))
354+
{
355+
Debug.LogWarning("MLAPI: Duplicate passthrough message type " + NetworkConfig.MessageTypes[i].Name);
356+
continue;
357+
}
338358
if (NetworkConfig.MessageTypes[i].Passthrough)
359+
{
339360
NetworkConfig.PassthroughMessageHashSet.Add(MessageManager.messageTypes[NetworkConfig.MessageTypes[i].Name]);
361+
addedPassthroughMessages.Add(NetworkConfig.MessageTypes[i].Name);
362+
}
340363
}
341364
}
342365

0 commit comments

Comments
 (0)