move worldsync messages to folder

This commit is contained in:
_nebula 2024-02-13 13:06:43 +00:00
parent bea9764f7d
commit b04e28752e
8 changed files with 64 additions and 62 deletions

View File

@ -6,7 +6,7 @@ using QSB.Animation.Player.Thrusters;
using QSB.Messaging;
using QSB.Player;
using QSB.Utility;
using QSB.WorldSync;
using QSB.WorldSync.Messages;
using System;
using UnityEngine;

View File

@ -1,7 +1,7 @@
using QSB.EchoesOfTheEye.LightSensorSync.Messages;
using QSB.Messaging;
using QSB.Player;
using QSB.WorldSync;
using QSB.WorldSync.Messages;
using System.Linq;
using UnityEngine;

View File

@ -1,5 +1,6 @@
using Mirror;
using QSB.WorldSync;
using QSB.WorldSync.Messages;
using System;
namespace QSB.Utility;

View File

@ -0,0 +1,31 @@
using QSB.Messaging;
using QSB.Utility;
using System;
namespace QSB.WorldSync.Messages;
/// <summary>
/// sent to the host to get initial object states.
/// <para/>
/// world objects will be ready on both sides at this point
/// </summary>
public class RequestInitialStatesMessage : QSBMessage
{
public RequestInitialStatesMessage() => To = 0;
public override void OnReceiveRemote() =>
Delay.RunWhen(() => QSBWorldSync.AllObjectsReady,
() => SendInitialStates(From));
private static void SendInitialStates(uint to)
{
SendInitialState?.SafeInvoke(to);
DebugLog.DebugWrite($"sent initial states to {to}");
}
/// <summary>
/// called on the host.
/// use this to send initial states to whoever is asking for it.
/// </summary>
public static event Action<uint> SendInitialState;
}

View File

@ -0,0 +1,29 @@
using OWML.Common;
using QSB.Messaging;
using QSB.Player.Messages;
using QSB.Utility;
namespace QSB.WorldSync.Messages;
/// <summary>
/// sends QSBWorldSync.WorldObjectsHash to the server for sanity checking
/// </summary>
public class WorldObjectsHashMessage : QSBMessage<(string managerName, string hash, int count)>
{
public WorldObjectsHashMessage(string managerName, string hash, int count) : base((managerName, hash, count)) => To = 0;
public override void OnReceiveRemote()
{
Delay.RunWhen(() => QSBWorldSync.AllObjectsAdded, () =>
{
var (hash, count) = QSBWorldSync.ManagerHashes[Data.managerName];
if (hash != Data.hash)
{
// oh fuck oh no oh god
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();
}
});
}
}

View File

@ -9,6 +9,7 @@ using QSB.Player.TransformSync;
using QSB.TriggerSync.WorldObjects;
using QSB.Utility;
using QSB.Utility.LinkedWorldObject;
using QSB.WorldSync.Messages;
using System;
using System.Collections.Generic;
using System.Diagnostics;

View File

@ -1,31 +0,0 @@
using QSB.Messaging;
using QSB.Utility;
using System;
namespace QSB.WorldSync;
/// <summary>
/// sent to the host to get initial object states.
/// <para/>
/// world objects will be ready on both sides at this point
/// </summary>
public class RequestInitialStatesMessage : QSBMessage
{
public RequestInitialStatesMessage() => To = 0;
public override void OnReceiveRemote() =>
Delay.RunWhen(() => QSBWorldSync.AllObjectsReady,
() => SendInitialStates(From));
private static void SendInitialStates(uint to)
{
SendInitialState?.SafeInvoke(to);
DebugLog.DebugWrite($"sent initial states to {to}");
}
/// <summary>
/// called on the host.
/// use this to send initial states to whoever is asking for it.
/// </summary>
public static event Action<uint> SendInitialState;
}

View File

@ -1,29 +0,0 @@
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>
public class WorldObjectsHashMessage : QSBMessage<(string managerName, string hash, int count)>
{
public WorldObjectsHashMessage(string managerName, string hash, int count) : base((managerName, hash, count)) => To = 0;
public override void OnReceiveRemote()
{
Delay.RunWhen(() => QSBWorldSync.AllObjectsAdded, () =>
{
var (hash, count) = QSBWorldSync.ManagerHashes[Data.managerName];
if (hash != Data.hash)
{
// oh fuck oh no oh god
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();
}
});
}
}