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
Tables
Section titled “Tables”| 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 |
Match outcomes
Section titled “Match outcomes”Results come from the players’ emulators (Win detection).
- Reports: each player reports each event under the same
Sequence, and the server stores both payloads. - 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.
- Recomputing: after every report and when a match ends,
MatchService.UpdateOutcomeAsyncrecomputes the match from its verifiedBattleandSetresults:- the score is the number of verified rounds won by each side, plus draws;
- a verified
Setdecides 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.
- Records: whenever a decided match changes, both players’
PlayerGameRecordfor 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.
Leaderboards
Section titled “Leaderboards”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.
Migrations
Section titled “Migrations”| 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:
dotnet tool restoredotnet ef migrations add <Name> --project src/server/AcidBoy.Server --output-dir Data/Migrations