mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-25 23:18:44 -07:00
Import december-2020-12-18 from private repo (scrubbed 2026-05-27)
Targets Rec Room 2020.12.18 client.
Re-import after adding:
- DorkNet.ClientMod/dorknet-clientmod.json.template — config schema
the launcher's manifest-driven patcher renders into UserData/.
- tools/build-patcher-zip.ps1 — produces the dorknet-clientpatch-{key}.zip
Release asset the launcher fetches.
- .github/workflows/release.yml — auto-publishes both Release assets
on v1-december-* tag push.
Scrubbed via maintainer-side scrub-for-public.ps1: same drop rules as
the prior import, plus build-patcher-zip.ps1 added to the tools/
allow-list so it survives the scrub.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DorkNet.Server.Data;
|
||||
using System.Security.Claims;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DorkNet.Server.Auth;
|
||||
|
||||
/// <summary>
|
||||
/// Short-circuits any authenticated request whose JWT-resolved player has
|
||||
/// a non-null <c>BannedUntil</c> in the future. Sits AFTER
|
||||
/// <c>UseAuthentication</c>/<c>UseAuthorization</c> in the pipeline so the
|
||||
/// claims principal is populated before we look at it.
|
||||
///
|
||||
/// Anonymous requests (no/invalid bearer) pass through unchanged — this
|
||||
/// middleware never short-circuits them. Whether they're allowed is the
|
||||
/// per-endpoint <c>[Authorize]</c> decision, not ours.
|
||||
///
|
||||
/// Lookup is one query per request against the Players table. Cached for
|
||||
/// the request lifetime via the scoped DbContext, so repeated bearer
|
||||
/// checks within one request hit the EF first-level cache.
|
||||
/// </summary>
|
||||
public class BanCheckMiddleware(RequestDelegate next)
|
||||
{
|
||||
public async Task InvokeAsync(HttpContext ctx, DorkNetDbContext db)
|
||||
{
|
||||
// Cheap early-out for anonymous traffic — no DB hit.
|
||||
var sub = ctx.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (!long.TryParse(sub, out var playerId))
|
||||
{
|
||||
await next(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
// Project just the BannedUntil column — no need to materialise the
|
||||
// full player entity for every request.
|
||||
var bannedUntil = await db.Players
|
||||
.Where(p => p.Id == playerId)
|
||||
.Select(p => p.BannedUntil)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (bannedUntil.HasValue && bannedUntil.Value > DateTime.UtcNow)
|
||||
{
|
||||
ctx.Response.StatusCode = StatusCodes.Status401Unauthorized;
|
||||
ctx.Response.ContentType = "application/json";
|
||||
await ctx.Response.WriteAsync(JsonSerializer.Serialize(new
|
||||
{
|
||||
Error = "banned",
|
||||
Until = bannedUntil.Value.ToString("o"),
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
await next(ctx);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user