mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-26 15:38:45 -07:00
327dcb789c
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.
115 lines
5.2 KiB
C#
115 lines
5.2 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using DorkNet.Server.Data;
|
|
|
|
namespace DorkNet.Server.Controllers.API.Role;
|
|
|
|
/// <summary>
|
|
/// api.rec.net/api/role/* — role / privilege probes the watch consults
|
|
/// when deciding whether to surface dev-only UI (the in-watch debug
|
|
/// console button, hidden admin-tool tab, etc).
|
|
///
|
|
/// URL verified against
|
|
/// Cpp2IL_ISIL/IsilDump/Assembly-CSharp/RecNet/Accounts.txt:5168
|
|
/// (<c>"role/developer/{0}"</c>) called from
|
|
/// <c>RecNet.Accounts.GetAccountIsDeveloper</c>. Response shape is a
|
|
/// bare JSON boolean — the watch wraps the call with
|
|
/// <c>PromiseExtensions.ExpectPrimitiveResponse<bool></c>, so an
|
|
/// array or object response throws InvalidCastException and silently
|
|
/// disables the dev UI.
|
|
///
|
|
/// To make a player a developer (and unlock the watch's
|
|
/// debug-console button), set <c>Players.IsDeveloper = 1</c> in the
|
|
/// SQLite DB or via the admin UI's player editor.
|
|
/// </summary>
|
|
[ApiController]
|
|
public class RoleController(DorkNetDbContext db) : ControllerBase
|
|
{
|
|
// Service-routed call from Accounts.GetAccountIsDeveloper. The
|
|
// 2020 dump's SendRequest carries `Service = 0` (Auth) — verified
|
|
// at Cpp2IL_ISIL/.../RecNet/Accounts.txt:5183-5186 against the
|
|
// RecNet.Service enum in dump.cs:586523-586538 (Auth=0). Service.Auth
|
|
// maps to <c>auth.{apex}</c> in ConfigService's ServiceUrls, and
|
|
// the path the watch appends has NO `/api/` prefix — it's just
|
|
// <c>role/developer/{id}</c>. The previous <c>/api/role/...</c>-only
|
|
// route never matched, so every nameplate probe came back 404 and
|
|
// the watch logged "Failed to GetIsDeveloper for accountId X: HTTP
|
|
// Error 404" once per remote player per scene load.
|
|
[HttpGet("/role/developer/{accountId:long}")]
|
|
[HttpGet("/api/role/developer/{accountId:long}")]
|
|
[AllowAnonymous]
|
|
public async Task<ActionResult<bool>> IsDeveloper(long accountId)
|
|
{
|
|
// OR IsCommunityTeam into the answer so the watch unlocks the
|
|
// in-settings "Developer Display Mode" slider for community-team
|
|
// members too — the slider's positions render the overhead
|
|
// badge as "Community Team" / "Developer" (see
|
|
// Cpp2IL_ISIL/.../PlayerUI.txt:9085-9099). The 2020 watch never
|
|
// probes a separate community-team role, so collapsing both
|
|
// flags into this one endpoint is the only way to reach the
|
|
// badge UI without patching the binary.
|
|
var isDev = await db.Players
|
|
.Where(p => p.Id == accountId)
|
|
.Select(p => (bool?)(p.IsDeveloper || p.IsCommunityTeam || p.IsAdmin))
|
|
.FirstOrDefaultAsync();
|
|
return Ok(isDev ?? false);
|
|
}
|
|
|
|
/// <summary>Mirror endpoint for the admin role — same shape, in case
|
|
/// later builds added an <c>/api/role/admin/{id}</c> probe. The 2020
|
|
/// dump only references the developer one but admins also get all
|
|
/// dev privileges, so the result is unioned.</summary>
|
|
[HttpGet("/role/admin/{accountId:long}")]
|
|
[HttpGet("/api/role/admin/{accountId:long}")]
|
|
[AllowAnonymous]
|
|
public async Task<ActionResult<bool>> IsAdmin(long accountId)
|
|
{
|
|
var isAdmin = await db.Players
|
|
.Where(p => p.Id == accountId)
|
|
.Select(p => (bool?)p.IsAdmin)
|
|
.FirstOrDefaultAsync();
|
|
return Ok(isAdmin ?? false);
|
|
}
|
|
|
|
/// <summary>The March-2023 client probes this one in addition to
|
|
/// <c>role/developer</c>. Both calls funnel through the same helper
|
|
/// (<c>OPMAPIOEIFG.ILHILCFCNFF</c>, which formats <c>"role/{0}/{1}"</c>
|
|
/// and issues it with HTTPMethods.GET); the two call sites differ only
|
|
/// in the role literal they pass — <c>"developer"</c> at
|
|
/// RecNet.Runtime/OPMAPIOEIFG.txt:9402 and <c>"moderator"</c> at
|
|
/// :9471. The 2020 build never referenced the moderator probe, so it
|
|
/// used to 404 for every remote player on the 2023 client.
|
|
///
|
|
/// DorkNet has no dedicated moderator bit, so admins and community-team
|
|
/// members answer true — they are the accounts that actually hold
|
|
/// moderation powers here.</summary>
|
|
[HttpGet("/role/moderator/{accountId:long}")]
|
|
[HttpGet("/api/role/moderator/{accountId:long}")]
|
|
[AllowAnonymous]
|
|
public async Task<ActionResult<bool>> IsModerator(long accountId)
|
|
{
|
|
var isMod = await db.Players
|
|
.Where(p => p.Id == accountId)
|
|
.Select(p => (bool?)(p.IsAdmin || p.IsCommunityTeam))
|
|
.FirstOrDefaultAsync();
|
|
return Ok(isMod ?? false);
|
|
}
|
|
|
|
/// <summary>Future-proofing for a hypothetical
|
|
/// <c>role/communityteam/{id}</c> probe — not referenced by the 2020
|
|
/// build, but mirrors the developer shape so a patched watch can
|
|
/// distinguish the two roles without a server change.</summary>
|
|
[HttpGet("/role/communityteam/{accountId:long}")]
|
|
[HttpGet("/api/role/communityteam/{accountId:long}")]
|
|
[AllowAnonymous]
|
|
public async Task<ActionResult<bool>> IsCommunityTeam(long accountId)
|
|
{
|
|
var isCt = await db.Players
|
|
.Where(p => p.Id == accountId)
|
|
.Select(p => (bool?)p.IsCommunityTeam)
|
|
.FirstOrDefaultAsync();
|
|
return Ok(isCt ?? false);
|
|
}
|
|
}
|