Files
DorkNet/DorkNet.Server/Controllers/API/PlayerWarnings/PlayerWarningsController.cs
Alexa 6ee1d6f9b3 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.
2026-10-15 14:08:11 +03:00

148 lines
6.8 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using DorkNet.Server.Auth;
using DorkNet.Server.Data;
namespace DorkNet.Server.Controllers.API.PlayerWarnings;
[ApiController]
[Authorize]
public class PlayerWarningsController(DorkNetDbContext db) : ControllerBase
{
[HttpGet("api/playerwarnings")]
public async Task<IActionResult> Warnings()
{
var me = this.RequireCurrentPlayerId();
var rows = await db.PlayerSettings
.Where(s => s.PlayerId == me && s.Key.StartsWith("warning:"))
.OrderByDescending(s => s.Id)
.ToListAsync();
return Ok(rows
.Select(ToWarningWire)
.Where(w => !w.Acknowledged)
.ToList());
}
/// <summary>Moderator issues a warning against a player. The 2023-03-21
/// client POSTs this (verb register <c>rdx=2</c> at
/// RecNet.Runtime/FPIBGPIAOBI.txt:3455) with the form keys
/// <c>WarnedPlayerId</c>, <c>ReportCategory</c>, <c>DisplayReason</c> and
/// <c>ModeratorNote</c> (:3468-3520), matching the issuing method
/// <c>FGLDKEJLAKB&lt;DJMHAFPGLLN&gt; OEJIMKKDMBI(Int32, BDOGOIGCKMK,
/// String, String)</c> (:3102).
///
/// Only GET was registered here, so every warning the moderator tools
/// tried to create came back 405 and silently failed.</summary>
[HttpPost("api/playerwarnings")]
[Consumes("application/json", "application/x-www-form-urlencoded", "multipart/form-data")]
public async Task<IActionResult> CreateWarning(
[FromForm(Name = "WarnedPlayerId")] long? warnedPlayerId,
[FromForm(Name = "ReportCategory")] int? reportCategory,
[FromForm(Name = "DisplayReason")] string? displayReason,
[FromForm(Name = "ModeratorNote")] string? moderatorNote)
{
var me = this.RequireCurrentPlayerId();
var moderator = await db.Players
.Where(p => p.Id == me)
.Select(p => (bool?)(p.IsAdmin || p.IsDeveloper || p.IsCommunityTeam))
.FirstOrDefaultAsync();
// Both calls are read as DJMHAFPGLLN = {Success, Error} (the formatter,
// RecNet.Runtime/LMCCNLLHLCJ.txt:191-218, knows no "Message" key). A
// failure without Error reached Promise.Rejected(null) and threw
// "Error message cannot be null" instead of showing the reason.
if (moderator != true)
return Ok(new { Success = false, Error = "not_authorized", Message = "not_authorized" });
var target = warnedPlayerId
?? (long.TryParse(Request.Query["WarnedPlayerId"].FirstOrDefault(), out var q) ? q : 0);
if (target <= 0) return Ok(new { Success = false, Error = "missing_player", Message = "missing_player" });
if (!await db.Players.AnyAsync(p => p.Id == target))
return Ok(new { Success = false, Error = "player_not_found", Message = "player_not_found" });
// Same "warning:{id}|message|category|createdAt|acknowledged" layout the
// GET list handler parses in ToWarningWire.
var reason = (displayReason ?? string.Empty).Trim();
var note = (moderatorNote ?? string.Empty).Trim();
var message = string.IsNullOrEmpty(note) ? reason : $"{reason} ({note})";
var id = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff");
db.PlayerSettings.Add(new DorkNet.Server.Data.Entities.PlayerSettingEntity
{
PlayerId = target,
Key = $"warning:{id}",
Value = string.Join('|',
message.Replace('|', '/'),
(reportCategory ?? 0).ToString(),
DateTime.UtcNow.ToString("O"),
"false"),
});
await db.SaveChangesAsync();
return Ok(new { Success = true, Error = string.Empty, Message = string.Empty, WarningId = id });
}
/// <summary>The 2023-03-21 client's acknowledge call takes NO arguments —
/// the issuing method is <c>FGLDKEJLAKB&lt;DJMHAFPGLLN&gt; DOFADJPFBMK()</c>
/// (FPIBGPIAOBI.txt:3524) and it POSTs an empty body (:3590-3592). It means
/// "acknowledge my pending warning".
///
/// Demanding a warningId made every call 400, so the modal was never marked
/// read and re-appeared on each login. With no id supplied we now
/// acknowledge the newest unacknowledged warning, and acknowledging nothing
/// is a success rather than an error.</summary>
[HttpPost("api/playerwarnings/acknowledge")]
[Consumes("application/json", "application/x-www-form-urlencoded", "multipart/form-data")]
public async Task<IActionResult> Acknowledge([FromForm] string? warningId)
{
var me = this.RequireCurrentPlayerId();
var id = warningId ?? Request.Query["warningId"].FirstOrDefault() ?? Request.Query["id"].FirstOrDefault();
DorkNet.Server.Data.Entities.PlayerSettingEntity? row;
if (string.IsNullOrWhiteSpace(id))
{
// Acknowledged state lives inside the packed Value string, so the
// filter has to run client-side after materialising.
var rows = await db.PlayerSettings
.Where(s => s.PlayerId == me && s.Key.StartsWith("warning:"))
.OrderByDescending(s => s.Id)
.ToListAsync();
row = rows.FirstOrDefault(s => !ToWarningWire(s).Acknowledged);
if (row is null) return Ok(new { Success = true, Error = string.Empty, Message = string.Empty });
}
else
{
row = await db.PlayerSettings
.FirstOrDefaultAsync(s => s.PlayerId == me && s.Key == $"warning:{id}");
if (row is null) return Ok(new { Success = true, Error = string.Empty, Message = string.Empty });
}
var parts = row.Value.Split('|');
row.Value = string.Join('|', parts.Take(3).Append("true"));
await db.SaveChangesAsync();
return Ok(new { Success = true, Error = string.Empty, Message = string.Empty, WarningId = row.Key["warning:".Length..] });
}
private static WarningWire ToWarningWire(DorkNet.Server.Data.Entities.PlayerSettingEntity row)
{
var parts = row.Value.Split('|');
return new WarningWire
{
WarningId = row.Key["warning:".Length..],
Message = parts.ElementAtOrDefault(0) ?? string.Empty,
Category = int.TryParse(parts.ElementAtOrDefault(1), out var category) ? category : 0,
CreatedAt = parts.ElementAtOrDefault(2) ?? string.Empty,
Acknowledged = bool.TryParse(parts.ElementAtOrDefault(3), out var acknowledged) && acknowledged,
};
}
private sealed class WarningWire
{
public string WarningId { get; set; } = string.Empty;
public string Message { get; set; } = string.Empty;
public int Category { get; set; }
public string CreatedAt { get; set; } = string.Empty;
public bool Acknowledged { get; set; }
}
}