Skip to content

Commit

Permalink
ReportingEndpoints: Dont error on invalid level + dont return error o…
Browse files Browse the repository at this point in the history
…n PSP (#280)

More PSP weirdness + allow grief reports on missing levels, just incase
some weirdness happens, like a level is deleted after creation, and
someone happened to start playing it, and you want to grief report a
player in your game or something, unlikely, but we probably should allow
it anyway
  • Loading branch information
jvyden authored Nov 19, 2023
2 parents 947b608 + 059809c commit 0f1b728
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
8 changes: 5 additions & 3 deletions Refresh.GameServer/Endpoints/Game/ReportingEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
31 changes: 21 additions & 10 deletions RefreshTests.GameServer/Tests/Reporting/ReportingEndpointsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void UploadReport()
}

[Test]
public void CantUploadReportWithBadLevel()
public void CanUploadReportWithBadLevel()
{
using TestContext context = this.GetServer();
GameUser user = context.CreateUser();
Expand All @@ -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<GameReport> griefReports = context.Database.GetGriefReports(10, 0);
Assert.That(griefReports.TotalItems, Is.EqualTo(1));
List<GameReport> 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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 0f1b728

Please sign in to comment.