Skip to content

Commit 8d0b5a4

Browse files
authored
Fix in-game level republishes not preserving reupload information (#916)
https://discord.com/channels/1049223665243389953/1049225857350254632/1400919160547971186
2 parents d8ed12e + 821587f commit 8d0b5a4

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

Refresh.Database/GameDatabaseContext.Levels.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ public void UpdateLevelLocations(IEnumerable<ISerializedEditLevelLocation> locat
176176
newLevel.Publisher = author;
177177
newLevel.PublishDate = oldLevel.PublishDate;
178178
newLevel.DateTeamPicked = oldLevel.DateTeamPicked;
179+
newLevel.IsReUpload = oldLevel.IsReUpload;
180+
newLevel.OriginalPublisher = oldLevel.OriginalPublisher;
179181

180182
// If the actual contents of the level haven't changed, extract some extra information
181183
if (oldLevel.RootResource == newLevel.RootResource)
@@ -623,7 +625,6 @@ public void UpdateSkillRewardsForLevel(GameLevel level, IEnumerable<GameSkillRew
623625
Title = reward.Title,
624626
Enabled = reward.Enabled,
625627
RequiredAmount = reward.RequiredAmount,
626-
Level = level,
627628
LevelId = level.LevelId,
628629
ConditionType = reward.ConditionType,
629630
};

RefreshTests.GameServer/Tests/Levels/PublishEndpointsTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using RefreshTests.GameServer.Extensions;
99
using Refresh.Database.Models.Levels;
1010
using Refresh.Database.Models.Notifications;
11+
using Refresh.Interfaces.APIv3.Endpoints.DataTypes.Request;
1112
using Refresh.Interfaces.Game.Endpoints.DataTypes.Request;
1213
using Refresh.Interfaces.Game.Endpoints.DataTypes.Response;
1314
using Refresh.Interfaces.Game.Types.Levels;
@@ -704,4 +705,71 @@ public void CanPublishLevelWithSkillRewards()
704705
IEnumerable<GameSkillReward> rewards = context.Database.GetSkillRewardsForLevel(dbLevel!);
705706
Assert.That(rewards, Is.Not.Empty);
706707
}
708+
709+
[Test]
710+
public void ReuploadStatusPreserved()
711+
{
712+
using TestContext context = this.GetServer();
713+
GameUser user = context.CreateUser();
714+
715+
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
716+
717+
HttpResponseMessage message = client.PostAsync($"/lbp/upload/{TEST_ASSET_HASH}", new ReadOnlyMemoryContent("LVLb"u8.ToArray())).Result;
718+
Assert.That(message.StatusCode, Is.EqualTo(OK));
719+
720+
GameLevel dbLevel = context.CreateLevel(user);
721+
context.Database.UpdateLevel(new ApiAdminEditLevelRequest()
722+
{
723+
IsReUpload = true,
724+
OriginalPublisher = "glotchmeister69",
725+
}, dbLevel, null);
726+
727+
using (Assert.EnterMultipleScope())
728+
{
729+
Assert.That(dbLevel.IsReUpload, Is.True);
730+
Assert.That(dbLevel.OriginalPublisher, Is.EqualTo("glotchmeister69"));
731+
}
732+
733+
GameLevelRequest level = new()
734+
{
735+
LevelId = dbLevel.LevelId,
736+
IsAdventure = false,
737+
Title = "Level",
738+
IconHash = "0",
739+
Description = new string('=', UgcLimits.DescriptionLimit * 2),
740+
Location = new GameLocation(),
741+
GameVersion = 0,
742+
RootResource = TEST_ASSET_HASH,
743+
PublishDate = 0,
744+
UpdateDate = 0,
745+
MinPlayers = 0,
746+
MaxPlayers = 0,
747+
EnforceMinMaxPlayers = false,
748+
SameScreenGame = false,
749+
SkillRewards = new List<GameSkillReward>()
750+
{
751+
new()
752+
{
753+
ConditionType = GameSkillRewardCondition.Lives,
754+
RequiredAmount = 3,
755+
Id = 1,
756+
Title = "do the stuff",
757+
Enabled = true,
758+
},
759+
},
760+
};
761+
762+
// Republish the level
763+
message = client.PostAsync("/lbp/publish", new StringContent(level.AsXML())).Result;
764+
Assert.That(message.StatusCode, Is.EqualTo(OK));
765+
766+
context.Database.Refresh();
767+
dbLevel = context.Database.GetLevelById(dbLevel.LevelId)!;
768+
769+
using (Assert.EnterMultipleScope())
770+
{
771+
Assert.That(dbLevel.IsReUpload, Is.True);
772+
Assert.That(dbLevel.OriginalPublisher, Is.EqualTo("glotchmeister69"));
773+
}
774+
}
707775
}

0 commit comments

Comments
 (0)