Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A Windows client for running several FourFold accounts side by side, each in its
- **Community plugins**: open the plugin list (the wrench) and choose **Plugin hub** to search and install plugins made by the community. Every plugin is reviewed before it is listed, runs in a sandbox, and updates itself. To make one, see [PLUGIN_AUTHORS.md](PLUGIN_AUTHORS.md).
- **Overlays**: drag XP/hr, stats, XP calculator and timer cards anywhere over the game.
- **Second monitor**: pop the tools panel into its own window, or float individual cards on any screen.
- **Shared XP leaderboard**: daily, weekly and monthly XP gains across opted-in players.
- **XP leaderboard**: daily, weekly and monthly XP gains, read from [ffdb.info](https://ffdb.info).
- **Store blocking**: optionally stop the in-game store and gold buttons from opening (Settings → Display).

## Shortcuts
Expand Down Expand Up @@ -57,7 +57,7 @@ dotnet run --project src/FourFoldAccountManager.Desktop/FourFoldAccountManager.D
<details>
<summary><strong>Leaderboard service (maintainers)</strong></summary>

The desktop uses `https://fourfold-shared-xp-leaderboard.onrender.com`; override it with `FOURFOLD_LEADERBOARD_URL`. Local XP tracking works without it. The server reads public profiles itself and never accepts XP values from the client.
The desktop reads rankings from `https://ffdb.info/api/leaderboards`; override the host with `FOURFOLD_LEADERBOARD_URL`. It sends nothing, so it needs no server of ours. The service below is no longer used by the desktop.

**Backup:** use PostgreSQL 16+ tools against Neon's direct TLS endpoint, with credentials in `PG*` environment variables. Dumps contain profile IDs and XP data, so keep them private.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@ namespace FourFoldAccountManager.Core.Tests.Panel;

public sealed class PanelLayoutPolicyTests
{
[Fact]
public void SettingsTransformsPreserveLeaderboardSharingPreference()
{
var accountId = Guid.NewGuid();
var settings = PanelSettings.Default with
{
ShareLinkedAccounts = true,
SlotAccountIds = [accountId, null, null, null, null]
};

Assert.True(PanelLayoutPolicy.WithLayout(settings, PanelLayout.OneByTwo).ShareLinkedAccounts);
Assert.True(PanelLayoutPolicy.Assign(settings, 1, Guid.NewGuid()).ShareLinkedAccounts);
Assert.True(PanelLayoutPolicy.ClearAccount(settings, accountId).ShareLinkedAccounts);
Assert.True(PanelLayoutPolicy.WithSplitState(settings,
new PanelSplitState("2x2.rows", [0.7, 0.3])).ShareLinkedAccounts);
Assert.True(PanelLayoutPolicy.ResetSplitStates(settings).ShareLinkedAccounts);
}

[Fact]
public void SettingsTransformsPreserveOverlayCardsAndClearAccountRemovesTheAccountsCards()
{
Expand Down
6 changes: 1 addition & 5 deletions src/FourFoldAccountManager.Core/Data/SettingsStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ public async Task<PanelSettings> LoadAsync(CancellationToken cancellationToken =
{
if (!File.Exists(_paths.SettingsFilePath))
{
// An existing account file may predate the sharing setting. Keep that installation private.
return Validate(PanelSettings.Default with
{
ShareLinkedAccounts = !File.Exists(_paths.AccountsFilePath)
});
return Validate(PanelSettings.Default);
}

try
Expand Down
7 changes: 1 addition & 6 deletions src/FourFoldAccountManager.Core/Models/PanelSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public PanelSettings(PanelLayout layout, IReadOnlyList<Guid?> slotAccountIds)

public bool FillGameToPanel { get; init; } = false;

public bool ShareLinkedAccounts { get; init; } = false;

public bool ShowFullScreenExitButton { get; init; } = true;

// Whether the plugin panel is open beside the strip. The name and JSON key predate the strip, so existing settings
Expand Down Expand Up @@ -106,8 +104,5 @@ public PanelSettings(PanelLayout layout, IReadOnlyList<Guid?> slotAccountIds)
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IReadOnlyDictionary<Guid, OverlayBounds>? LegacyXpOverlayBoundsByAccount { get; init; }

public static PanelSettings Default => new(PanelLayout.TwoByTwo, new Guid?[5])
{
ShareLinkedAccounts = true
};
public static PanelSettings Default => new(PanelLayout.TwoByTwo, new Guid?[5]);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Net;
using System.Net.Http;
using System.IO;
using System.Text.Json;
using System.Text.Json.Nodes;
using FourFoldAccountManager.Core.Data;
using FourFoldAccountManager.Core.Leaderboard;
using FourFoldAccountManager.Desktop.Services;
Expand All @@ -13,119 +11,64 @@ namespace FourFoldAccountManager.Desktop.Tests.Leaderboard;
public sealed class LeaderboardCoordinatorTests
{
[Fact]
public async Task OldSettingsDefaultToPrivateAndOptInSurvivesRestart()
{
using var temp = new TempDirectory();
var paths = new LocalDataPaths(temp.Path);
var settings = new SettingsStore(paths);
await settings.SaveAsync(await settings.LoadAsync());
var oldJson = JsonNode.Parse(await File.ReadAllTextAsync(paths.SettingsFilePath))!.AsObject();
oldJson.Remove("shareLinkedAccounts");
await File.WriteAllTextAsync(paths.SettingsFilePath, oldJson.ToJsonString());
Assert.False((await settings.LoadAsync()).ShareLinkedAccounts);
await settings.SaveAsync((await settings.LoadAsync()) with { ShareLinkedAccounts = true });
Assert.True((await settings.LoadAsync()).ShareLinkedAccounts);
}

[Fact]
public async Task InstallationIdPersistsAndWireRequestContainsOnlyPublicIdentity()
public async Task ReadsAnFfdbPageAndKeepsItAcrossRestarts()
{
using var temp = new TempDirectory();
var handler = new RecordingHandler();
await using var first = CreateCoordinator(temp.Path, handler, sharing: true);
await first.InitializeAsync();
await first.SyncParticipationAsync([new LeaderboardProfile(42, "Player")], [42], CancellationToken.None);
await first.FlushPendingAsync();
var firstRequest = handler.Bodies.Single();
using var json = JsonDocument.Parse(firstRequest);
var id = json.RootElement.GetProperty("installationId").GetGuid();
Assert.NotEqual(Guid.Empty, id);
Assert.Equal(42, json.RootElement.GetProperty("activePlayerIds")[0].GetInt32());
Assert.DoesNotContain("accountId", firstRequest, StringComparison.OrdinalIgnoreCase);
Assert.DoesNotContain("label", firstRequest, StringComparison.OrdinalIgnoreCase);
Assert.DoesNotContain("password", firstRequest, StringComparison.OrdinalIgnoreCase);
await using var second = CreateCoordinator(temp.Path, new RecordingHandler(), sharing: true);
await second.InitializeAsync();
Assert.Equal(id, second.InstallationId);
}
await using (var coordinator = CreateCoordinator(temp.Path, handler))
{
var page = await coordinator.RefreshPageAsync(LeaderboardPeriod.Weekly, 2, 25, CancellationToken.None);
Assert.NotNull(page);
Assert.Equal(26, Assert.Single(page.Entries).Rank);
Assert.Equal("pinkmilk", page.Entries[0].Username);
Assert.Equal(41, page.TotalEntries);
}
Assert.Equal("https://ffdb.info/api/leaderboards?period=weekly&page=2",
Assert.Single(handler.Requests).ToString());

[Fact]
public async Task OptOutPersistsLocallyBeforeRequestAndRetriesEmptyHeartbeat()
{
using var temp = new TempDirectory();
var settings = new SettingsStore(new LocalDataPaths(temp.Path));
await settings.SaveAsync((await settings.LoadAsync()) with { ShareLinkedAccounts = true });
var handler = new RecordingHandler { Fail = true };
await using var coordinator = CreateCoordinator(temp.Path, handler, sharing: true,
async (enabled, ct) => await settings.SaveAsync((await settings.LoadAsync(ct)) with { ShareLinkedAccounts = enabled }, ct));
await coordinator.InitializeAsync();
await coordinator.SetSharingEnabledAsync(false, CancellationToken.None);
Assert.False((await settings.LoadAsync()).ShareLinkedAccounts);
await coordinator.FlushPendingAsync();
Assert.True(coordinator.HasPendingParticipation);
handler.Fail = false;
await coordinator.FlushPendingAsync();
Assert.False(coordinator.HasPendingParticipation);
using var json = JsonDocument.Parse(handler.Bodies.Last());
Assert.False(json.RootElement.GetProperty("sharingEnabled").GetBoolean());
Assert.Empty(json.RootElement.GetProperty("activePlayerIds").EnumerateArray());
await using var restarted = CreateCoordinator(temp.Path, new RecordingHandler { Fail = true });
var cached = await restarted.GetCachedPageAsync(LeaderboardPeriod.Weekly, 2, 25, CancellationToken.None);
Assert.Equal("pinkmilk", Assert.Single(cached!.Entries).Username);
Assert.Null(await restarted.RefreshPageAsync(LeaderboardPeriod.Weekly, 2, 25, CancellationToken.None,
scheduleRetry: false));
}

[Fact]
public async Task DefaultPrivateStateNeverContactsParticipationEndpoint()
public async Task OldStateFileWithParticipationFieldsStillLoadsItsCache()
{
using var temp = new TempDirectory();
var handler = new RecordingHandler();
await using var coordinator = CreateCoordinator(temp.Path, handler, sharing: false);
await coordinator.InitializeAsync();
await coordinator.SyncParticipationAsync([new LeaderboardProfile(42, "Player")], [42], CancellationToken.None);
await coordinator.FlushPendingAsync();
Assert.Empty(handler.Bodies);
}
var paths = new LocalDataPaths(temp.Path);
await using (var coordinator = CreateCoordinator(temp.Path, new RecordingHandler()))
await coordinator.RefreshPageAsync(LeaderboardPeriod.Weekly, 2, 25, CancellationToken.None);
var json = await File.ReadAllTextAsync(paths.LeaderboardStateFilePath);
await File.WriteAllTextAsync(paths.LeaderboardStateFilePath, json.Insert(1,
"\"installationId\":\"3f2c1e9a-0000-4000-8000-000000000001\",\"pendingParticipation\":null,"));

[Fact]
public async Task FailingLeaderboardDoesNotPreventLocalTrackerStart()
{
using var temp = new TempDirectory();
await using var coordinator = CreateCoordinator(temp.Path, new RecordingHandler { Fail = true }, sharing: true);
await coordinator.InitializeAsync();
await coordinator.SyncParticipationAsync([new LeaderboardProfile(42, "Player")], [42], CancellationToken.None);
await coordinator.FlushPendingAsync();
await using var tracker = new XpTrackerCoordinator(new LocalDataPaths(temp.Path), _ => Task.CompletedTask);
var accountId = Guid.NewGuid();
tracker.Start(accountId, "Player", 42);
Assert.Equal(accountId, Assert.Single(tracker.GetStates()).AccountId);
Assert.Equal(42, Assert.Single(tracker.GetActiveLeaderboardProfiles()).PlayerId);
Assert.True(coordinator.HasPendingParticipation);
var state = await new LeaderboardClientStateStore(paths).LoadAsync();
Assert.Single(state.CachedPages);
}

private static LeaderboardCoordinator CreateCoordinator(string path, RecordingHandler handler, bool sharing,
Func<bool, CancellationToken, Task>? persist = null)
private static LeaderboardCoordinator CreateCoordinator(string path, RecordingHandler handler)
{
var client = new LeaderboardApiClient(new HttpClient(handler),
new LeaderboardApiOptions(new Uri("https://leaderboard.example/")));
return new LeaderboardCoordinator(new LeaderboardClientStateStore(new LocalDataPaths(path)),
client, sharing, persist ?? ((_, _) => Task.CompletedTask));
var client = new LeaderboardApiClient(new HttpClient(handler), LeaderboardApiOptions.FromEnvironment()!);
return new LeaderboardCoordinator(new LeaderboardClientStateStore(new LocalDataPaths(path)), client);
}

private sealed class RecordingHandler : HttpMessageHandler
{
public List<string> Bodies { get; } = [];
public List<Uri> Requests { get; } = [];
public bool Fail { get; set; }
public bool BadJson { get; set; }
public int GetRequests { get; private set; }

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken ct)
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken ct)
{
if (request.Content is not null) Bodies.Add(await request.Content.ReadAsStringAsync(ct));
if (request.Method == HttpMethod.Get) GetRequests++;
Requests.Add(request.RequestUri!);
if (Fail) throw new HttpRequestException("offline");
if (request.Method == HttpMethod.Put) return new HttpResponseMessage(HttpStatusCode.NoContent);
var page = request.RequestUri!.Query.Contains("page=2&", StringComparison.Ordinal) ? 2 : 1;
var body = BadJson ? "{broken" : $$"""
{"period":0,"periodStartUtc":"2026-09-23T00:00:00Z","periodEndUtc":"2026-09-24T00:00:00Z","page":{{page}},"pageSize":50,"totalEntries":2,"generatedAtUtc":"2026-09-23T12:00:00Z","entries":[{"rank":{{page}},"playerId":{{41 + page}},"username":"Player {{page}}","xpGained":100,"lastSampledAtUtc":"2026-09-23T12:00:00Z","isStale":false}]}
var (start, end) = LeaderboardPeriodWindow.GetCurrent(LeaderboardPeriod.Weekly, DateTimeOffset.UtcNow);
// Shape copied from a live ffdb.info weekly page 2 response.
var body = $$"""
{"trackingGeneration":"fourfolddb-xp-2026-10-25","source":"fourfolddb","period":1,"periodStartUtc":"{{start:O}}","periodEndUtc":"{{end:O}}","pageSize":25,"totalEntries":41,"generatedAtUtc":"2026-11-04T19:03:58.900Z","trackingStartedAtUtc":"2026-10-25T22:31:55.062Z","lastCollectedAtUtc":"2026-11-04T19:03:58.805Z","initialPassComplete":true,"trackedPlayers":260,"page":2,"fetchedAtUtc":"2026-11-04T19:04:24.677Z","sourceUnavailable":false,"entries":[{"rank":26,"playerId":235,"username":"pinkmilk","xpGained":197839,"lastSampledAtUtc":"2026-11-04T19:03:58.805Z","isStale":false}]}
""";
return new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(body) };
return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(body) });
}
}

Expand Down
Loading
Loading