Skip to content

fix: keep the XP tracker's player id tied to the name it was checked against - #38

Merged
CodySimonds65 merged 2 commits into
mainfrom
fix/xp-tracker-player-id
Oct 5, 2026
Merged

CodySimonds65 merged 2 commits into
mainfrom
fix/xp-tracker-player-id

Conversation

@CodySimonds65

Copy link
Copy Markdown
Owner

Two pre-existing defects in how the XP tracker resolves a player id. Both were found by code reading; each is now reproduced by a test that failed on main before the fix.

1. A failed read reported an id cached for a different username

PlayerProfileService caches the last good (player id, snapshot) per account. Failure(...) returned that entry no matter which username the failed read was for.

Reproduced: track an account as Login (id 7), change it to Ranked, and have the fetch fail. GetActiveLeaderboardProfiles() returned (account, 7, "Ranked").

Fix: a failed read only falls back on the last good read when that read was made under the same username (case-insensitive).

The cached id is still the first one tried under the new name. A player's id survives an in-game rename, so it may well still be right. It just is not reported until a read confirms it.

2. A failed first read discarded a linked player id

In XpTrackerCoordinator.PollAccountAsync, the generic failure branch did account.PlayerId = result.PlayerId. With nothing cached that is null, so an id passed to Start(...) was gone for the session.

Reproduced: link id 42 for a player outside the top 200, fail the first read, then let reads succeed. The tracker fell through to the ranking lookup and never got a snapshot.

Fix: account.PlayerId ??= result.PlayerId. A failed read can supply an id the account lacks, but never clears or replaces one.

Also changed

  • XpTrackerCoordinator.ProfileRetryDelay (internal, default still 5 s). Every failed first read waits 5 s before its one retry, so without this the two tests add 10 s to a suite that runs in under a second.
  • A read with no username no longer returns the account's cached id and snapshot. Only the Stats / XP calculator panel reaches this path; it now shows just the "Add a ranking username" message instead of the previous name's stats.

Not changed

  • MainWindow.PublicPlayerId / PublicInGameName.
  • After a rename to a different player, a successful first read still reports "Player name mismatch" for one poll before the ranking lookup takes over. That is the existing behaviour and the price of trying the cached id first.
  • If an account is relinked to a different id under the same username and the next fetch fails, the Stats panel can briefly show the previously linked player's last snapshot. The tracker itself keeps the new link.

Tests

dotnet test src/FourFoldAccountManager.Desktop.Tests: 30 passed. dotnet test src/FourFoldAccountManager.Core.Tests: 309 passed.

Each new test was also checked against its own fix: undoing either fix alone fails exactly one of them.

Merging publishes a client release, since this touches src/.

…against

A failed profile read handed back whatever id was cached for the account,
even when the read was for a different username. After a Ranking username
change with the fetch failing, the tracker stored the old login's player id
under the new name and offered that pair to the leaderboard.

The cached id is still the one tried first, since an id survives an in-game
rename, but a failed read now only falls back on the last good read when it
was made under the same username.

A failed first read also cleared an explicitly linked player id for the rest
of the session, so a player outside the top 200 stopped being tracked. A
failed read can now supply a missing id but never clears or replaces one.
@CodySimonds65
CodySimonds65 merged commit 75237de into main Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant