quantum-space-buddies/QSB/WorldSync/WorldObjectsHashMessage.cs

30 lines
1.0 KiB
C#
Raw Normal View History

2022-10-08 20:18:22 +01:00
using OWML.Common;
using QSB.Messaging;
using QSB.Player.Messages;
using QSB.Utility;
namespace QSB.WorldSync;
2022-10-08 14:27:57 -07:00
/// <summary>
/// sends QSBWorldSync.WorldObjectsHash to the server for sanity checking
/// </summary>
2023-03-08 21:02:00 +00:00
internal class WorldObjectsHashMessage : QSBMessage<(string managerName, string hash, int count)>
2022-10-08 20:18:22 +01:00
{
2023-03-08 21:02:00 +00:00
public WorldObjectsHashMessage(string managerName, string hash, int count) : base((managerName, hash, count)) => To = 0;
2022-10-08 20:18:22 +01:00
public override void OnReceiveRemote()
{
Delay.RunWhen(() => QSBWorldSync.AllObjectsAdded, () =>
2022-10-08 20:18:22 +01:00
{
2023-03-08 21:02:00 +00:00
var (hash, count) = QSBWorldSync.ManagerHashes[Data.managerName];
2022-12-11 13:59:04 +00:00
2023-03-08 21:02:00 +00:00
if (hash != Data.hash)
2022-12-11 13:59:04 +00:00
{
// oh fuck oh no oh god
2023-03-08 21:02:00 +00:00
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();
2022-12-11 13:59:04 +00:00
}
});
2022-10-08 20:18:22 +01:00
}
}