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.
101 lines
4.1 KiB
C#
101 lines
4.1 KiB
C#
using System.Text.Json;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using DorkNet.Server.Auth;
|
|
|
|
namespace DorkNet.Server.Controllers.API.Comments;
|
|
|
|
/// <summary>
|
|
/// Room-comment unread counts. Client contract (RecNet.Runtime
|
|
/// <c>OPELMBNJHNO.DJLNMANKMAA(IReadOnlyCollection<long>)</c>).
|
|
///
|
|
/// The response is a JSON <b>ARRAY</b>, not an object. The method's return
|
|
/// type is <c>Dictionary<long,uint></c>, but that dictionary is built
|
|
/// client-side: OPELMBNJHNO.txt:889 constructs a
|
|
/// <c>Func<List<UnreadRoomComments>, Dictionary<long,uint>></c>
|
|
/// projection that runs over the deserialised payload. So the wire type is
|
|
/// <c>List<RecNet.UnreadRoomComments></c> — each element an object with a
|
|
/// room id (Int64) and a count (UInt32), per the two properties on
|
|
/// RecNet/UnreadRoomComments.txt.
|
|
///
|
|
/// This previously returned an object map keyed by room id. Json.NET cannot
|
|
/// read a JSON object into a <c>List<T></c>, so every call threw and the
|
|
/// client logged "Failed to get unread room comment counts"
|
|
/// (OPELMBNJHNO.txt:937) and fell back to an empty dictionary — the watch's
|
|
/// room-comment unread badge never appeared.
|
|
///
|
|
/// The element's exact property names are attribute-driven and are not
|
|
/// recoverable from the ISIL (see the note on key aliasing below), so each
|
|
/// element carries the plausible spellings side by side. Json.NET matches
|
|
/// case-insensitively and ignores unknown members, so the extra aliases are
|
|
/// inert whichever name the DTO actually declares.
|
|
///
|
|
/// Counts are all zero until per-player comment read-state is tracked; the
|
|
/// shape is what matters for the client not to throw.
|
|
/// </summary>
|
|
[ApiController]
|
|
[Authorize]
|
|
public class CommentsController : ControllerBase
|
|
{
|
|
[HttpPost("/comments/unreadcounts")]
|
|
[HttpGet("/comments/unreadcounts")]
|
|
[Consumes("application/json", "application/x-www-form-urlencoded", "multipart/form-data")]
|
|
public async Task<IActionResult> UnreadCounts()
|
|
{
|
|
var roomIds = await ReadRoomIdsAsync();
|
|
var result = roomIds
|
|
.Select(id => new Dictionary<string, object>
|
|
{
|
|
["RoomId"] = id,
|
|
["UnreadCount"] = 0u,
|
|
["Count"] = 0u,
|
|
})
|
|
.ToList();
|
|
return Ok(result);
|
|
}
|
|
|
|
private async Task<HashSet<long>> ReadRoomIdsAsync()
|
|
{
|
|
var ids = new HashSet<long>();
|
|
|
|
void AddCsv(string? s)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(s)) return;
|
|
foreach (var part in s.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
|
if (long.TryParse(part, out var v) && v > 0) ids.Add(v);
|
|
}
|
|
|
|
// Query / form: roomIds=1,2,3
|
|
foreach (var k in new[] { "roomIds", "roomId", "ids", "id" })
|
|
{
|
|
AddCsv(Request.Query[k].ToString());
|
|
if (Request.HasFormContentType) AddCsv(Request.Form[k].ToString());
|
|
}
|
|
|
|
// JSON body: either a bare array [1,2,3] or { "roomIds": [1,2,3] }.
|
|
if (!Request.HasFormContentType)
|
|
{
|
|
try
|
|
{
|
|
Request.EnableBuffering();
|
|
Request.Body.Position = 0;
|
|
using var doc = await JsonDocument.ParseAsync(Request.Body);
|
|
var root = doc.RootElement;
|
|
JsonElement arr = default;
|
|
var haveArr = false;
|
|
if (root.ValueKind == JsonValueKind.Array) { arr = root; haveArr = true; }
|
|
else if (root.ValueKind == JsonValueKind.Object)
|
|
{
|
|
foreach (var k in new[] { "roomIds", "RoomIds", "ids", "Ids" })
|
|
if (root.TryGetProperty(k, out arr) && arr.ValueKind == JsonValueKind.Array) { haveArr = true; break; }
|
|
}
|
|
if (haveArr)
|
|
foreach (var el in arr.EnumerateArray())
|
|
if (el.ValueKind == JsonValueKind.Number && el.TryGetInt64(out var v) && v > 0) ids.Add(v);
|
|
}
|
|
catch { /* non-JSON / empty body */ }
|
|
}
|
|
return ids;
|
|
}
|
|
}
|