Files
SVSimServer/SVSim.EmulatedEntrypoint/Extensions/HttpContextExtensions.cs
gamer147 c8ee1e487f ext: HttpContext.GetUdid() over SID-mapping service
Mirrors how the translation middleware resolves the per-request UDID;
needed by ToolController.Signup and the SteamSession find-or-link
branch.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 14:07:42 -04:00

41 lines
1.4 KiB
C#

using SVSim.Database.Models;
using SVSim.EmulatedEntrypoint.Constants;
using SVSim.EmulatedEntrypoint.Services;
namespace SVSim.EmulatedEntrypoint.Extensions;
public static class HttpContextExtensions
{
private const string ViewerItemName = "SVSimViewer";
public static Viewer? GetViewer(this HttpContext context)
{
if (context.Items.TryGetValue(ViewerItemName, out object? viewer))
{
return viewer as Viewer;
}
return null;
}
public static Viewer SetViewer(this HttpContext context, Viewer viewer)
{
context.Items[ViewerItemName] = viewer;
return viewer;
}
/// <summary>
/// Resolves the client's UDID for this request by looking up the SID header in the
/// in-memory SID→UDID dict that <see cref="Middlewares.SessionidMappingMiddleware"/>
/// populates from the UDID header. Returns null when the SID isn't mapped (e.g. the
/// request didn't carry a UDID header at all, or carried an undecodable one).
/// </summary>
public static Guid? GetUdid(this HttpContext context)
{
string? sid = context.Request.Headers[NetworkConstants.SessionIdHeaderName];
if (sid is null) return null;
var sessionService = context.RequestServices.GetService<ShadowverseSessionService>();
return sessionService?.GetUdidFromSessionId(sid);
}
}