Skip to content

Commit

Permalink
Fix story mission softlock (#753)
Browse files Browse the repository at this point in the history
A player got into a state where they were unable to progress the main
campaign as their client was refusing to call
`/mission/unlock_main_story_group`. Upon further investigation it seems
the cause of this is that we are always sending
`current_main_story_mission` from `/mission/get_mission_list` with data,
even if it relates to main story missions that are already completed.

This lead to the missions showing as completed on their screen, but
without any endeavours to claim and with the quest remaining locked.

Fix this by filtering out the current main story mission to those that
are not claimed. We will therefore send an empty
`current_main_story_mission` if none is in progress. This fixes the
issue, and lines up with what I have seen in my captures from my main
account on the official servers, which had completed the campaign.

Also includes a misc fix to user impersionation as I used it while
troubleshooting and noticed that it was broken after the global query
filter changes :P
  • Loading branch information
SapiensAnatis authored Apr 6, 2024
1 parent b28c44d commit 2b71ed3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,68 @@ await this.Client.PostMsgpack<MissionGetMissionListResponse>("mission/get_missio
.And.Contain(x => x.PeriodMissionId == expectedMission.Id)
.And.Contain(x => x.PeriodMissionId == otherExpectedMission.Id);
}

[Fact]
public async Task GetMissionList_DoesNotReturnPreviousMainStoryMissions()
{
IEnumerable<DbPlayerMission> completedMissions = MasterAsset
.MissionMainStoryData.Enumerable.Where(x => x.MissionMainStoryGroupId == 1)
.Select(x => new DbPlayerMission()
{
Id = x.Id,
GroupId = 1,
ViewerId = this.ViewerId,
Type = MissionType.MainStory,
State = MissionState.Claimed
});

await this.AddRangeToDatabase(completedMissions);

DragaliaResponse<MissionGetMissionListResponse> response =
await this.Client.PostMsgpack<MissionGetMissionListResponse>(
"mission/get_mission_list"
);

response
.Data.CurrentMainStoryMission.Should()
.BeEquivalentTo(new CurrentMainStoryMission());
}

[Fact]
public async Task GetMissionList_ReturnsCurrentMainStoryMissions()
{
IEnumerable<DbPlayerMission> inProgressMissions = MasterAsset
.MissionMainStoryData.Enumerable.Where(x => x.MissionMainStoryGroupId == 1)
.Select(x => new DbPlayerMission()
{
Id = x.Id,
GroupId = 1,
ViewerId = this.ViewerId,
Type = MissionType.MainStory,
State = MissionState.InProgress,
});

await this.AddRangeToDatabase(inProgressMissions);

DragaliaResponse<MissionGetMissionListResponse> response =
await this.Client.PostMsgpack<MissionGetMissionListResponse>(
"mission/get_mission_list"
);

response
.Data.CurrentMainStoryMission.Should()
.BeEquivalentTo(
new CurrentMainStoryMission()
{
MainStoryMissionGroupId = 1,
MainStoryMissionStateList = MasterAsset
.MissionMainStoryData.Enumerable.Where(x => x.MissionMainStoryGroupId == 1)
.Select(x => new AtgenMainStoryMissionStateList()
{
MainStoryMissionId = x.Id,
State = (int)MissionState.InProgress,
})
}
);
}
}
14 changes: 9 additions & 5 deletions DragaliaAPI/DragaliaAPI/Features/GraphQL/MutationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using DragaliaAPI.Database;
using DragaliaAPI.Database.Entities;
using DragaliaAPI.Shared.PlayerDetails;
using Microsoft.EntityFrameworkCore;

namespace DragaliaAPI.Features.GraphQL;

Expand All @@ -24,11 +25,9 @@ protected IDisposable StartUserImpersonation(
Func<IQueryable<DbPlayer>, IQueryable<DbPlayer>>? include = null
)
{
IDisposable context = this.identityService.StartUserImpersonation(viewerId, null);

IQueryable<DbPlayer> query = this.apiContext.Players.Where(x =>
x.UserData != null && x.UserData.ViewerId == viewerId
);
IQueryable<DbPlayer> query = this
.apiContext.Players.IgnoreQueryFilters()
.Where(x => x.UserData != null && x.UserData.ViewerId == viewerId);

if (include is not null)
query = include.Invoke(query);
Expand All @@ -40,6 +39,11 @@ protected IDisposable StartUserImpersonation(

this.Player = player;

IDisposable context = this.identityService.StartUserImpersonation(
viewerId,
player.AccountId
);

return context;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ public async Task<CurrentMainStoryMission> GetCurrentMainStoryMission()
{
int? mainStoryMissionGroupId = await this
.missionRepository.GetMissionsByType(MissionType.MainStory)
.Where(x => x.State < MissionState.Claimed)
.MaxAsync(x => x.GroupId);

if (mainStoryMissionGroupId == null)
Expand Down

0 comments on commit 2b71ed3

Please sign in to comment.