Skip to content

Commit

Permalink
move worldsync messages to folder
Browse files Browse the repository at this point in the history
  • Loading branch information
misternebula committed Feb 13, 2024
1 parent bea9764 commit b04e287
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 62 deletions.
2 changes: 1 addition & 1 deletion QSB/Animation/Player/AnimationSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using QSB.Messaging;
using QSB.Player;
using QSB.Utility;
using QSB.WorldSync;
using QSB.WorldSync.Messages;
using System;
using UnityEngine;

Expand Down
2 changes: 1 addition & 1 deletion QSB/EchoesOfTheEye/LightSensorSync/QSBPlayerLightSensor.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 1 addition & 0 deletions QSB/Utility/QSBNetworkBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Mirror;
using QSB.WorldSync;
using QSB.WorldSync.Messages;
using System;

namespace QSB.Utility;
Expand Down
31 changes: 31 additions & 0 deletions QSB/WorldSync/Messages/RequestInitialStatesMessage.cs
Original file line number Diff line number Diff line change
@@ -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;
}
29 changes: 29 additions & 0 deletions QSB/WorldSync/Messages/WorldObjectsHashMessage.cs
Original file line number Diff line number Diff line change
@@ -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();
}
});
}
}
1 change: 1 addition & 0 deletions QSB/WorldSync/QSBWorldSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using QSB.TriggerSync.WorldObjects;
using QSB.Utility;
using QSB.Utility.LinkedWorldObject;
using QSB.WorldSync.Messages;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down
31 changes: 0 additions & 31 deletions QSB/WorldSync/RequestInitialStatesMessage.cs

This file was deleted.

29 changes: 0 additions & 29 deletions QSB/WorldSync/WorldObjectsHashMessage.cs

This file was deleted.

0 comments on commit b04e287

Please sign in to comment.