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>
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
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))
|
||||
@@ -21,4 +23,18 @@ public static class HttpContextExtensions
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user