diff --git a/QSB/Ghostbuster.cs b/QSB/Ghostbuster.cs new file mode 100644 index 00000000..e1d9483c --- /dev/null +++ b/QSB/Ghostbuster.cs @@ -0,0 +1,66 @@ +using Mirror; +using QSB.Player; +using QSB.Utility; +using System.Collections.Generic; +using UnityEngine; + +namespace QSB; +internal class Ghostbuster : MonoBehaviour, IAddComponentOnStart +{ + private const int UpdateInterval = 60; + + private int _updateCount; + + public void Update() + { + if (!QSBCore.IsInMultiplayer) + { + return; + } + + if (!QSBCore.IsHost) + { + return; + } + + if (_updateCount != UpdateInterval) + { + _updateCount++; + return; + } + else + { + _updateCount = 0; + } + + var _ghostPlayers = new List(); + + foreach (var player in QSBPlayerManager.PlayerList) + { + var isGhost = false; + + var networkIdentity = player.TransformSync.netIdentity; + + if (networkIdentity.connectionToClient == null) + { + isGhost = true; + } + else if (!NetworkServer.connections.ContainsValue(networkIdentity.connectionToClient)) + { + isGhost = true; + } + + if (isGhost) + { + // WE GOT ONE!!!!!! + _ghostPlayers.Add(player); + } + } + + foreach (var item in _ghostPlayers) + { + DebugLog.ToConsole($"Deleting playerId:{item.PlayerId} - It's a ghooOoOoOooost! (hopefully)", OWML.Common.MessageType.Info); + NetworkServer.DestroyPlayerForConnection(item.TransformSync.netIdentity.connectionToClient); + } + } +} diff --git a/QSB/HUD/MultiplayerHUDManager.cs b/QSB/HUD/MultiplayerHUDManager.cs index bdf89e64..cac810e2 100644 --- a/QSB/HUD/MultiplayerHUDManager.cs +++ b/QSB/HUD/MultiplayerHUDManager.cs @@ -220,7 +220,7 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart private void OnRemovePlayer(PlayerInfo player) { - Destroy(player.HUDBox.gameObject); + Destroy(player.HUDBox?.gameObject); } private PlanetTrigger CreateTrigger(string parentPath, HUDIcon icon) diff --git a/QSB/Player/Patches/VolumePatches.cs b/QSB/Player/Patches/VolumePatches.cs index 84131603..81152e7f 100644 --- a/QSB/Player/Patches/VolumePatches.cs +++ b/QSB/Player/Patches/VolumePatches.cs @@ -49,10 +49,16 @@ internal class VolumePatches : QSBPatch public static bool PreventRemotePlayerEnter(object __instance, GameObject hitObj) { DebugLog.DebugWrite($"{__instance} funny prevent enter {hitObj}"); - // this is a dogshit fix to a bug where this would ApplyShock to remote players, - // which would actually apply the shock affects to the entire planet / sector - // // TODO: also do this with remote probes return hitObj.name is not ("REMOTE_PlayerDetector" or "REMOTE_CameraDetector"); } + + [HarmonyPrefix] + [HarmonyPatch(typeof(VanishVolume), nameof(VanishVolume.OnTriggerEnter))] + public static bool PreventRemotePlayerEnter(object __instance, Collider hitCollider) + { + DebugLog.DebugWrite($"{__instance} funny prevent enter {hitCollider}"); + // TODO: also do this with remote probes + return hitCollider.name is not ("REMOTE_PlayerDetector" or "REMOTE_CameraDetector"); + } } diff --git a/QSB/Player/TransformSync/PlayerTransformSync.cs b/QSB/Player/TransformSync/PlayerTransformSync.cs index c030693c..4cadce5b 100644 --- a/QSB/Player/TransformSync/PlayerTransformSync.cs +++ b/QSB/Player/TransformSync/PlayerTransformSync.cs @@ -36,7 +36,7 @@ public class PlayerTransformSync : SectoredTransformSync var player = new PlayerInfo(this); QSBPlayerManager.PlayerList.SafeAdd(player); base.OnStartClient(); - QSBPlayerManager.OnAddPlayer?.Invoke(Player); + QSBPlayerManager.OnAddPlayer?.SafeInvoke(Player); DebugLog.DebugWrite($"Create Player : {Player}", MessageType.Info); JoinLeaveSingularity.Create(Player, true); @@ -50,7 +50,7 @@ public class PlayerTransformSync : SectoredTransformSync // TODO : Maybe move this to a leave event...? Would ensure everything could finish up before removing the player QSBPatch.Remote = true; - QSBPlayerManager.OnRemovePlayer?.Invoke(Player); + QSBPlayerManager.OnRemovePlayer?.SafeInvoke(Player); QSBPatch.Remote = false; base.OnStopClient(); Player.HudMarker?.Remove(); diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index f52bdb61..519e684f 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -16,7 +16,7 @@ - + diff --git a/QSB/Utility/DebugActions.cs b/QSB/Utility/DebugActions.cs index 5f75a53c..4749c8cc 100644 --- a/QSB/Utility/DebugActions.cs +++ b/QSB/Utility/DebugActions.cs @@ -226,7 +226,7 @@ public class DebugActions : MonoBehaviour, IAddComponentOnStart { var player = new PlayerInfo(QSBPlayerManager.LocalPlayer.TransformSync); QSBPlayerManager.PlayerList.SafeAdd(player); - QSBPlayerManager.OnAddPlayer?.Invoke(player); + QSBPlayerManager.OnAddPlayer?.SafeInvoke(player); DebugLog.DebugWrite($"CREATING FAKE PLAYER : {player}", MessageType.Info); JoinLeaveSingularity.Create(player, true); diff --git a/QSB/Utility/DebugGUI.cs b/QSB/Utility/DebugGUI.cs index 54139539..4f6acf43 100644 --- a/QSB/Utility/DebugGUI.cs +++ b/QSB/Utility/DebugGUI.cs @@ -159,6 +159,12 @@ internal class DebugGUI : MonoBehaviour, IAddComponentOnStart { WriteLine(1, $" - {item}"); } + + WriteLine(1, $"Sectors :"); + foreach (var sector in PlayerTransformSync.LocalInstance.SectorDetector.SectorList) + { + WriteLine(1, $"- {sector.Name}"); + } } #endregion @@ -196,12 +202,6 @@ internal class DebugGUI : MonoBehaviour, IAddComponentOnStart WriteLine(2, $" - Ref. Sector : {(referenceSector == null ? "NULL" : referenceSector.Name)}", referenceSector == null ? Color.red : Color.white); WriteLine(2, $" - Ref. Transform : {(referenceTransform == null ? "NULL" : referenceTransform.name)}", referenceTransform == null ? Color.red : Color.white); - - WriteLine(2, $"Sectors :"); - foreach (var sector in PlayerTransformSync.LocalInstance.SectorDetector.SectorList) - { - WriteLine(2, $"- {sector.Name}"); - } } } diff --git a/QSB/Utility/Extensions.cs b/QSB/Utility/Extensions.cs index 0b1488c5..41d4e8c7 100644 --- a/QSB/Utility/Extensions.cs +++ b/QSB/Utility/Extensions.cs @@ -1,6 +1,7 @@ using Cysharp.Threading.Tasks; using Mirror; using OWML.Common; +using QSB.Player; using System; using System.Collections.Generic; using System.Linq; @@ -40,10 +41,10 @@ public static class Extensions public static uint GetPlayerId(this NetworkConnectionToClient conn) { - if (!conn.identity) + if (conn.identity == null) { // wtf - DebugLog.ToConsole($"Error - GetPlayerId on {conn} has no identity\n{Environment.StackTrace}", MessageType.Error); + DebugLog.ToConsole($"Error - GetPlayerId on {conn} has no identity.", MessageType.Error); return uint.MaxValue; } diff --git a/QSB/manifest.json b/QSB/manifest.json index 983d635f..d95fa49b 100644 --- a/QSB/manifest.json +++ b/QSB/manifest.json @@ -7,7 +7,7 @@ "body": "- Disable *all* other mods. (Can heavily affect performance)\n- Make sure you are not running any other network-intensive applications." }, "uniqueName": "Raicuparta.QuantumSpaceBuddies", - "version": "0.26.1", + "version": "0.26.3", "owmlVersion": "2.9.0", "dependencies": [ "_nebula.MenuFramework", "JohnCorby.VanillaFix" ], "pathsToPreserve": [ "debugsettings.json" ],