mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-21 00:39:53 +00:00
remove ValidatePlayers
This commit is contained in:
parent
ca42319262
commit
0495e256b3
@ -126,68 +126,4 @@ public static class QSBPlayerManager
|
||||
|
||||
public static IEnumerable<(PlayerInfo Player, IQSBItem HeldItem)> GetPlayerCarryItems()
|
||||
=> PlayerList.Select(x => (x, x.HeldItem));
|
||||
|
||||
private static Dictionary<int, PlayerInfo> _connectionIdToPlayer = new();
|
||||
|
||||
public static IEnumerator ValidatePlayers()
|
||||
{
|
||||
// BUG: this does not work. try using a ping (heartbeat) message to detect whether the player actually exists. if they dont, kick the player.
|
||||
while (true)
|
||||
{
|
||||
if (QSBCore.IsInMultiplayer && QSBCore.IsHost)
|
||||
{
|
||||
_connectionIdToPlayer.Clear();
|
||||
|
||||
var playersToRemove = new List<PlayerInfo>();
|
||||
|
||||
foreach (var player in PlayerList)
|
||||
{
|
||||
var transformSync = player.TransformSync;
|
||||
|
||||
if (transformSync == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - {player.PlayerId}'s TransformSync is null.", MessageType.Error);
|
||||
playersToRemove.Add(player);
|
||||
continue;
|
||||
}
|
||||
|
||||
var networkIdentity = transformSync.netIdentity;
|
||||
|
||||
if (networkIdentity == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - {player.PlayerId}'s TransformSync's NetworkIdentity is null.", MessageType.Error);
|
||||
playersToRemove.Add(player);
|
||||
continue;
|
||||
}
|
||||
|
||||
var connectionToClient = networkIdentity.connectionToClient;
|
||||
|
||||
if (_connectionIdToPlayer.ContainsKey(connectionToClient.connectionId))
|
||||
{
|
||||
// oh god oh fuck
|
||||
DebugLog.ToConsole($"Error - {player.PlayerId}'s connectionToClient.connectionId is already being used?!?", MessageType.Error);
|
||||
playersToRemove.Add(player);
|
||||
continue;
|
||||
}
|
||||
|
||||
_connectionIdToPlayer.Add(connectionToClient.connectionId, player);
|
||||
}
|
||||
|
||||
if (playersToRemove.Count != 0)
|
||||
{
|
||||
DebugLog.DebugWrite($"Removing {playersToRemove.Count} invalid players.", MessageType.Success);
|
||||
|
||||
foreach (var player in playersToRemove)
|
||||
{
|
||||
OnRemovePlayer?.Invoke(player);
|
||||
player.HudMarker?.Remove();
|
||||
PlayerList.Remove(player);
|
||||
DebugLog.DebugWrite($"Remove Invalid Player : {player}", MessageType.Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
yield return new WaitForSecondsRealtime(5);
|
||||
}
|
||||
}
|
||||
}
|
@ -188,8 +188,6 @@ public class QSBCore : ModBehaviour
|
||||
QSBWorldSync.Managers = components.OfType<WorldObjectManager>().ToArray();
|
||||
QSBPatchManager.OnPatchType += OnPatchType;
|
||||
QSBPatchManager.OnUnpatchType += OnUnpatchType;
|
||||
|
||||
StartCoroutine(QSBPlayerManager.ValidatePlayers());
|
||||
}
|
||||
|
||||
private static void OnPatchType(QSBPatchTypes type)
|
||||
|
Loading…
x
Reference in New Issue
Block a user