Added checks to prevent simulations to be ran on non Servers

This commit is contained in:
Albin Corén 2018-03-04 20:40:34 +01:00
parent a24588e6a7
commit 9c11fa07e5
2 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
namespace MLAPI.MonoBehaviours.Core namespace MLAPI.MonoBehaviours.Core
@ -10,6 +11,11 @@ namespace MLAPI.MonoBehaviours.Core
public static void Simulate(float secondsAgo, Action action) public static void Simulate(float secondsAgo, Action action)
{ {
if(!NetworkingManager.singleton.isServer)
{
Debug.LogWarning("MLAPI: Lag compensation simulations are only to be ran on the server.");
return;
}
for (int i = 0; i < SimulationObjects.Count; i++) for (int i = 0; i < SimulationObjects.Count; i++)
{ {
SimulationObjects[i].ReverseTransform(secondsAgo); SimulationObjects[i].ReverseTransform(secondsAgo);
@ -26,6 +32,11 @@ namespace MLAPI.MonoBehaviours.Core
private static byte error = 0; private static byte error = 0;
public static void Simulate(int clientId, Action action) public static void Simulate(int clientId, Action action)
{ {
if (!NetworkingManager.singleton.isServer)
{
Debug.LogWarning("MLAPI: Lag compensation simulations are only to be ran on the server.");
return;
}
float milisecondsDelay = NetworkTransport.GetCurrentRTT(NetworkingManager.singleton.hostId, clientId, out error) / 2f; float milisecondsDelay = NetworkTransport.GetCurrentRTT(NetworkingManager.singleton.hostId, clientId, out error) / 2f;
Simulate(milisecondsDelay * 1000f, action); Simulate(milisecondsDelay * 1000f, action);
} }

View File

@ -329,6 +329,7 @@ namespace MLAPI
(messagesProcessed < NetworkConfig.MaxMessagesPerFrame || NetworkConfig.MaxMessagesPerFrame < 0)); (messagesProcessed < NetworkConfig.MaxMessagesPerFrame || NetworkConfig.MaxMessagesPerFrame < 0));
} }
if (isServer)
LagCompensationManager.AddFrames(); LagCompensationManager.AddFrames();
} }