Skip to content

Commit 9c11fa0

Browse files
committed
Added checks to prevent simulations to be ran on non Servers
1 parent a24588e commit 9c11fa0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

MLAPI/MonoBehaviours/Core/LagCompensationManager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using UnityEngine;
34
using UnityEngine.Networking;
45

56
namespace MLAPI.MonoBehaviours.Core
@@ -10,6 +11,11 @@ public static class LagCompensationManager
1011

1112
public static void Simulate(float secondsAgo, Action action)
1213
{
14+
if(!NetworkingManager.singleton.isServer)
15+
{
16+
Debug.LogWarning("MLAPI: Lag compensation simulations are only to be ran on the server.");
17+
return;
18+
}
1319
for (int i = 0; i < SimulationObjects.Count; i++)
1420
{
1521
SimulationObjects[i].ReverseTransform(secondsAgo);
@@ -26,6 +32,11 @@ public static void Simulate(float secondsAgo, Action action)
2632
private static byte error = 0;
2733
public static void Simulate(int clientId, Action action)
2834
{
35+
if (!NetworkingManager.singleton.isServer)
36+
{
37+
Debug.LogWarning("MLAPI: Lag compensation simulations are only to be ran on the server.");
38+
return;
39+
}
2940
float milisecondsDelay = NetworkTransport.GetCurrentRTT(NetworkingManager.singleton.hostId, clientId, out error) / 2f;
3041
Simulate(milisecondsDelay * 1000f, action);
3142
}

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ private void Update()
329329
(messagesProcessed < NetworkConfig.MaxMessagesPerFrame || NetworkConfig.MaxMessagesPerFrame < 0));
330330

331331
}
332-
LagCompensationManager.AddFrames();
332+
if (isServer)
333+
LagCompensationManager.AddFrames();
333334
}
334335

335336
private IEnumerator ApprovalTimeout(int clientId)

0 commit comments

Comments
 (0)