mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RadicadeServer.DB;
|
||||
using RadicadeServer.RecNet.Auth.Cached;
|
||||
using RadicadeServer.RecNet.Enums.Players;
|
||||
|
||||
namespace RadicadeServer.Auth.Cached
|
||||
{
|
||||
[Route("auth/cachedlogin")]
|
||||
public class CachedLoginAPI : Controller
|
||||
{
|
||||
RecDBContext db;
|
||||
public CachedLoginAPI(RecDBContext context)
|
||||
{
|
||||
this.db = context;
|
||||
}
|
||||
|
||||
[HttpGet("forplatformid/{platform}/{platformId}")]
|
||||
public async Task<IActionResult> GetCachedLoginsForPlatformId(Platforms platform, string platformId)
|
||||
{
|
||||
if (platform == Platforms.Standalone) return Ok(new List<CachedLogin>());
|
||||
var cached = await db.CachedLogins.AsNoTracking()
|
||||
.Where(login => login.platformId == platformId && login.platform == platform)
|
||||
.Where(login => db.Players.Any(player => player.AccountId == login.accountId))
|
||||
.Where(login => db.Profiles.Any(profile => profile.accountId == login.accountId))
|
||||
.Where(login => db.Presences.Any(presence => presence.playerId == login.accountId))
|
||||
.OrderByDescending(login => login.lastLoginTime)
|
||||
.ToListAsync();
|
||||
return Ok(cached);
|
||||
}
|
||||
|
||||
[HttpPost("forplatformids")]
|
||||
public async Task<List<CachedLogin>> GetCachedLoginsForPlatformIds([FromForm] string[] id)
|
||||
{
|
||||
if (id == null || id.Length <= 0) return [];
|
||||
|
||||
var requestedIds = id.Where(platformId => !string.IsNullOrWhiteSpace(platformId))
|
||||
.Distinct(StringComparer.Ordinal).ToArray();
|
||||
var cachedLogins = new List<CachedLogin>();
|
||||
foreach (var platformId in requestedIds)
|
||||
{
|
||||
var cached = await db.CachedLogins.AsNoTracking()
|
||||
.Where(login => login.platformId == platformId && login.platform != Platforms.Standalone)
|
||||
.Where(login => db.Players.Any(player => player.AccountId == login.accountId))
|
||||
.Where(login => db.Profiles.Any(profile => profile.accountId == login.accountId))
|
||||
.Where(login => db.Presences.Any(presence => presence.playerId == login.accountId))
|
||||
.OrderByDescending(login => login.lastLoginTime)
|
||||
.FirstOrDefaultAsync();
|
||||
if (cached != null) cachedLogins.Add(cached);
|
||||
}
|
||||
|
||||
return cachedLogins;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user