30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
using SVSim.EmulatedEntrypoint.Constants;
|
|
using SVSim.EmulatedEntrypoint.Security;
|
|
using SVSim.EmulatedEntrypoint.Services;
|
|
|
|
namespace SVSim.EmulatedEntrypoint.Middlewares;
|
|
|
|
/// <summary>
|
|
/// Maps an incoming request's session id to a udid if both are present.
|
|
/// </summary>
|
|
public class SessionidMappingMiddleware : IMiddleware
|
|
{
|
|
private readonly ShadowverseSessionService _shadowverseSessionService;
|
|
|
|
public SessionidMappingMiddleware(ShadowverseSessionService shadowverseSessionService)
|
|
{
|
|
_shadowverseSessionService = shadowverseSessionService;
|
|
}
|
|
|
|
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
|
|
{
|
|
bool hasSessionId = context.Request.Headers.TryGetValue(NetworkConstants.UdidHeaderName, out var udid);
|
|
bool hasUdid = context.Request.Headers.TryGetValue(NetworkConstants.SessionIdHeaderName, out var sid);
|
|
if (hasSessionId && hasUdid)
|
|
{
|
|
_shadowverseSessionService.StoreUdidForSessionId(sid.FirstOrDefault(), Guid.Parse(Encryption.Decode(udid.FirstOrDefault())));
|
|
}
|
|
|
|
await next.Invoke(context);
|
|
}
|
|
} |