Skip to content

Commit

Permalink
Merge pull request #607 from misternebula/dev
Browse files Browse the repository at this point in the history
0.26.3
  • Loading branch information
misternebula authored Mar 9, 2023
2 parents b948f81 + 8864157 commit 390a3a0
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 49 deletions.
Binary file modified QSB/AssetBundles/qsb_network
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ namespace QSB.EchoesOfTheEye.RaftSync.TransformSync;
public class RaftTransformSync : UnsectoredRigidbodySync, ILinkedNetworkBehaviour
{
private bool ShouldMovePlayer =>
(
Locator.GetPlayerController().GetGroundBody() == null ||
Locator.GetPlayerController().GetGroundBody() == AttachedRigidbody
) &&
Vector3.Distance(AttachedTransform.position, Locator.GetPlayerBody().GetPosition()) < 10;
protected override bool UseInterpolation => !ShouldMovePlayer;

Expand Down
6 changes: 5 additions & 1 deletion QSB/Menus/MenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,12 @@ private static void SetButtonActive(GameObject button, bool active)
return;
}

var titleAnimationController = QSBWorldSync.GetUnityObject<TitleScreenManager>()._gfxController;

var activeAlpha = titleAnimationController.IsTitleAnimationComplete() ? 1 : 0;

button.SetActive(active);
button.GetComponent<CanvasGroup>().alpha = active ? 1 : 0;
button.GetComponent<CanvasGroup>().alpha = active ? activeAlpha : 0;
}

private void InitPauseMenus()
Expand Down
10 changes: 9 additions & 1 deletion QSB/Messaging/QSBMessageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ private static void OnServerReceive(QSBMessage msg)
}
else
{
msg.To.GetNetworkConnection().Send<Wrapper>(msg);
var connection = msg.To.GetNetworkConnection();

if (connection == default)
{
DebugLog.ToConsole($"Warning - Tried to handle message from disconnected(?) player.", MessageType.Warning);
return;
}

connection.Send<Wrapper>(msg);
}
}

Expand Down
4 changes: 2 additions & 2 deletions QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
namespace QSB.QuantumSync.WorldObjects;

/// <summary>
/// TODO: just use OnSectorOccupantsUpdated instead of this shape bullshit
///
/// TODO: make it part of the ad-hoc owner interface
///
/// TODO: make it so only players in the sector (which sector?) are checked for visibility
/// </summary>
internal abstract class QSBQuantumObject<T> : WorldObject<T>, IQSBQuantumObject
where T : QuantumObject
Expand Down
9 changes: 4 additions & 5 deletions QSB/ShipSync/TransformSync/ShipTransformSync.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using QSB.HUD;
using QSB.Player;
using QSB.Syncs.Sectored.Rigidbodies;
using QSB.Utility;
using UnityEngine;
Expand Down Expand Up @@ -124,10 +126,7 @@ private static void SetVelocity(OWRigidbody @this, Vector3 newVelocity)


private bool ShouldMovePlayer =>
(
Locator.GetPlayerController().GetGroundBody() == null ||
Locator.GetPlayerController().GetGroundBody() == AttachedRigidbody
) &&
Vector3.Distance(AttachedTransform.position, Locator.GetPlayerBody().GetPosition()) < 100;
PlayerState.InZeroG()
&& Vector3.Distance(AttachedTransform.position, Locator.GetPlayerBody().GetPosition()) < 100;
protected override bool UseInterpolation => !ShouldMovePlayer;
}
2 changes: 1 addition & 1 deletion QSB/TimeSync/Messages/ServerTimeMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ public override void Deserialize(NetworkReader reader)
}

public override void OnReceiveRemote()
=> WakeUpSync.LocalInstance.OnClientReceiveMessage(ServerTime, LoopCount, SecondsRemaining);
=> WakeUpSync.LocalInstance?.OnClientReceiveMessage(ServerTime, LoopCount, SecondsRemaining);
}
8 changes: 0 additions & 8 deletions QSB/TimeSync/StopMeditation.cs

This file was deleted.

23 changes: 7 additions & 16 deletions QSB/TimeSync/WakeUpSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

namespace QSB.TimeSync;

/// <summary>
/// BUG: this runs on remote players = BAD! can we move this off of network player?
/// </summary>
[UsedInUnityProject]
public class WakeUpSync : NetworkBehaviour
public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
{
public static WakeUpSync LocalInstance { get; private set; }

Expand All @@ -41,8 +37,6 @@ public enum State { NotLoaded, Loaded, FastForwarding, Pausing }
private int _serverLoopCount;
private bool _hasWokenUp;

public override void OnStartLocalPlayer() => LocalInstance = this;

public void OnDisconnect()
{
OWTime.SetTimeScale(1f);
Expand All @@ -60,11 +54,6 @@ public void OnDisconnect()

public void Start()
{
if (!isLocalPlayer)
{
return;
}

if (QSBSceneManager.IsInUniverse)
{
Init();
Expand Down Expand Up @@ -108,10 +97,12 @@ private void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isInUniverse
_hasWokenUp = true;
}

LocalInstance = this;
Init();
}
else
{
LocalInstance = null;
CurrentState = State.NotLoaded;
}
}
Expand All @@ -120,7 +111,7 @@ private void Init()
{
new RequestStateResyncMessage().Send();
CurrentState = State.Loaded;
if (isServer)
if (QSBCore.IsHost)
{
SendServerTime();
}
Expand Down Expand Up @@ -162,7 +153,7 @@ private void WakeUpOrSleep()
return;
}

if (PlayerData.LoadLoopCount() != _serverLoopCount && !isServer)
if (PlayerData.LoadLoopCount() != _serverLoopCount && !QSBCore.IsHost)
{
DebugLog.ToConsole($"Warning - ServerLoopCount is not the same as local loop count! local:{PlayerData.LoadLoopCount()} server:{_serverLoopCount}");
return;
Expand Down Expand Up @@ -268,11 +259,11 @@ private void WakeUp()

public void Update()
{
if (isServer)
if (QSBCore.IsHost)
{
UpdateServer();
}
else if (isLocalPlayer && !QSBCore.DebugSettings.AvoidTimeSync)
else if (NetworkClient.active && QSBSceneManager.IsInUniverse && !QSBCore.DebugSettings.AvoidTimeSync)
{
UpdateClient();
}
Expand Down
9 changes: 5 additions & 4 deletions QSB/WorldSync/QSBWorldSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class QSBWorldSync
public static WorldObjectManager[] Managers;

private static readonly Dictionary<string, List<IWorldObject>> _managerToBuiltObjects = new();
public static readonly Dictionary<string, string> ManagerHashes = new();
public static readonly Dictionary<string, (string hash, int count)> ManagerHashes = new();

/// <summary>
/// Set when all WorldObjectManagers have called Init() on all their objects (AKA all the objects are created)
Expand Down Expand Up @@ -91,15 +91,16 @@ await manager.Try("building world objects", async () =>
foreach (var item in _managerToBuiltObjects)
{
var worldObjects = item.Value;
var hash = worldObjects.Select(x => x.GetType().Name).GetMD5Hash();
ManagerHashes[item.Key] = hash;
var objects = worldObjects.Select(x => x.GetType().Name);
var hash = objects.GetMD5Hash();
ManagerHashes[item.Key] = (hash, objects.Count());
}

if (!QSBCore.IsHost)
{
foreach (var item in ManagerHashes)
{
new WorldObjectsHashMessage(item.Key, item.Value).Send();
new WorldObjectsHashMessage(item.Key, item.Value.hash, item.Value.count).Send();
}

new RequestLinksMessage().Send();
Expand Down
12 changes: 6 additions & 6 deletions QSB/WorldSync/WorldObjectsHashMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ namespace QSB.WorldSync;
/// <summary>
/// sends QSBWorldSync.WorldObjectsHash to the server for sanity checking
/// </summary>
internal class WorldObjectsHashMessage : QSBMessage<(string managerName, string hash)>
internal class WorldObjectsHashMessage : QSBMessage<(string managerName, string hash, int count)>
{
public WorldObjectsHashMessage(string managerName, string hash) : base((managerName, hash)) => To = 0;
public WorldObjectsHashMessage(string managerName, string hash, int count) : base((managerName, hash, count)) => To = 0;

public override void OnReceiveRemote()
{
Delay.RunWhen(() => QSBWorldSync.AllObjectsAdded, () =>
{
var serverHash = QSBWorldSync.ManagerHashes[Data.managerName];
var (hash, count) = QSBWorldSync.ManagerHashes[Data.managerName];
if (serverHash != Data.hash)
if (hash != Data.hash)
{
// oh fuck oh no oh god
DebugLog.ToConsole($"Kicking {From} because their WorldObjects hash for {Data.managerName} is wrong. (server:{serverHash}, client:{Data.hash})", MessageType.Error);
new PlayerKickMessage(From, $"WorldObject hash error for {Data.managerName}. (Server:{serverHash}, Client:{Data.hash})").Send();
DebugLog.ToConsole($"Kicking {From} because their WorldObjects hash for {Data.managerName} is wrong. (Server:{hash} count:{count}, Client:{Data.hash} count:{Data.count})", MessageType.Error);
new PlayerKickMessage(From, $"WorldObject hash error for {Data.managerName}. (Server:{hash} count:{count}, Client:{Data.hash}, count:{Data.count})").Send();
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion QSB/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.2",
"version": "0.26.3",
"owmlVersion": "2.9.0",
"dependencies": [ "_nebula.MenuFramework", "JohnCorby.VanillaFix" ],
"pathsToPreserve": [ "debugsettings.json" ],
Expand Down

0 comments on commit 390a3a0

Please sign in to comment.