heartbeat sucks

This commit is contained in:
JohnCorby 2022-08-25 18:12:26 -07:00
parent 6126136abb
commit f9c24128da
4 changed files with 1 additions and 70 deletions

View File

@ -1,20 +0,0 @@
using QSB.Messaging;
namespace QSB.Player.Messages;
internal class PlayerHeartbeatMessage : QSBMessage
{
public override void OnReceiveRemote()
{
if (!QSBCore.IsHost)
{
// send a response back to the host
new PlayerHeartbeatMessage { To = 0 }.Send();
}
else
{
// note that we got a response
QSBPlayerManager.GetPlayer(From).HeartbeatReceived = true;
}
}
}

View File

@ -35,11 +35,6 @@ public partial class PlayerInfo
public ThrusterLightTracker ThrusterLightTracker;
public bool FlyingShip => ShipManager.Instance.CurrentFlyer == PlayerId;
/// <summary>
/// only used on host
/// </summary>
public bool HeartbeatReceived;
public PlayerInfo(PlayerTransformSync transformSync)
{
PlayerId = transformSync.netId;

View File

@ -1,14 +1,10 @@
using Mirror;
using OWML.Common;
using OWML.Common;
using QSB.ItemSync.WorldObjects.Items;
using QSB.Messaging;
using QSB.Player.Messages;
using QSB.Player.TransformSync;
using QSB.Tools.FlashlightTool;
using QSB.Tools.ProbeTool;
using QSB.Utility;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
@ -129,41 +125,4 @@ public static class QSBPlayerManager
public static IEnumerable<(PlayerInfo Player, IQSBItem HeldItem)> GetPlayerCarryItems()
=> PlayerList.Select(x => (x, x.HeldItem));
public static IEnumerator SendHeartbeat()
{
// yeah mirror has its own hearbeat stuff, but we have problems with "ghost" PlayerInfos due to epic transport being goofy
while (true)
{
if (QSBCore.IsInMultiplayer && QSBCore.IsHost)
{
// iterate backwards since we sometimes remove
for (var i = PlayerList.Count - 1; i >= 0; i--)
{
var player = PlayerList[i];
if (player.IsLocalPlayer)
{
continue;
}
// if we didn't receive a response in the last iteration then we should remove them
if (!player.HeartbeatReceived)
{
DebugLog.DebugWrite($"Didn't receive heartbeat from {player} in time. Removing them.", MessageType.Warning);
NetworkServer.Destroy(player.TransformSync.gameObject);
}
// reset the state for the next send
player.HeartbeatReceived = false;
}
// send out the ping
new PlayerHeartbeatMessage().Send();
}
yield return new WaitForSecondsRealtime(10);
}
}
}

View File

@ -5,7 +5,6 @@ using OWML.ModHelper;
using QSB.Localization;
using QSB.Menus;
using QSB.Patches;
using QSB.Player;
using QSB.QuantumSync;
using QSB.SaveSync;
using QSB.Utility;
@ -188,8 +187,6 @@ public class QSBCore : ModBehaviour
QSBWorldSync.Managers = components.OfType<WorldObjectManager>().ToArray();
QSBPatchManager.OnPatchType += OnPatchType;
QSBPatchManager.OnUnpatchType += OnUnpatchType;
StartCoroutine(QSBPlayerManager.SendHeartbeat());
}
private static void OnPatchType(QSBPatchTypes type)