Skip to content

Commit bc78303

Browse files
committed
Fixed various issues with message passthrough
1 parent a209044 commit bc78303

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

+16-10
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ private ConnectionConfig Init(NetworkingConfiguration netConfig)
7171
MessageManager.reverseMessageTypes = new Dictionary<ushort, string>();
7272
SpawnManager.spawnedObjects = new Dictionary<uint, NetworkedObject>();
7373
SpawnManager.releasedNetworkObjectIds = new Stack<uint>();
74-
if(NetworkConfig.AllowPassthroughMessages)
75-
{
76-
for (int i = 0; i < NetworkConfig.PassthroughMessageTypes.Count; i++)
77-
{
78-
NetworkConfig.RegisteredPassthroughMessageTypes.Add(MessageManager.messageTypes[NetworkConfig.PassthroughMessageTypes[i]]);
79-
}
80-
}
8174
if (NetworkConfig.HandleObjectSpawning)
8275
{
8376
NetworkedObject[] sceneObjects = FindObjectsOfType<NetworkedObject>();
@@ -119,10 +112,19 @@ private ConnectionConfig Init(NetworkingConfiguration netConfig)
119112
ushort messageId = 32;
120113
for (ushort i = 0; i < NetworkConfig.MessageTypes.Count; i++)
121114
{
122-
MessageManager.reverseMessageTypes.Add(messageId, NetworkConfig.MessageTypes[i]);
123115
MessageManager.messageTypes.Add(NetworkConfig.MessageTypes[i], messageId);
116+
MessageManager.reverseMessageTypes.Add(messageId, NetworkConfig.MessageTypes[i]);
124117
messageId++;
125118
}
119+
120+
if (NetworkConfig.AllowPassthroughMessages)
121+
{
122+
for (int i = 0; i < NetworkConfig.PassthroughMessageTypes.Count; i++)
123+
{
124+
NetworkConfig.RegisteredPassthroughMessageTypes.Add(MessageManager.messageTypes[NetworkConfig.PassthroughMessageTypes[i]]);
125+
}
126+
}
127+
126128
return cConfig;
127129
}
128130

@@ -373,12 +375,16 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
373375
Debug.LogWarning("MLAPI: Server tried to send a passthrough message for a messageType not registered as passthrough");
374376
return;
375377
}
376-
else if(isServer && NetworkConfig.AllowPassthroughMessages && connectedClients.ContainsKey(passthroughTarget))
378+
else if(isServer && isPassthrough)
377379
{
380+
if (!connectedClients.ContainsKey(passthroughTarget))
381+
{
382+
Debug.LogWarning("MLAPI: Passthrough message was sent with invalid target: " + passthroughTarget + " from client " + clientId);
383+
return;
384+
}
378385
uint? netIdTarget = null;
379386
if (targeted)
380387
netIdTarget = targetNetworkId;
381-
382388
PassthroughSend(passthroughTarget, clientId, messageType, channelId, incommingData, netIdTarget);
383389
return;
384390
}

MLAPI/NetworkingManagerComponents/SpawnManager.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ internal static GameObject SpawnPlayerObject(int clientId, uint networkId)
8383

8484
internal static void OnDestroyObject(uint networkId, bool destroyGameObject)
8585
{
86-
if (!spawnedObjects.ContainsKey(networkId) || !netManager.NetworkConfig.HandleObjectSpawning)
86+
if (!spawnedObjects.ContainsKey(networkId) || (netManager != null && !netManager.NetworkConfig.HandleObjectSpawning))
8787
return;
8888
GameObject go = spawnedObjects[networkId].gameObject;
8989
if (netManager != null && netManager.isServer)
@@ -98,7 +98,7 @@ internal static void OnDestroyObject(uint networkId, bool destroyGameObject)
9898
writer.Write(networkId);
9999
}
100100
//If we are host, send to everyone except ourselves. Otherwise, send to all
101-
if (netManager.isHost)
101+
if (netManager != null && netManager.isHost)
102102
netManager.Send("MLAPI_DESTROY_OBJECT", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.GetBuffer(), -1);
103103
else
104104
netManager.Send("MLAPI_DESTROY_OBJECT", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.GetBuffer());

0 commit comments

Comments
 (0)