mirror of
https://gitea.tendokyu.moe/Kayori/Medusa.net.git
synced 2026-09-26 08:18:01 +03:00
- SppassOpenHandler/LookupHandler/CloseHandler implementing the eAmuse
sppass.open/lookup/close xrpc methods (request/response schema
confirmed by tracing the client's psmap-based response parser and by
live testing against a real cabinet build)
- SppassSessionService backs open/lookup/close with a token-keyed
session (url + interval for the cabinet to display/poll, later
card_type/card_id once approved)
- CardlessApi: POST /api/cardless/{token}/approve, letting a signed-in
player's phone approve the pending token using their account's
first registered card
- Cardless frontend pages ([token].vue, scan.vue) and useCardlessAuth
composable driving the approval call
- GetConfig GraphQL query + ConfigQuery resolver so the cardless page
can show which server it's talking to
- Wire ISppassSessionService and the cardless routes into Program.cs;
HandlerService now parses model into a GameModel once per request
instead of re-parsing per handler
49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
namespace Server.Services;
|
|
|
|
public class SppassSessionService(IMemoryCache cache) : ISppassSessionService
|
|
{
|
|
private static readonly TimeSpan SessionLifetime = TimeSpan.FromMinutes(3);
|
|
|
|
private readonly IMemoryCache _cache = cache;
|
|
|
|
public SppassSession Open()
|
|
{
|
|
var session = new SppassSession(GenerateToken(), DateTimeOffset.UtcNow.Add(SessionLifetime));
|
|
_cache.Set(session.Token, session, session.ExpiresAt);
|
|
return session;
|
|
}
|
|
|
|
public SppassSession? GetSession(string token)
|
|
=> _cache.TryGetValue(token, out SppassSession? session) ? session : null;
|
|
|
|
public bool TryApprove(string token, string cardType, string cardId)
|
|
{
|
|
var session = GetSession(token);
|
|
if (session is null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
session.CardType = cardType;
|
|
session.CardId = cardId;
|
|
return true;
|
|
}
|
|
|
|
public void Close(string token)
|
|
{
|
|
_cache.Remove(token);
|
|
}
|
|
|
|
private static string GenerateToken()
|
|
=> Guid.NewGuid().ToString().Replace("-", "").ToUpper();
|
|
}
|
|
|
|
public record SppassSession(string Token, DateTimeOffset ExpiresAt)
|
|
{
|
|
public string? CardType { get; set; }
|
|
public string? CardId { get; set; }
|
|
public bool IsApproved => CardId is not null;
|
|
}
|