-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb6b811
commit 6e04266
Showing
6 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using OWML.Common; | ||
using QSB.Utility; | ||
using QSB.Player.Messages; | ||
using QSB.Messaging; | ||
using QSB.Utility.Deterministic; | ||
|
||
namespace QSB.WorldSync; | ||
|
||
public class HashErrorAnalysis | ||
{ | ||
public static Dictionary<string, HashErrorAnalysis> Instances = new(); | ||
|
||
private readonly string _managerName; | ||
|
||
private readonly List<(string hash, string path)> _paths = new(); | ||
|
||
public HashErrorAnalysis(string managerName) => _managerName = managerName; | ||
|
||
public void OnReceiveMessage(string deterministicPath) => _paths.Add((deterministicPath.GetMD5Hash(), deterministicPath)); | ||
|
||
public void AllDataSent(uint from) | ||
{ | ||
var serverObjects = QSBWorldSync.GetWorldObjectsFromManager(_managerName); | ||
|
||
var serverDetPaths = serverObjects.Select(x => x.AttachedObject.DeterministicPath()); | ||
var serverDetPathDict = serverDetPaths.Select(path => (path.GetMD5Hash(), path)).ToList<(string hash, string path)>(); | ||
|
||
var serverDoesNotHave = new List<string>(); | ||
var clientDoesNotHave = new List<string>(); | ||
|
||
foreach (var (hash, path) in serverDetPathDict) | ||
{ | ||
if (!_paths.Any(x => x.hash == hash)) | ||
{ | ||
// client does not contain something from the server | ||
clientDoesNotHave.Add(path); | ||
} | ||
} | ||
|
||
foreach (var (hash, path) in _paths) | ||
{ | ||
if (!serverDetPathDict.Any(x => x.hash == hash)) | ||
{ | ||
// client does not contain something from the server | ||
serverDoesNotHave.Add(path); | ||
} | ||
} | ||
|
||
DebugLog.ToConsole($"{_managerName} - Client is missing :", MessageType.Error); | ||
foreach (var item in clientDoesNotHave) | ||
{ | ||
DebugLog.ToConsole($"- {item}", MessageType.Error); | ||
} | ||
|
||
DebugLog.ToConsole($"{_managerName} - Client has extra :", MessageType.Error); | ||
foreach (var item in serverDoesNotHave) | ||
{ | ||
DebugLog.ToConsole($"- {item}", MessageType.Error); | ||
} | ||
Instances.Remove(_managerName); | ||
|
||
new PlayerKickMessage(from, $"WorldObject hash error for {_managerName}").Send(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using QSB.Messaging; | ||
|
||
namespace QSB.WorldSync.Messages; | ||
|
||
public class DataDumpFinishedMessage : QSBMessage<string> | ||
{ | ||
public DataDumpFinishedMessage(string managerName) : base(managerName) => To = 0; | ||
|
||
public override void OnReceiveRemote() => HashErrorAnalysis.Instances[Data].AllDataSent(From); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using QSB.Messaging; | ||
|
||
namespace QSB.WorldSync.Messages; | ||
|
||
internal class HashCheckSucceededMessage : QSBMessage | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using OWML.Common; | ||
using QSB.Messaging; | ||
using QSB.Utility; | ||
|
||
namespace QSB.WorldSync.Messages; | ||
|
||
/// <summary> | ||
/// Sent to clients from the server when a client has an incorrect WorldObject hash. | ||
/// </summary> | ||
internal class RequestHashBreakdownMessage : QSBMessage<string> | ||
{ | ||
public RequestHashBreakdownMessage(string managerName) : base(managerName) { } | ||
|
||
public override void OnReceiveRemote() | ||
{ | ||
DebugLog.ToConsole($"Received RequestHashBreakdownMessage for {Data}", MessageType.Error); | ||
var objects = QSBWorldSync.GetWorldObjectsFromManager(Data); | ||
|
||
foreach (var worldObject in objects) | ||
{ | ||
new WorldObjectInfoMessage(worldObject, Data).Send(); | ||
} | ||
|
||
DebugLog.ToConsole("- Sending finished message.", MessageType.Error); | ||
new DataDumpFinishedMessage(Data).Send(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using QSB.Messaging; | ||
using QSB.Utility.Deterministic; | ||
|
||
namespace QSB.WorldSync.Messages; | ||
|
||
/// <summary> | ||
/// Sent by clients to the server after receiving a RequestHashBreakdown message. | ||
/// </summary> | ||
public class WorldObjectInfoMessage : QSBMessage<(string fullPath, string managerName)> | ||
{ | ||
public WorldObjectInfoMessage(IWorldObject obj, string managerName) : base((obj.AttachedObject.DeterministicPath(), managerName)) => To = 0; | ||
|
||
public override void OnReceiveRemote() | ||
{ | ||
HashErrorAnalysis.Instances[Data.managerName].OnReceiveMessage(Data.fullPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters