Skip to content

Data model and results

EF Core over PostgreSQL (Data/AcidBoyDb.cs). Migrations are in Data/Migrations and are applied at startup.

erDiagram
    Account ||--o{ ExternalLogin : "signs in with"
    Account ||--o{ RefreshToken : has
    Account ||--o{ Friendship : "requester / addressee"
    Account ||--o{ Match : "host / guest / winner / ended by"
    Match ||--o{ MatchResult : has
    Account ||--o{ PlayerGameRecord : has
    Account ||--o{ AuditEntry : "actor / target"
    Channel
Table Key fields Notes
Accounts Id, DisplayName, AvatarUrl, CreatedAt, LastSeenAt, Role (Player/Moderator/Admin), BannedUntil/BanReason, MutedUntil/MuteReason A permanent ban or mute ends 9999-12-31
ExternalLogins Provider, ProviderUserId (unique together), AccountId github, discord, google, dev
RefreshTokens TokenHash (SHA-256, unique), ExpiresAt, RevokedAt
Channels Id (slug), Name, Description, SortOrder Seeded: general, pokemon-gen1, pokemon-gen2, tetris
Friendships RequesterId, AddresseeId (unique pair), Status (Pending/Accepted)
Matches Players and their game titles and ROM SHA-1s, Lobby, StartedAt, ConnectedAt, EndedAt, EndReason, EndedById, BytesRelayed, plus the outcome: GameKey, HostWins, GuestWins, Draws, DecidedAt, WinnerId One relayed link session
MatchResults MatchId + Sequence (unique), Kind, HostPayload, GuestPayload (jsonb) One row per event; each player fills in their side
PlayerGameRecords AccountId + GameKey (key), Wins, Losses, Draws, RoundsWon, RoundsLost, LastPlayedAt A cache rebuilt from decided matches
AuditLog At, ActorId, Action, TargetAccountId, Target, Details (jsonb) Every staff action

Results come from the players’ emulators (Win detection).

  1. Reports: each player reports each event under the same Sequence, and the server stores both payloads.
  2. Verification: a result is verified when both payloads are identical. A one-sided or disagreeing result is shown in the history and the dashboard, but never counts.
  3. Recomputing: after every report and when a match ends, MatchService.UpdateOutcomeAsync recomputes the match from its verified Battle and Set results:
    • the score is the number of verified rounds won by each side, plus draws;
    • a verified Set decides the match at once, and its winner is the match winner;
    • otherwise the match is decided when it ends: the side with more verified round wins wins it, and equal wins is a draw;
    • a match with no verified rounds stays undecided.
  4. Records: whenever a decided match changes, both players’ PlayerGameRecord for that game are rebuilt from all their decided matches. Duplicate or late reports therefore never double-count. Each game’s leaderboard cache is invalidated at the same time.

Old payloads without a game field get it from the host’s cartridge title. At startup, finished matches with results but no outcome are decided.

LeaderboardService:

  • Ranking: players of a game are ranked by match wins. Ties go to the better win rate (counted from 5 decided matches), then to the most recent player.
  • Size: up to 100 entries.
  • Caching: results are cached for 60 s, with a version per game so a new result appears at once.
Migration Adds
Initial Accounts, logins, refresh tokens, channels (seeded), friendships, matches, results
AdminAndModeration Roles, bans, mutes, audit log
MatchOutcomes Match outcome fields, EndedById, PlayerGameRecords

Add one with:

Terminal window
dotnet tool restore
dotnet ef migrations add <Name> --project src/server/AcidBoy.Server --output-dir Data/Migrations