mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-25 23:18:44 -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.
131 lines
4.5 KiB
C#
131 lines
4.5 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using DorkNet.Server.Auth;
|
|
using DorkNet.Server.Data;
|
|
using DorkNet.Server.Services;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace DorkNet.Server.Controllers.Econ;
|
|
|
|
/// <summary>
|
|
/// econ.{rec.net,localhost} — token balance + inventory queries used
|
|
/// by older client flows. Reads from <see cref="LevelService"/>
|
|
/// (currency type 0 = Token per <c>CurrencyType.cs</c>) and the
|
|
/// <see cref="PlayerInventoryEntity"/> table. Note: the primary
|
|
/// store/inventory surface is api.*/api/storefronts/* + api/inventory/*;
|
|
/// this host is a legacy alias.
|
|
/// </summary>
|
|
[ApiController]
|
|
[Authorize]
|
|
public class EconController(DorkNetDbContext db, LevelService level) : ControllerBase
|
|
{
|
|
[HttpGet("/econ/v1/balance/{accountId:long}")]
|
|
public async Task<ActionResult<TokenBalance>> GetBalance(long accountId)
|
|
{
|
|
var tokens = await level.GetBalanceAsync(accountId, 0);
|
|
return Ok(new TokenBalance
|
|
{
|
|
AccountId = accountId,
|
|
Tokens = (int)tokens,
|
|
BonusTokens = 0,
|
|
});
|
|
}
|
|
|
|
[HttpGet("/econ/v1/ownershipbatch")]
|
|
public async Task<IActionResult> GetOwnershipBatch([FromQuery] string? ids)
|
|
{
|
|
var pid = this.RequireCurrentPlayerId();
|
|
var slugs = (ids ?? string.Empty)
|
|
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
|
.ToList();
|
|
var q = db.PlayerInventory.Where(p => p.PlayerId == pid);
|
|
if (slugs.Count > 0) q = q.Where(p => slugs.Contains(p.ItemSlug));
|
|
var rows = await q.Select(p => new { p.ItemSlug, p.Quantity }).ToListAsync();
|
|
return Ok(rows);
|
|
}
|
|
|
|
[HttpGet("/econ/v1/inventory/{accountId:long}")]
|
|
public async Task<IActionResult> GetInventory(long accountId)
|
|
{
|
|
var rows = await db.PlayerInventory
|
|
.Where(p => p.PlayerId == accountId)
|
|
.Select(p => new { p.ItemSlug, p.Quantity })
|
|
.ToListAsync();
|
|
return Ok(rows);
|
|
}
|
|
|
|
[HttpGet("/econ/v1/products")]
|
|
public async Task<IActionResult> GetProducts()
|
|
{
|
|
var rows = await db.StoreItems
|
|
.Where(s => s.IsActive)
|
|
.Select(s => new
|
|
{
|
|
Id = s.Id,
|
|
Slug = s.Slug,
|
|
Name = s.DisplayName,
|
|
Price = s.Price,
|
|
CurrencyType = s.CurrencyType,
|
|
})
|
|
.ToListAsync();
|
|
return Ok(rows);
|
|
}
|
|
|
|
[HttpGet("/econ/customAvatarItems")]
|
|
[HttpGet("/econ/customAvatarItems/v1/owned")]
|
|
public async Task<IActionResult> GetOwnedCustomAvatarItems([FromQuery] int skip = 0, [FromQuery] int take = 100)
|
|
{
|
|
var pid = this.RequireCurrentPlayerId();
|
|
skip = Math.Max(0, skip);
|
|
take = Math.Clamp(take, 1, 100);
|
|
|
|
var query = db.CustomAvatarItemOwnership
|
|
.Where(o => o.PlayerId == pid)
|
|
.Join(db.CustomAvatarItems, o => o.CustomAvatarItemId, i => i.Id, (o, i) => i)
|
|
.OrderByDescending(i => i.UpdatedAt);
|
|
|
|
var total = await query.CountAsync();
|
|
var rows = await query
|
|
.Skip(skip)
|
|
.Take(take)
|
|
.ToListAsync();
|
|
|
|
return Ok(new
|
|
{
|
|
Results = rows.Select(ToCustomAvatarItemWire),
|
|
TotalResults = total,
|
|
});
|
|
}
|
|
|
|
/// <summary>The client reads this body as a BARE integer — the issuing
|
|
/// method is <c>FGLDKEJLAKB<System.Int32> KPOENLDFAJD()</c>
|
|
/// (RecNet.Runtime/MPBLNLMCEDL.txt:2881, route literal on :2955).
|
|
/// Returning a JSON object made the deserialize throw, so the ownership-cap
|
|
/// check that runs before a custom-shirt purchase always errored out.</summary>
|
|
[HttpGet("/econ/customAvatarItems/v1/itemOwnershipLimit")]
|
|
public IActionResult CustomAvatarItemOwnershipLimit()
|
|
=> Content("1000", "application/json");
|
|
|
|
private static object ToCustomAvatarItemWire(DorkNet.Server.Data.Entities.CustomAvatarItemEntity i) => new
|
|
{
|
|
CustomAvatarItemId = i.PublicId,
|
|
Id = i.PublicId,
|
|
CreatorPlayerId = (int)i.CreatorPlayerId,
|
|
i.Name,
|
|
i.Description,
|
|
i.Price,
|
|
i.ItemType,
|
|
i.ImageName,
|
|
i.AssetName,
|
|
i.Color,
|
|
};
|
|
}
|
|
|
|
public class TokenBalance
|
|
{
|
|
[JsonPropertyName("AccountId")] public long AccountId { get; set; }
|
|
[JsonPropertyName("Tokens")] public int Tokens { get; set; }
|
|
[JsonPropertyName("BonusTokens")] public int BonusTokens { get; set; }
|
|
}
|