mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-01 03:32:38 +00:00
bust them ghosts
This commit is contained in:
parent
bfddd8f8cc
commit
a4b7deb322
66
QSB/Ghostbuster.cs
Normal file
66
QSB/Ghostbuster.cs
Normal file
@ -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<PlayerInfo>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -260,6 +260,8 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
|
||||
|
||||
public override void OnServerAddPlayer(NetworkConnectionToClient connection) // Called on the server when a client joins
|
||||
{
|
||||
connection.Disconnect();
|
||||
|
||||
DebugLog.DebugWrite("OnServerAddPlayer", MessageType.Info);
|
||||
base.OnServerAddPlayer(connection);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user