Skip to content

Commit 005e5a7

Browse files
authored
Prevent LBP3 from overwriting LBP1/2 level root resources (#946)
2 parents e0cf25c + 4de22ed commit 005e5a7

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Refresh.Interfaces.Game/Endpoints/Levels/PublishEndpoints.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ public Response PublishLevel(RequestContext context,
212212
return BadRequest;
213213
}
214214

215+
// LBP3 doesn't allow users to overwrite LBP1/2 levels, however editing their metadata will cause LBP3 to reserialize the root resource,
216+
// upload it and put its hash into the republish request body, making the levels unplayable in LBP1/2.
217+
if (dataContext.Game == TokenGame.LittleBigPlanet3 && levelToUpdate.GameVersion != TokenGame.LittleBigPlanet3)
218+
{
219+
body.RootResource = levelToUpdate.RootResource;
220+
}
221+
215222
bool isFullEdit = body.RootResource != levelToUpdate.RootResource;
216223
levelToUpdate = dataContext.Database.UpdateLevel(body, levelToUpdate, dataContext.Game);
217224

RefreshTests.GameServer/Tests/Levels/PublishEndpointsTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,45 @@ public void CantRepublishOtherUsersLevel()
362362
message = client2.PostAsync("/lbp/publish", new StringContent(level.AsXML())).Result;
363363
Assert.That(message.StatusCode, Is.EqualTo(BadRequest));
364364
}
365+
366+
[Test]
367+
public void CantOverwriteNonLbp3LevelInLbp3()
368+
{
369+
using TestContext context = this.GetServer();
370+
GameUser user = context.CreateUser();
371+
using HttpClient clientLbp3 = context.GetAuthenticatedClient(TokenType.Game, TokenGame.LittleBigPlanet3, TokenPlatform.PS3, user);
372+
373+
GameLevel level = context.Database.AddLevel(new GameLevelRequest()
374+
{
375+
Title = "AMASING LBP1 LEVEL!!",
376+
Description = "Im gonna come up with a description later...",
377+
RootResource = "epic",
378+
}, TokenGame.LittleBigPlanet1, user);
379+
380+
// Now try republishing the level in LBP3
381+
GameLevelRequest republish = new()
382+
{
383+
LevelId = level.LevelId,
384+
Title = "AMAZING LBP1 LEVEL!!",
385+
IconHash = "g719",
386+
Description = "THIS LEVEL IS SO GOOD IT MAKES ME WANT TO BEAUTIFY ITS METADATA IN LBP3 WITHOUT LOOKING!!",
387+
RootResource = TEST_ASSET_HASH,
388+
};
389+
390+
// Upload our """level"""
391+
HttpResponseMessage message = clientLbp3.PostAsync($"/lbp/upload/{TEST_ASSET_HASH}", new ReadOnlyMemoryContent("LVLb"u8.ToArray())).Result;
392+
Assert.That(message.StatusCode, Is.EqualTo(OK));
393+
394+
message = clientLbp3.PostAsync("/lbp/publish", new StringContent(republish.AsXML())).Result;
395+
Assert.That(message.StatusCode, Is.EqualTo(OK));
396+
397+
GameLevelResponse response = message.Content.ReadAsXML<GameLevelResponse>();
398+
Assert.That(response.Title, Is.EqualTo(republish.Title));
399+
Assert.That(response.Description, Is.EqualTo(republish.Description));
400+
Assert.That(response.IconHash, Is.EqualTo(republish.IconHash));
401+
Assert.That(response.RootResource, Is.EqualTo("epic"));
402+
Assert.That(response.GameVersion, Is.EqualTo((int)TokenGame.LittleBigPlanet1));
403+
}
365404

366405
[Test]
367406
public void CantPublishSameRootLevelHashTwice()

0 commit comments

Comments
 (0)