diff --git a/Refresh.GameServer/Endpoints/Game/ReportingEndpoints.cs b/Refresh.GameServer/Endpoints/Game/ReportingEndpoints.cs index d7878285..33adce99 100644 --- a/Refresh.GameServer/Endpoints/Game/ReportingEndpoints.cs +++ b/Refresh.GameServer/Endpoints/Game/ReportingEndpoints.cs @@ -83,13 +83,15 @@ public Response UploadReport(RequestContext context, GameDatabaseContext databas return OK; } - //If the level is specified but its invalid, return BadRequest + //If the level is specified but its invalid, set it to 0, to indicate the level is unknown + //This case is hit when someone makes a grief report from a non-existent level, which we allow if (body.LevelId != 0 && level == null) - return BadRequest; + body.LevelId = 0; //Basic validation if (body.Players is { Length: > 4 } || body.ScreenElements is { Player.Length: > 4 }) - return BadRequest; + //Return OK on PSP, since if we dont, it will error when trying to access the community moon and soft-lock the save file + return context.IsPSP() ? OK : BadRequest; database.AddGriefReport(body); diff --git a/RefreshTests.GameServer/Tests/Reporting/ReportingEndpointsTests.cs b/RefreshTests.GameServer/Tests/Reporting/ReportingEndpointsTests.cs index 47e57c53..1333e344 100644 --- a/RefreshTests.GameServer/Tests/Reporting/ReportingEndpointsTests.cs +++ b/RefreshTests.GameServer/Tests/Reporting/ReportingEndpointsTests.cs @@ -85,7 +85,7 @@ public void UploadReport() } [Test] - public void CantUploadReportWithBadLevel() + public void CanUploadReportWithBadLevel() { using TestContext context = this.GetServer(); GameUser user = context.CreateUser(); @@ -98,17 +98,26 @@ public void CantUploadReportWithBadLevel() }; HttpResponseMessage response = client.PostAsync("/lbp/grief", new StringContent(report.AsXML())).Result; - Assert.That(response.StatusCode, Is.EqualTo(BadRequest)); + Assert.That(response.StatusCode, Is.EqualTo(OK)); + + context.Database.Refresh(); + + DatabaseList griefReports = context.Database.GetGriefReports(10, 0); + Assert.That(griefReports.TotalItems, Is.EqualTo(1)); + List reports = griefReports.Items.ToList(); + Assert.That(reports[0].Description, Is.EqualTo(report.Description)); } - [Test] - public void CantUploadReportWithBadPlayerCount() + [TestCase(true)] + [TestCase(false)] + public void CantUploadReportWithBadPlayerCount(bool psp) { using TestContext context = this.GetServer(); GameUser user = context.CreateUser(); using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, TokenGame.LittleBigPlanet1, TokenPlatform.PS3, user); - + if(psp) client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT"); + GameReport report = new() { LevelId = 0, @@ -138,17 +147,19 @@ public void CantUploadReportWithBadPlayerCount() }; HttpResponseMessage response = client.PostAsync("/lbp/grief", new StringContent(report.AsXML())).Result; - Assert.That(response.StatusCode, Is.EqualTo(BadRequest)); + Assert.That(response.StatusCode, Is.EqualTo(psp ? OK : BadRequest)); } - [Test] - public void CantUploadReportWithBadScreenElementPlayerCount() + [TestCase(true)] + [TestCase(false)] + public void CantUploadReportWithBadScreenElementPlayerCount(bool psp) { using TestContext context = this.GetServer(); GameUser user = context.CreateUser(); using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, TokenGame.LittleBigPlanet1, TokenPlatform.PS3, user); - + if(psp) client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT"); + GameReport report = new() { LevelId = 0, @@ -181,7 +192,7 @@ public void CantUploadReportWithBadScreenElementPlayerCount() }; HttpResponseMessage response = client.PostAsync("/lbp/grief", new StringContent(report.AsXML())).Result; - Assert.That(response.StatusCode, Is.EqualTo(BadRequest)); + Assert.That(response.StatusCode, Is.EqualTo(psp ? OK : BadRequest)); } [TestCase(TokenGame.LittleBigPlanet1)]