fix: presence, profile edits, outfit menu and RecNetResult writes for the 2023 client

Every change below was checked against the 2023-03-21 client disassembly;
file:line evidence is in the code comments and in
docs/recroom-2023-client-api-complete.md.

Presence
- matchmake/none means "online, in no room" (its only caller is
  TryGoToOfflineRoom, which ignores the reply). The server used to keep the
  old room or invent a dorm, so the next heartbeat looked out of sync and
  the client cancelled its load to chase that room.
- The join watchdog no longer clears presence 30 s into a long room load;
  it is a 3 minute backstop that drops the room only.
- One fan-out (PresenceBroadcastService) for every transition: deferred
  joins, matchmake/none, logout, failed joins, visibility changes, SignalR
  connect/disconnect. isOnline is sent on its own; pushes never go to the
  subject, because a self push moves the player.
- Online-status visibility (Public / Friends / Favorites / Appear offline)
  is stored and honoured by GET /player and by the live pushes.

Profile
- PUT account/me/{emoji,personalpronouns,identityflags,bannerimage} were
  404; added with the client's real form keys and persisted (new Players
  columns plus migration). Every account read now returns them, and edits
  push AccountUpdate to everyone.

Outfit menu
- Saved outfits kept OutfitSelectionsV2 and CustomAvatarItems, so loading a
  slot restores what was saved instead of a stale outfit.
- isCreationAllowedForAccount answers the {Success, Error} envelope the
  client parses; minPriceForPublicItem is a bare int; gifts/generate accepts
  form bodies; lockeditems returns the full owned-item shape; colourways no
  longer share their base item's AvatarItemId.

RecNetResult writes
- About 40 writes look status-only but parse the body as {Success, Error}.
  An empty 200 showed "Failed to ..." after the server applied the change,
  and a body without Success threw "Error message cannot be null". Clubs,
  announcements, keepsakes, comments/read, subscriptions, purchase offers
  and privacy settings now answer RecNetResult.
- Login token and device-code grants are real; remoteauth approves the
  device code; createlogintoken returns a bare string.
- New: incentivizedreferrals/referrals, account/bulk/{email,phone},
  GET strings, account/me/confirmphone, PlayMenuCarouselOrdering_1.
  Route inventory and coverage test extended to match.

README now describes the 2023 branch.
This commit is contained in:
Alexa
2026-10-15 14:08:11 +03:00
parent 36e64e99ba
commit 6ee1d6f9b3
45 changed files with 6666 additions and 448 deletions
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore;
using DorkNet.Server.Auth;
using DorkNet.Server.Data;
using DorkNet.Server.Services;
namespace DorkNet.Server.Controllers.Match;
@@ -36,10 +38,19 @@ namespace DorkNet.Server.Controllers.Match;
/// </summary>
[ApiController]
public class PlayerPresenceController(
PlayerPresenceService presence) : ControllerBase
PlayerPresenceService presence,
PresenceBroadcastService presenceFanout,
JoinTimeoutService joinTimeouts,
DorkNetDbContext db,
ServerSettingsService settings) : ControllerBase
{
/// <summary>PlayerSettings key written by <c>PUT /player/statusvisibility</c>
/// (MatchPlayerController.PrefStatusVisibility — same literal; the
/// round-trip is pinned by a regression test).</summary>
public const string PrefStatusVisibility = PresenceBroadcastService.StatusVisibilityPrefKey;
[HttpGet("/player")]
public ActionResult<List<PlayerPresenceDto>> GetPresences()
public async Task<ActionResult<List<PlayerPresenceDto>>> GetPresences()
{
// The watch sends two URL flavours for this endpoint:
// 1. Bulk: <c>/player?{id1}&amp;{id2}&amp;{id3}</c> — bare keys,
@@ -81,31 +92,39 @@ public class PlayerPresenceController(
// mid-coroutine. Only redact for OTHER players where the
// privacy concern actually applies.
var callerId = this.CurrentPlayerId();
var callerRoom = callerId is long cid ? presence.GetRoom(cid) : null;
var callerRoom = callerId is long cid ? SelfRoom(cid) : null;
var visibility = await LoadVisibilityAsync(ids);
var hiddenFromCaller = await ResolveHiddenAsync(callerId, ids, visibility);
var result = ids.Select(id =>
{
var room = presence.GetRoom(id);
// Other players need both a room presence and an active
// live signal. Use the recent-heartbeat marker as the
// truth source: SignalR can drop while the player is still
// heartbeating, or linger after the game is gone. Presence
// keys intentionally live for minutes to survive long room
// loads, so using them alone leaves friends stuck online
// after a graceful disconnect.
var isSelf = callerId == id;
var active = isSelf || presence.IsRecentlyActive(id);
var isOnline = room is not null && active;
// The caller's own row must say exactly what their heartbeat
// says (pending-join target, or null in the offline room): the
// client compares its cached self presence field by field
// (HCHDEHIGEBE.DCIJHIPJHOB) and treats any difference as
// out-of-sync.
var room = isSelf ? callerRoom : presence.GetRoom(id);
// Online = a live signal (recent heartbeat, or a SignalR
// connection), NOT "has a room". Presence keys live for minutes
// to survive long room loads, so a room alone would leave friends
// stuck online after the game is gone; and a player in the offline
// room after matchmake/none has no room but is very much online
// (the 2023 DTO carries isOnline on its own; see
// NotificationService.BuildPresenceUpdatePayload).
// A player who chose "appear offline" (or friends/favorites
// only, when the caller doesn't qualify) is reported exactly
// like a genuinely offline player: no room, isOnline=false.
var isOnline = (isSelf || presenceFanout.IsOnline(id)) && !hiddenFromCaller.Contains(id);
if (!isOnline) room = null;
return new PlayerPresenceDto
{
PlayerId = (int)id,
// StatusVisibility is the player's *preference* for who may
// see them online. The enum is Everyone=0 / FriendsOnly=1 /
// Nobody=2 — so the previous value 1 (mislabeled "Visible")
// actually meant FriendsOnly, and anyone who wasn't your
// friend saw you as OFFLINE. On a private server everyone
// should see everyone, so report Everyone (0). IsOnline=false
// still gates the "Online" badge for offline players.
StatusVisibility = 0, // Everyone
// The player's stored online-status visibility. Self MUST
// see its own stored value: the profile dialog's current
// selection is read from the cached self presence, and a
// hard-coded 0 here snapped it back to Public after every
// presence refresh.
StatusVisibility = visibility.GetValueOrDefault(id, PresenceVisibility.Public),
DeviceClass = 0, // Desktop / unknown — not VR
VrMovementMode = 0,
// Full instance details are safe, and necessary, when the
@@ -124,6 +143,58 @@ public class PlayerPresenceController(
return Ok(result);
}
/// <summary>The caller's own room as their heartbeat reports it.</summary>
private RoomInstanceDto? SelfRoom(long playerId)
{
if (joinTimeouts.GetPending(playerId) is { DeferPresenceCommit: true } pending)
return pending.TargetRoom;
if (presence.IsInNoRoom(playerId)) return null;
return presence.GetRoom(playerId);
}
private Task<Dictionary<long, int>> LoadVisibilityAsync(HashSet<long> ids) =>
PresenceBroadcastService.GetStatusVisibilitiesAsync(db, ids);
/// <summary>Ids whose online status the caller may not see. The caller
/// always sees itself; anonymous callers only see Public players.</summary>
private async Task<HashSet<long>> ResolveHiddenAsync(
long? callerId, HashSet<long> ids, Dictionary<long, int> visibility)
{
var hidden = new HashSet<long>();
var restricted = visibility
.Where(kv => kv.Value != PresenceVisibility.Public && kv.Key != callerId)
.ToList();
if (restricted.Count == 0) return hidden;
if (callerId is not long me)
{
foreach (var kv in restricted) hidden.Add(kv.Key);
return hidden;
}
HashSet<long>? friends = null;
HashSet<long>? favoritedMe = null;
foreach (var (target, vis) in restricted)
{
if (vis == PresenceVisibility.Offline) { hidden.Add(target); continue; }
friends ??= (await RelationshipQueries.EffectiveFriendIdsAsync(db, settings, me)).ToHashSet();
if (!friends.Contains(target)) { hidden.Add(target); continue; }
if (vis == PresenceVisibility.FavoriteFriendsOnly)
{
// Favorited lives on the favoriter's own row
// (RequesterId = favoriter), as RelationshipsController.BuildMerged reads it.
favoritedMe ??= (await db.Relationships
.Where(r => r.TargetId == me && r.Favorited && ids.Contains(r.RequesterId))
.Select(r => r.RequesterId)
.ToListAsync()).ToHashSet();
if (!favoritedMe.Contains(target)) hidden.Add(target);
}
}
return hidden;
}
private static bool ShouldExposeFullRoom(
long? callerId,
RoomInstanceDto? callerRoom,
@@ -151,8 +222,8 @@ public class PlayerPresenceDto
[JsonPropertyName("playerId")]
public int PlayerId { get; set; }
/// <summary>PlayerStatusVisibility enum (int):
/// 0 = Hidden / Offline-appearing, 1 = Visible, 2 = FriendsOnly.</summary>
/// <summary>Online-status visibility enum (int, 2023 client):
/// 0 = Public, 1 = FriendsOnly, 2 = FavoriteFriendsOnly, 3 = Offline.</summary>
[JsonPropertyName("statusVisibility")]
public int StatusVisibility { get; set; }