From fd6367feca067cf5954c6957aca0e0b2f2f14d07 Mon Sep 17 00:00:00 2001 From: jvyden Date: Thu, 4 Nov 2021 15:30:58 -0400 Subject: [PATCH] Fix publishing, default to LBP1 on connect, fix LBP1 not connecting --- ProjectLighthouse.sln.DotSettings | 1 + ProjectLighthouse/Controllers/LoginController.cs | 4 +++- ProjectLighthouse/Controllers/PublishController.cs | 2 +- ProjectLighthouse/Controllers/ScoreController.cs | 9 ++++++--- ProjectLighthouse/Helpers/GameVersionHelper.cs | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ProjectLighthouse.sln.DotSettings b/ProjectLighthouse.sln.DotSettings index 9bfc9063..f914df07 100644 --- a/ProjectLighthouse.sln.DotSettings +++ b/ProjectLighthouse.sln.DotSettings @@ -89,6 +89,7 @@ True True True + True True True True diff --git a/ProjectLighthouse/Controllers/LoginController.cs b/ProjectLighthouse/Controllers/LoginController.cs index d1c61fab..c0e88d38 100644 --- a/ProjectLighthouse/Controllers/LoginController.cs +++ b/ProjectLighthouse/Controllers/LoginController.cs @@ -22,8 +22,10 @@ namespace LBPUnion.ProjectLighthouse.Controllers } [HttpPost] - public async Task Login([FromQuery] string titleId) + public async Task Login([FromQuery] string? titleId) { + titleId ??= ""; + string body = await new StreamReader(this.Request.Body).ReadToEndAsync(); LoginData? loginData; diff --git a/ProjectLighthouse/Controllers/PublishController.cs b/ProjectLighthouse/Controllers/PublishController.cs index bf59ef15..b52a02c7 100644 --- a/ProjectLighthouse/Controllers/PublishController.cs +++ b/ProjectLighthouse/Controllers/PublishController.cs @@ -60,7 +60,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers // User user = await this.database.UserFromRequest(this.Request); (User, Token)? userAndToken = await this.database.UserAndTokenFromRequest(this.Request); - if (userAndToken != null) return this.StatusCode(403, ""); + if (userAndToken == null) return this.StatusCode(403, ""); // ReSharper disable once PossibleInvalidOperationException User user = userAndToken.Value.Item1; diff --git a/ProjectLighthouse/Controllers/ScoreController.cs b/ProjectLighthouse/Controllers/ScoreController.cs index 90a710ee..95445488 100644 --- a/ProjectLighthouse/Controllers/ScoreController.cs +++ b/ProjectLighthouse/Controllers/ScoreController.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -30,7 +31,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers string bodyString = await new StreamReader(this.Request.Body).ReadToEndAsync(); XmlSerializer serializer = new(typeof(Score)); - Score score = (Score)serializer.Deserialize(new StringReader(bodyString)); + Score? score = (Score?)serializer.Deserialize(new StringReader(bodyString)); if (score == null) return this.BadRequest(); score.SlotId = id; @@ -58,7 +59,9 @@ namespace LBPUnion.ProjectLighthouse.Controllers public async Task TopScores(int slotId, int type, [FromQuery] int pageStart, [FromQuery] int pageSize) { // Get username - User user = await this.database.UserFromRequest(this.Request); + User? user = await this.database.UserFromRequest(this.Request); + + if (user == null) return this.StatusCode(403, ""); // This is hella ugly but it technically assigns the proper rank to a score // var needed for Anonymous type returned from SELECT @@ -67,7 +70,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers .ToList() .Select ( - (Score s, int rank) => new + (s, rank) => new { Score = s, Rank = rank + 1, diff --git a/ProjectLighthouse/Helpers/GameVersionHelper.cs b/ProjectLighthouse/Helpers/GameVersionHelper.cs index 12ec15b0..a44721d4 100644 --- a/ProjectLighthouse/Helpers/GameVersionHelper.cs +++ b/ProjectLighthouse/Helpers/GameVersionHelper.cs @@ -82,7 +82,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers if (LittleBigPlanet2TitleIds.Contains(titleId)) return GameVersion.LittleBigPlanet2; if (LittleBigPlanet3TitleIds.Contains(titleId)) return GameVersion.LittleBigPlanet3; - return GameVersion.Unknown; + return GameVersion.LittleBigPlanet1; } } } \ No newline at end of file