more fixey fixey

This commit is contained in:
Mister_Nebula 2020-08-18 13:56:07 +01:00
parent 91fc9b12ca
commit f5bb68553a
6 changed files with 105 additions and 20 deletions

View File

@ -116,6 +116,7 @@ namespace QSB
public override void OnClientConnect(NetworkConnection connection) // Called on the client when connecting to a server public override void OnClientConnect(NetworkConnection connection) // Called on the client when connecting to a server
{ {
DebugLog.ToConsole("Connecting to server...", OWML.Common.MessageType.Info);
base.OnClientConnect(connection); base.OnClientConnect(connection);
gameObject.AddComponent<SectorSync>(); gameObject.AddComponent<SectorSync>();
@ -142,13 +143,25 @@ namespace QSB
public override void OnStopClient() // Called on the client when closing connection public override void OnStopClient() // Called on the client when closing connection
{ {
DebugLog.ToConsole("Disconnecting from server...", OWML.Common.MessageType.Info);
Destroy(GetComponent<SectorSync>()); Destroy(GetComponent<SectorSync>());
Destroy(GetComponent<RespawnOnDeath>()); Destroy(GetComponent<RespawnOnDeath>());
Destroy(GetComponent<PreventShipDestruction>()); Destroy(GetComponent<PreventShipDestruction>());
EventList.Reset(); EventList.Reset();
if (IsClientConnected()) if (IsClientConnected())
{ {
PlayerTransformSync.LocalInstance.gameObject.GetComponent<AnimationSync>().Reset(); PlayerTransformSync.LocalInstance?.gameObject.GetComponent<AnimationSync>().Reset();
}
foreach (var player in PlayerRegistry.PlayerList)
{
if (player.HudMarker != null)
{
Destroy(player.HudMarker.transform.parent.gameObject);
}
}
foreach (var connection in NetworkServer.connections)
{
CleanupConnection(connection);
} }
_canEditName = true; _canEditName = true;
} }
@ -176,20 +189,6 @@ namespace QSB
base.OnStopServer(); base.OnStopServer();
} }
public override void OnClientDisconnect(NetworkConnection conn)
{
DebugLog.ToConsole("Disconnected from server.", OWML.Common.MessageType.Info);
foreach (var player in PlayerRegistry.PlayerList)
{
Destroy(player.HudMarker.transform.parent.gameObject);
}
foreach (var connection in NetworkServer.connections.Where(x => x != conn))
{
CleanupConnection(connection);
}
base.OnClientDisconnect(conn);
}
private void CleanupConnection(NetworkConnection connection) private void CleanupConnection(NetworkConnection connection)
{ {
var playerId = connection.playerControllers[0].gameObject.GetComponent<PlayerTransformSync>().netId.Value; var playerId = connection.playerControllers[0].gameObject.GetComponent<PlayerTransformSync>().netId.Value;

View File

@ -49,6 +49,12 @@ namespace QSB.TimeSync
GlobalMessenger.AddListener(EventNames.RestartTimeLoop, OnLoopStart); GlobalMessenger.AddListener(EventNames.RestartTimeLoop, OnLoopStart);
} }
private void OnDestroy()
{
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
GlobalMessenger.RemoveListener(EventNames.RestartTimeLoop, OnLoopStart);
}
private void OnSceneLoaded(OWScene scene, bool isInUniverse) private void OnSceneLoaded(OWScene scene, bool isInUniverse)
{ {
if (isInUniverse) if (isInUniverse)

View File

@ -1,5 +1,7 @@
using QSB.Events; using QSB.Events;
using QSB.Tools; using QSB.Tools;
using QSB.Utility;
using System;
using UnityEngine; using UnityEngine;
namespace QSB.TransformSync namespace QSB.TransformSync
@ -13,7 +15,25 @@ namespace QSB.TransformSync
LocalInstance = this; LocalInstance = this;
} }
public override uint PlayerId => netId.Value - 2; public override uint PlayerId
{
get
{
uint id = uint.MaxValue;
try
{
id = netId.Value - 2;
}
catch
{
DebugLog.ToConsole($"Error while geting netId of {GetType().Name}! " +
$"{Environment.NewLine} - Did you destroy the TransformSync without destroying the {GetType().Name}?" +
$"{Environment.NewLine} - Did a destroyed TransformSync/{GetType().Name} still have an active action/event listener?" +
$"{Environment.NewLine} If you are a user seeing this, please report this error.", OWML.Common.MessageType.Error);
}
return id;
}
}
protected override Transform InitLocalTransform() protected override Transform InitLocalTransform()
{ {

View File

@ -1,4 +1,6 @@
using QSB.Tools; using QSB.Tools;
using QSB.Utility;
using System;
using UnityEngine; using UnityEngine;
namespace QSB.TransformSync namespace QSB.TransformSync
@ -14,7 +16,25 @@ namespace QSB.TransformSync
LocalInstance = this; LocalInstance = this;
} }
public override uint PlayerId => netId.Value - 3; public override uint PlayerId
{
get
{
uint id = uint.MaxValue;
try
{
id = netId.Value - 3;
}
catch
{
DebugLog.ToConsole($"Error while geting netId of {GetType().Name}! " +
$"{Environment.NewLine} - Did you destroy the TransformSync without destroying the {GetType().Name}?" +
$"{Environment.NewLine} - Did a destroyed TransformSync/{GetType().Name} still have an active action/event listener?" +
$"{Environment.NewLine} If you are a user seeing this, please report this error.", OWML.Common.MessageType.Error);
}
return id;
}
}
private Transform GetProbe() private Transform GetProbe()
{ {

View File

@ -1,4 +1,6 @@
using QSB.Animation; using QSB.Animation;
using QSB.Utility;
using System;
using UnityEngine; using UnityEngine;
namespace QSB.TransformSync namespace QSB.TransformSync
@ -17,7 +19,25 @@ namespace QSB.TransformSync
LocalInstance = this; LocalInstance = this;
} }
public override uint PlayerId => netId.Value - 0; public override uint PlayerId
{
get
{
uint id = uint.MaxValue;
try
{
id = netId.Value - 0;
}
catch
{
DebugLog.ToConsole($"Error while geting netId of {GetType().Name}! " +
$"{Environment.NewLine} - Did you destroy the TransformSync without destroying the {GetType().Name}?" +
$"{Environment.NewLine} - Did a destroyed TransformSync/{GetType().Name} still have an active action/event listener?" +
$"{Environment.NewLine} If you are a user seeing this, please report this error.", OWML.Common.MessageType.Error);
}
return id;
}
}
private Transform GetPlayerModel() private Transform GetPlayerModel()
{ {

View File

@ -1,4 +1,6 @@
using UnityEngine; using QSB.Utility;
using System;
using UnityEngine;
namespace QSB.TransformSync namespace QSB.TransformSync
{ {
@ -11,7 +13,25 @@ namespace QSB.TransformSync
LocalInstance = this; LocalInstance = this;
} }
public override uint PlayerId => netId.Value - 1; public override uint PlayerId
{
get
{
uint id = uint.MaxValue;
try
{
id = netId.Value - 1;
}
catch
{
DebugLog.ToConsole($"Error while geting netId of {GetType().Name}! " +
$"{Environment.NewLine} - Did you destroy the TransformSync without destroying the {GetType().Name}?" +
$"{Environment.NewLine} - Did a destroyed TransformSync/{GetType().Name} still have an active action/event listener?" +
$"{Environment.NewLine} If you are a user seeing this, please report this error.", OWML.Common.MessageType.Error);
}
return id;
}
}
private Transform GetShipModel() private Transform GetShipModel()
{ {