Fixed various issues with message passthrough

This commit is contained in:
Albin Corén 2018-01-10 14:16:06 +01:00
parent a2090443d4
commit bc78303957
2 changed files with 18 additions and 12 deletions

View File

@ -71,13 +71,6 @@ namespace MLAPI
MessageManager.reverseMessageTypes = new Dictionary<ushort, string>(); MessageManager.reverseMessageTypes = new Dictionary<ushort, string>();
SpawnManager.spawnedObjects = new Dictionary<uint, NetworkedObject>(); SpawnManager.spawnedObjects = new Dictionary<uint, NetworkedObject>();
SpawnManager.releasedNetworkObjectIds = new Stack<uint>(); SpawnManager.releasedNetworkObjectIds = new Stack<uint>();
if(NetworkConfig.AllowPassthroughMessages)
{
for (int i = 0; i < NetworkConfig.PassthroughMessageTypes.Count; i++)
{
NetworkConfig.RegisteredPassthroughMessageTypes.Add(MessageManager.messageTypes[NetworkConfig.PassthroughMessageTypes[i]]);
}
}
if (NetworkConfig.HandleObjectSpawning) if (NetworkConfig.HandleObjectSpawning)
{ {
NetworkedObject[] sceneObjects = FindObjectsOfType<NetworkedObject>(); NetworkedObject[] sceneObjects = FindObjectsOfType<NetworkedObject>();
@ -119,10 +112,19 @@ namespace MLAPI
ushort messageId = 32; ushort messageId = 32;
for (ushort i = 0; i < NetworkConfig.MessageTypes.Count; i++) for (ushort i = 0; i < NetworkConfig.MessageTypes.Count; i++)
{ {
MessageManager.reverseMessageTypes.Add(messageId, NetworkConfig.MessageTypes[i]);
MessageManager.messageTypes.Add(NetworkConfig.MessageTypes[i], messageId); MessageManager.messageTypes.Add(NetworkConfig.MessageTypes[i], messageId);
MessageManager.reverseMessageTypes.Add(messageId, NetworkConfig.MessageTypes[i]);
messageId++; messageId++;
} }
if (NetworkConfig.AllowPassthroughMessages)
{
for (int i = 0; i < NetworkConfig.PassthroughMessageTypes.Count; i++)
{
NetworkConfig.RegisteredPassthroughMessageTypes.Add(MessageManager.messageTypes[NetworkConfig.PassthroughMessageTypes[i]]);
}
}
return cConfig; return cConfig;
} }
@ -373,12 +375,16 @@ namespace MLAPI
Debug.LogWarning("MLAPI: Server tried to send a passthrough message for a messageType not registered as passthrough"); Debug.LogWarning("MLAPI: Server tried to send a passthrough message for a messageType not registered as passthrough");
return; return;
} }
else if(isServer && NetworkConfig.AllowPassthroughMessages && connectedClients.ContainsKey(passthroughTarget)) else if(isServer && isPassthrough)
{ {
if (!connectedClients.ContainsKey(passthroughTarget))
{
Debug.LogWarning("MLAPI: Passthrough message was sent with invalid target: " + passthroughTarget + " from client " + clientId);
return;
}
uint? netIdTarget = null; uint? netIdTarget = null;
if (targeted) if (targeted)
netIdTarget = targetNetworkId; netIdTarget = targetNetworkId;
PassthroughSend(passthroughTarget, clientId, messageType, channelId, incommingData, netIdTarget); PassthroughSend(passthroughTarget, clientId, messageType, channelId, incommingData, netIdTarget);
return; return;
} }

View File

@ -83,7 +83,7 @@ namespace MLAPI.NetworkingManagerComponents
internal static void OnDestroyObject(uint networkId, bool destroyGameObject) internal static void OnDestroyObject(uint networkId, bool destroyGameObject)
{ {
if (!spawnedObjects.ContainsKey(networkId) || !netManager.NetworkConfig.HandleObjectSpawning) if (!spawnedObjects.ContainsKey(networkId) || (netManager != null && !netManager.NetworkConfig.HandleObjectSpawning))
return; return;
GameObject go = spawnedObjects[networkId].gameObject; GameObject go = spawnedObjects[networkId].gameObject;
if (netManager != null && netManager.isServer) if (netManager != null && netManager.isServer)
@ -98,7 +98,7 @@ namespace MLAPI.NetworkingManagerComponents
writer.Write(networkId); writer.Write(networkId);
} }
//If we are host, send to everyone except ourselves. Otherwise, send to all //If we are host, send to everyone except ourselves. Otherwise, send to all
if (netManager.isHost) if (netManager != null && netManager.isHost)
netManager.Send("MLAPI_DESTROY_OBJECT", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.GetBuffer(), -1); netManager.Send("MLAPI_DESTROY_OBJECT", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.GetBuffer(), -1);
else else
netManager.Send("MLAPI_DESTROY_OBJECT", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.GetBuffer()); netManager.Send("MLAPI_DESTROY_OBJECT", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.GetBuffer());