fix: correct 2023-03-21 client wire contracts across the API and notify surfaces

Audits every route the March-2023 client can call against what this server
actually serves, and fixes the defects that were breaking gameplay. Adds
docs/recroom-2023-client-api-complete.md as the reference: ~500 route
literals across 13 subsystems, with verb, request/response shape, and a
per-subsystem diff. 315 defects catalogued; the ones fixed here are listed
in its "Already fixed" table.

Path coverage was never the problem — 465 of 506 routes already had
handlers. The failures were in shape, and they cluster into four causes:

- Wrong verb. The verb is a BestHTTP.HTTPMethods ordinal (GET=0 .. PATCH=5),
  confirmed from that enum's static constructor. Routes registered POST-only
  while the client PUTs returned 405, which made room consumables neither
  buyable nor consumable and blocked every room-key edit.
- Bare scalar wrapped in an object. The client reads `1000`, not
  `{"Limit":1000}`; the issuing method signature says which. Wrapping makes
  the deserializer throw and the feature dies silently.
- [FromBody] vs form-urlencoded. The client sends nearly every write as form
  data, which an [ApiController] action bound [FromBody] rejects with 415
  before the handler runs. This alone broke all 13 club member-management
  endpoints. Adds Binding/FormOrJsonModelBinder so this is fixed once.
- Notify dispatch keys. Both enum overloads of the client's RegisterHandler
  lower the id via Int32.ToString() and register only that numeric key, and
  lookup is a case-sensitive TryGetValue that returns silently on a miss. We
  were sending the enum NAME for most ids, so friend-request updates, forced
  logout, maintenance broadcasts, live balance and consumable updates, and
  invention moderation pushes all evaporated with no error anywhere.

Notable behavioural bugs fixed:

- Editing a club announcement deleted it: PUT was a third binding on the
  delete handler. Split apart, and the missing create route added.
- leaderboard/CheckAndSetStat did not exist. The 2023 client has no SetStat
  literal at all, so every leaderboard score it wrote was discarded.
- Setting a club clubhouse cleared it: the handler read roomId from the query
  while the client sends it in the body, then wrote the resulting null.
- Club join requests were inverted (the enum is Open=0, InviteOnly=1,
  AskToJoin=2), so ask-to-join clubs rejected everyone and invite-only clubs
  quietly admitted them.
- Room bans were pushed as id 24, for which the client registers no handler;
  they now go out as ModerationKick with IsBan, so the ban takes effect
  immediately instead of at next login.
- Room-key ownership queries answered for the wrong player, and "has anyone
  bought this key" asked "did I buy it" — always false for the creator.

Also persists settings that were previously acknowledged and dropped
(playlist accessibility/restrictions/level-voting/warning, per-player status
visibility, VR movement mode and avoid-juniors, custom room codes), which is
what the new columns in the migration are for.

One test asserted the old nested PriceAndCurrency response shape; the
client's consumable formatter has no such key and reads Price and
PurchaseCurrencyId flat, so the test was corrected alongside the handler.
This commit is contained in:
Alexa
2026-07-27 23:27:23 +03:00
parent 674a3fc257
commit 327dcb789c
39 changed files with 9594 additions and 200 deletions
@@ -112,12 +112,17 @@ public class MatchPlayerController(
/// </summary>
[HttpPost("/player/notifydisconnect")]
[Consumes("application/x-www-form-urlencoded", "multipart/form-data")]
public IActionResult NotifyDisconnect([FromForm(Name = "otherPlayerId")] int? otherPlayerId)
public IActionResult NotifyDisconnect(
[FromForm(Name = "otherPlayerId")] int? otherPlayerId,
// The 2023-03-21 client sends PascalCase PlayerId + RoomInstanceId
// instead of 2020's otherPlayerId, so the legacy binding logged null.
[FromForm(Name = "PlayerId")] long? playerId,
[FromForm(Name = "RoomInstanceId")] long? roomInstanceId)
{
var caller = TryGetCurrentPlayerId();
log.LogInformation(
"[player-notify-disconnect] caller={Caller} reported other={Other} left",
caller, otherPlayerId);
"[player-notify-disconnect] caller={Caller} reported other={Other} instance={Instance} left",
caller, otherPlayerId ?? (int?)playerId, roomInstanceId);
return Ok();
}
@@ -158,9 +163,12 @@ public class MatchPlayerController(
return Ok(new PresenceDto
{
PlayerId = playerId,
StatusVisibility = 0, // Everyone (was 1 = FriendsOnly)
// Defaults: 0 = Everyone. Both come from the player's stored
// preference so a value set via /player/statusvisibility or
// /player/vrmovementmode survives the next heartbeat.
StatusVisibility = await GetPlayerPrefIntAsync(playerId, PrefStatusVisibility, 0),
DeviceClass = 0,
VrMovementMode = 0,
VrMovementMode = await GetPlayerPrefIntAsync(playerId, PrefVrMovementMode, 0),
RoomInstance = room,
});
}
@@ -170,13 +178,14 @@ public class MatchPlayerController(
public async Task<ActionResult<PresenceDto>> SetStatusVisibility([FromForm(Name = "statusVisibility")] int? value)
{
var playerId = TryGetCurrentPlayerId();
if (value is int v) await SetPlayerPrefAsync(playerId, PrefStatusVisibility, v.ToString());
var room = await GetPresenceRoomForResponseAsync(playerId);
return Ok(new PresenceDto
{
PlayerId = playerId,
StatusVisibility = value ?? 0, // default Everyone; honor explicit client choice
StatusVisibility = value ?? await GetPlayerPrefIntAsync(playerId, PrefStatusVisibility, 0),
DeviceClass = 0,
VrMovementMode = 0,
VrMovementMode = await GetPlayerPrefIntAsync(playerId, PrefVrMovementMode, 0),
RoomInstance = room,
});
}
@@ -186,17 +195,58 @@ public class MatchPlayerController(
public async Task<ActionResult<PresenceDto>> SetVrMovementMode([FromForm(Name = "vrMovementMode")] int? value)
{
var playerId = TryGetCurrentPlayerId();
if (value is int v) await SetPlayerPrefAsync(playerId, PrefVrMovementMode, v.ToString());
var room = await GetPresenceRoomForResponseAsync(playerId);
return Ok(new PresenceDto
{
PlayerId = playerId,
StatusVisibility = 0, // Everyone (was 1 = FriendsOnly)
StatusVisibility = await GetPlayerPrefIntAsync(playerId, PrefStatusVisibility, 0),
DeviceClass = 0,
VrMovementMode = value ?? 0,
VrMovementMode = value ?? await GetPlayerPrefIntAsync(playerId, PrefVrMovementMode, 0),
RoomInstance = room,
});
}
// ── per-player matchmaking preferences ───────────────────────────
// These three were previously echo-only: the client's chosen value came
// back in the response and was then dropped, so the setting reverted on the
// next heartbeat and never survived a restart. They live in PlayerSettings
// (no schema change needed) and are read back wherever presence is built.
private const string PrefStatusVisibility = "pref:statusVisibility";
private const string PrefVrMovementMode = "pref:vrMovementMode";
private const string PrefAvoidJuniors = "pref:avoidJuniors";
private async Task SetPlayerPrefAsync(long playerId, string key, string value)
{
if (playerId == 0) return;
var row = await db.PlayerSettings
.FirstOrDefaultAsync(s => s.PlayerId == playerId && s.Key == key);
if (row is null)
{
db.PlayerSettings.Add(new DorkNet.Server.Data.Entities.PlayerSettingEntity
{
PlayerId = playerId, Key = key, Value = value,
});
}
else
{
row.Value = value;
}
await db.SaveChangesAsync();
}
private async Task<string?> GetPlayerPrefAsync(long playerId, string key)
{
if (playerId == 0) return null;
return await db.PlayerSettings
.Where(s => s.PlayerId == playerId && s.Key == key)
.Select(s => s.Value)
.FirstOrDefaultAsync();
}
private async Task<int> GetPlayerPrefIntAsync(long playerId, string key, int fallback)
=> int.TryParse(await GetPlayerPrefAsync(playerId, key), out var v) ? v : fallback;
/// <summary>
/// GET <c>/player/avoidjuniors</c> — returns a primitive boolean.
/// Verified against
@@ -209,18 +259,28 @@ public class MatchPlayerController(
/// matchmaking init in a never-completes state on some boot flows.
/// </summary>
[HttpGet("/player/avoidjuniors")]
public ActionResult<bool> GetAvoidJuniors() => Ok(false);
public async Task<ActionResult<bool>> GetAvoidJuniors()
{
var playerId = TryGetCurrentPlayerId();
var stored = await GetPlayerPrefAsync(playerId, PrefAvoidJuniors);
return Ok(bool.TryParse(stored, out var v) && v);
}
/// <summary>PUT <c>/player/avoidjuniors</c> — body
/// <c>avoidJuniors=true|false</c> (Matchmaking.txt:7883). Stub for
/// now; the multi-tenant server doesn't currently track this
/// preference per-player. Returns the new value as a JSON
/// <c>avoidJuniors=true|false</c> (Matchmaking.txt:7883). Persisted
/// per-player in PlayerSettings and read back by
/// <see cref="GetAvoidJuniors"/>. Returns the new value as a JSON
/// primitive so the watch's ExpectPrimitiveResponse is happy.</summary>
[HttpPut("/player/avoidjuniors")]
[HttpPost("/player/avoidjuniors")]
[Consumes("application/x-www-form-urlencoded", "multipart/form-data")]
public ActionResult<bool> SetAvoidJuniors([FromForm(Name = "avoidJuniors")] bool? value)
=> Ok(value ?? false);
public async Task<ActionResult<bool>> SetAvoidJuniors([FromForm(Name = "avoidJuniors")] bool? value)
{
var playerId = TryGetCurrentPlayerId();
if (value is bool v)
await SetPlayerPrefAsync(playerId, PrefAvoidJuniors, v ? "true" : "false");
return Ok(value ?? false);
}
/// <summary>POST <c>/player/photonregionpings</c> — watch reports
/// its measured Photon region ping vector so the server can pick
@@ -260,6 +320,27 @@ public class MatchPlayerController(
// Sanity bound — discard wild values from misbehaving clients.
pairs[r] = Math.Clamp(p, 0, 2000);
}
// The 2023-03-21 client does NOT use the repeated (region, ping) pair
// shape above. It sends one field per measured region, keyed by the
// region name with the ping as the value (us=42&eu=90&...). Against the
// pair parser both arrays came back empty, so no 2023 client ever
// registered a ping and region selection fell back to the default.
if (pairs.Count == 0)
{
var fields = Request.HasFormContentType
? (IEnumerable<KeyValuePair<string, Microsoft.Extensions.Primitives.StringValues>>)Request.Form
: Request.Query;
foreach (var (key, value) in fields)
{
var name = key?.Trim();
if (string.IsNullOrEmpty(name)) continue;
if (name.Equals("region", StringComparison.OrdinalIgnoreCase) ||
name.Equals("ping", StringComparison.OrdinalIgnoreCase)) continue;
if (!int.TryParse(value.FirstOrDefault(), out var p)) continue;
pairs[name] = Math.Clamp(p, 0, 2000);
}
}
if (pairs.Count > 0)
presence.SetPhotonRegionPings(playerId, pairs);
log.LogInformation("[player-region-pings] player={Player} regions={Count}", playerId, pairs.Count);