add packet loss test

This commit is contained in:
_nebula 2023-06-11 01:00:27 +01:00
parent 43ac9d1c0d
commit 4d50945e01
2 changed files with 45 additions and 1 deletions

View File

@ -10,6 +10,7 @@ using QSB.ShipSync;
using QSB.Utility.Messages;
using QSB.WorldSync;
using System;
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.InputSystem;
@ -200,7 +201,10 @@ public class DebugActions : MonoBehaviour, IAddComponentOnStart
if (Keyboard.current[Key.Numpad4].wasPressedThisFrame)
{
DamageShipElectricalSystem();
if (QSBCore.IsHost)
{
StartCoroutine(SendPacketLossTest());
}
}
if (Keyboard.current[Key.Numpad5].wasPressedThisFrame)
@ -242,4 +246,21 @@ public class DebugActions : MonoBehaviour, IAddComponentOnStart
RespawnManager.Instance.RespawnSomePlayer();
}
}
const int MAX_MESSAGES = 100;
int currentMessage = 1;
public static int TotalMessages;
IEnumerator SendPacketLossTest()
{
DebugLog.DebugWrite($"STARTING DROPPED MESSAGE TEST...");
while (currentMessage <= MAX_MESSAGES)
{
new PacketLossTestMessage().Send();
currentMessage++;
yield return new WaitForSeconds(0.25f);
}
}
}

View File

@ -0,0 +1,23 @@
using QSB.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QSB.Utility.Messages;
internal class PacketLossTestMessage : QSBMessage
{
public override void OnReceiveLocal()
{
DebugActions.TotalMessages += 1;
DebugLog.DebugWrite($"Total test messages sent is now {DebugActions.TotalMessages}");
}
public override void OnReceiveRemote()
{
DebugActions.TotalMessages += 1;
DebugLog.DebugWrite($"Total test messages recieved is now {DebugActions.TotalMessages}");
}
}