diff --git a/ProjectLighthouse/Controllers/MatchController.cs b/ProjectLighthouse/Controllers/MatchController.cs index a865fa9e..ba19cb4a 100644 --- a/ProjectLighthouse/Controllers/MatchController.cs +++ b/ProjectLighthouse/Controllers/MatchController.cs @@ -6,6 +6,7 @@ using System.Text.Json; using System.Threading.Tasks; using Kettu; using LBPUnion.ProjectLighthouse.Helpers; +using LBPUnion.ProjectLighthouse.Helpers.Extensions; using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Match; @@ -53,8 +54,10 @@ namespace LBPUnion.ProjectLighthouse.Controllers } catch(Exception e) { - Logger.Log("Exception while parsing MatchData: " + e, LoggerLevelMatch.Instance); - Logger.Log("Data: " + bodyString, LoggerLevelMatch.Instance); + Logger.Log("Exception while parsing matchData: ", LoggerLevelMatch.Instance); + string[] lines = e.ToDetailedException().Split("\n"); + foreach (string line in lines) Logger.Log(line, LoggerLevelMatch.Instance); + Logger.Log("Associated matchData: " + bodyString, LoggerLevelMatch.Instance); return this.BadRequest(); } @@ -62,7 +65,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers if (matchData == null) { Logger.Log("Could not parse match data: matchData is null", LoggerLevelMatch.Instance); - Logger.Log("Data: " + bodyString, LoggerLevelMatch.Instance); + Logger.Log("Associated matchData: " + bodyString, LoggerLevelMatch.Instance); return this.BadRequest(); } diff --git a/ProjectLighthouse/Helpers/MatchHelper.cs b/ProjectLighthouse/Helpers/MatchHelper.cs index c6379435..5afa10e6 100644 --- a/ProjectLighthouse/Helpers/MatchHelper.cs +++ b/ProjectLighthouse/Helpers/MatchHelper.cs @@ -36,6 +36,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers return recentlyDivedIn.Contains(otherUserId); } + // This is the function used to show people how laughably awful LBP's protocol is. Beware. public static IMatchData? Deserialize(string data) { string matchType = ""; @@ -49,10 +50,13 @@ namespace LBPUnion.ProjectLighthouse.Helpers i++; } - string matchData = $"{{{string.Concat(data.Skip(matchType.Length + 3).SkipLast(2))}}}"; + string matchData = $"{{{string.Concat(data.Skip(matchType.Length + 3).SkipLast(2))}}}"; // unfuck formatting so we can parse it as json // JSON does not like the hex value that location comes in (0x7f000001) so, convert it to int matchData = Regex.Replace(matchData, @"0x[a-fA-F0-9]{8}", m => Convert.ToInt32(m.Value, 16).ToString()); + // oh, but it gets better than that! LBP also likes to send hex values with an uneven amount of digits (0xa000064, 7 digits). in any case, we handle it here: + matchData = Regex.Replace(matchData, @"0x[a-fA-F0-9]{7}", m => Convert.ToInt32(m.Value, 16).ToString()); + // i'm actually crying about it. return Deserialize(matchType, matchData); }