Skip to content

Commit 5b227ed

Browse files
committed
Merge branch 'master' of https://github.com/MidLevel/MLAPI
2 parents a341c84 + dbc539d commit 5b227ed

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

MLAPI/Core/NetworkingManager.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,18 @@ private void Init(bool server)
381381

382382
for (int i = 0; i < NetworkConfig.NetworkedPrefabs.Count; i++)
383383
{
384-
NetworkConfig.NetworkedPrefabs[i].Prefab.GetComponent<NetworkedObject>().ValidateHash();
384+
if (NetworkConfig.NetworkedPrefabs[i] == null || NetworkConfig.NetworkedPrefabs[i].Prefab == null)
385+
{
386+
if (LogHelper.CurrentLogLevel <= LogLevel.Error) LogHelper.LogError("Networked prefab cannot be null");
387+
}
388+
else if (NetworkConfig.NetworkedPrefabs[i].Prefab.GetComponent<NetworkedObject>() == null)
389+
{
390+
if (LogHelper.CurrentLogLevel <= LogLevel.Error) LogHelper.LogError("Networked prefab is missing a NetworkedObject component");
391+
}
392+
else
393+
{
394+
NetworkConfig.NetworkedPrefabs[i].Prefab.GetComponent<NetworkedObject>().ValidateHash();
395+
}
385396
}
386397

387398
NetworkConfig.NetworkTransport.OnTransportEvent += HandleRawTransportPoll;
@@ -615,7 +626,7 @@ private void Shutdown()
615626
private float lastTimeSyncTime;
616627
private void Update()
617628
{
618-
if(IsListening)
629+
if (IsListening)
619630
{
620631
if ((NetworkTime - lastReceiveTickTime >= (1f / NetworkConfig.ReceiveTickrate)) || NetworkConfig.ReceiveTickrate <= 0)
621632
{
@@ -634,6 +645,12 @@ private void Update()
634645
NetworkProfiler.EndTick();
635646
}
636647

648+
if (!IsListening)
649+
{
650+
// If we get disconnected in the previous poll. IsListening will be set to false.
651+
return;
652+
}
653+
637654
if (((NetworkTime - lastEventTickTime >= (1f / NetworkConfig.EventTickrate))))
638655
{
639656
NetworkProfiler.StartTick(TickType.Event);

MLAPI/Messaging/RpcTypeDefinition.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,21 @@ private RpcTypeDefinition(Type type)
8080

8181
Dictionary<ulong, ReflectionMethod> lookupTarget = rpcMethod.serverTarget ? serverMethods : clientMethods;
8282

83-
lookupTarget.Add(HashMethodNameAndValidate(method.Name), rpcMethod);
83+
ulong nameHash = HashMethodNameAndValidate(method.Name);
84+
85+
if (!lookupTarget.ContainsKey(nameHash))
86+
{
87+
lookupTarget.Add(nameHash, rpcMethod);
88+
}
8489

8590
if (parameters.Length > 0)
8691
{
87-
lookupTarget.Add(HashMethodNameAndValidate(NetworkedBehaviour.GetHashableMethodSignature(method)), rpcMethod);
92+
ulong signatureHash = HashMethodNameAndValidate(NetworkedBehaviour.GetHashableMethodSignature(method));
93+
94+
if (!lookupTarget.ContainsKey(signatureHash))
95+
{
96+
lookupTarget.Add(signatureHash, rpcMethod);
97+
}
8898
}
8999

90100
if (rpcMethod.useDelegate)

0 commit comments

Comments
 (0)