Merge branch 'dev' into nh-stuff

This commit is contained in:
JohnCorby 2022-10-08 16:52:05 -07:00
commit ff5c25ddb4
11 changed files with 65 additions and 10 deletions

View File

@ -32,13 +32,16 @@ public class QSBEclipseCodeController : WorldObject<EclipseCodeController4>
}
}
private void OnPlayerLeave(PlayerInfo obj)
private void OnPlayerLeave(PlayerInfo player)
{
if (!QSBCore.IsHost)
{
return;
}
this.SendMessage(new UseControllerMessage(false));
if (PlayerInControl == player)
{
this.SendMessage(new UseControllerMessage(false));
}
}
public void SetUser(uint user)

View File

@ -5,5 +5,5 @@ namespace QSB.EchoesOfTheEye.RaftSync.Messages;
public class RaftDockOnPressInteractMessage : QSBWorldObjectMessage<QSBRaftDock>
{
public override void OnReceiveRemote() => WorldObject.OnPressInteract();
public override void OnReceiveRemote() => WorldObject.AttachedObject.OnPressInteract();
}

View File

@ -6,6 +6,4 @@ namespace QSB.EchoesOfTheEye.RaftSync.WorldObjects;
public class QSBRaftDock : WorldObject<RaftDock>, IQSBDropTarget
{
IItemDropTarget IQSBDropTarget.AttachedObject => AttachedObject;
public void OnPressInteract() => AttachedObject.OnPressInteract();
}

View File

@ -17,13 +17,16 @@ public class QSBSlideProjector : WorldObject<SlideProjector>
public override void OnRemoval() =>
QSBPlayerManager.OnRemovePlayer -= OnPlayerLeave;
private void OnPlayerLeave(PlayerInfo obj)
private void OnPlayerLeave(PlayerInfo player)
{
if (!QSBCore.IsHost)
{
return;
}
this.SendMessage(new UseSlideProjectorMessage(false));
if (_user == player.PlayerId)
{
this.SendMessage(new UseSlideProjectorMessage(false));
}
}
public override void SendInitialState(uint to) =>

View File

@ -42,7 +42,7 @@ internal class MenuManager : MonoBehaviour, IAddComponentOnStart
private const int _titleButtonIndex = 2;
private float _connectPopupOpenTime;
private const string UpdateChangelog = "QSB Version 0.21.1\r\nFixed gamepass not working, and fixed a small bug with light sensors.";
private const string UpdateChangelog = "QSB Version 0.22.0\r\nFixed lots of bugs, and added lots of SFX and VFX stuff.";
private Action<bool> PopupClose;

View File

@ -369,7 +369,7 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
}
// stop dragging for the orbs this player was dragging
// why tf is this here instead of QSBOrb.OnPlayerLeave?
// i THINK this is here because orb authority is in network behavior, which may not work properly in OnPlayerLeave
foreach (var qsbOrb in QSBWorldSync.GetWorldObjects<QSBOrb>())
{
if (qsbOrb.NetworkBehaviour == null)

View File

@ -11,6 +11,7 @@ using System.Threading;
namespace QSB.Tools.ProbeLauncherTool.WorldObjects;
// TODO John - i think this can be simplified, i might be able to remove the variable syncer
// TODO: on player leave? idk if this will be needed if i ever simplify this
public class QSBStationaryProbeLauncher : QSBProbeLauncher, ILinkedWorldObject<StationaryProbeLauncherVariableSyncer>
{
private uint _currentUser = uint.MaxValue;

View File

@ -5,6 +5,8 @@ using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
#pragma warning disable CS0618
namespace QSB.Utility;
public static class DebugLog

View File

@ -214,5 +214,18 @@ public static class Extensions
}
}
// Adapted from https://stackoverflow.com/a/30758270
public static int GetSequenceHash(this IEnumerable<string> list)
{
const int seed = 487;
const int modifier = 31;
unchecked
{
return list.Aggregate(seed, (current, item) =>
(current * modifier) + item.GetStableHashCode());
}
}
#endregion
}

View File

@ -20,6 +20,7 @@ namespace QSB.WorldSync;
public static class QSBWorldSync
{
public static WorldObjectManager[] Managers;
public static int WorldObjectsHash { get; private set; }
/// <summary>
/// Set when all WorldObjectManagers have called Init() on all their objects (AKA all the objects are created)
@ -82,8 +83,12 @@ public static class QSBWorldSync
AllObjectsAdded = true;
DebugLog.DebugWrite("World Objects added.", MessageType.Success);
WorldObjectsHash = WorldObjects.Select(x => x.GetType().Name).GetSequenceHash();
DebugLog.DebugWrite($"WorldObject hash is {WorldObjectsHash}");
if (!QSBCore.IsHost)
{
new WorldObjectsHashMessage().Send();
new RequestLinksMessage().Send();
}
@ -248,7 +253,7 @@ public static class QSBWorldSync
if (WorldObjects[objectId] is not TWorldObject worldObject)
{
DebugLog.ToConsole($"Error - {typeof(TWorldObject).Name} id {objectId} is actually {WorldObjects[objectId].GetType().Name}.", MessageType.Error);
DebugLog.ToConsole($"Error - WorldObject id {objectId} is {WorldObjects[objectId].GetType().Name}, expected {typeof(TWorldObject).Name}.", MessageType.Error);
return default;
}

View File

@ -0,0 +1,30 @@
using OWML.Common;
using QSB.Messaging;
using QSB.Player.Messages;
using QSB.Utility;
namespace QSB.WorldSync;
/// <summary>
/// sends QSBWorldSync.WorldObjectsHash to the server for sanity checking
/// </summary>
internal class WorldObjectsHashMessage : QSBMessage<int>
{
public WorldObjectsHashMessage() : base(QSBWorldSync.WorldObjectsHash) => To = 0;
public override void OnReceiveRemote()
{
var serverHash = QSBWorldSync.WorldObjectsHash;
if (serverHash != Data)
{
// oh fuck oh no oh god
DebugLog.ToConsole($"Kicking {From} because their WorldObjects hash is wrong. (server:{serverHash}, client:{Data})", MessageType.Error);
new PlayerKickMessage(From, $"WorldObject hash error. (Server:{serverHash}, Client:{Data})").Send();
}
else
{
DebugLog.DebugWrite($"WorldObject hash from {From} verified!", MessageType.Success);
}
}
}