Build & Deploy / build (push) Successful in 31s
Adds SquadService (singleton, process-local) tracking squads by the squadId the client shares across party members, plus a user->squad index so TryGetCompleteSquadInfo (no squadId in request) can resolve the caller's squad. Members are lazily registered on any squad call. - TryGetCompleteSquadInfo: returns the caller's real squad. - SquadMemberReadyForMatch: joins the squad, records readiness/map, returns the squad + whether everyone is ready. - SquadMemberSelectedMap: records the member's selected map. - DbUserService.FindByIdAsync: resolve display name for squad members. Groundwork for the station lobby; assumes the client drives squads via these calls with a shared squadId (to confirm with a 2-client session). Real-time SignalR push (unknown event names) deferred; the squad is carried in responses + TryGetCompleteSquadInfo for now. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
76 lines
3.3 KiB
C#
76 lines
3.3 KiB
C#
using System.Text.Json.Serialization;
|
|
using Prospect.Server.Api.Services.CloudScript;
|
|
using Prospect.Server.Api.Services.Auth.Extensions;
|
|
using Prospect.Server.Api.Services.Database;
|
|
using Prospect.Server.Api.Services.Database.Models;
|
|
using Prospect.Server.Api.Services.Squad;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Prospect.Server.Api.Hubs;
|
|
|
|
public class SquadMemberReadyForMatchRequest
|
|
{
|
|
[JsonPropertyName("squadId")]
|
|
public string SquadID { get; set; }
|
|
[JsonPropertyName("matchmakingSettings")]
|
|
public FYUserMatchmakingSettings matchmakingSettings { get; set; }
|
|
}
|
|
|
|
public class SquadMemberReadyForMatchResponse
|
|
{
|
|
[JsonPropertyName("result")]
|
|
public int Result { get; set; } // EYSquadActionResult
|
|
[JsonPropertyName("squad")]
|
|
public FYPlayFabSquad Squad { get; set; }
|
|
[JsonPropertyName("isSquadReadyForMatch")]
|
|
public bool IsSquadReadyForMatch { get; set; }
|
|
}
|
|
|
|
[CloudScriptFunction("SquadMemberReadyForMatch")]
|
|
public class SquadMemberReadyForMatchFunction : ICloudScriptFunction<SquadMemberReadyForMatchRequest, SquadMemberReadyForMatchResponse>
|
|
{
|
|
private readonly ILogger<SquadMemberReadyForMatchFunction> _logger;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly IHubContext<CycleHub> _hubContext;
|
|
private readonly SquadService _squadService;
|
|
private readonly DbUserService _userService;
|
|
|
|
public SquadMemberReadyForMatchFunction(ILogger<SquadMemberReadyForMatchFunction> logger, IHttpContextAccessor httpContextAccessor, IHubContext<CycleHub> hubContext, SquadService squadService, DbUserService userService)
|
|
{
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_logger = logger;
|
|
_hubContext = hubContext;
|
|
_squadService = squadService;
|
|
_userService = userService;
|
|
}
|
|
|
|
public async Task<SquadMemberReadyForMatchResponse> ExecuteAsync(SquadMemberReadyForMatchRequest request)
|
|
{
|
|
var context = _httpContextAccessor.HttpContext;
|
|
if (context == null)
|
|
{
|
|
throw new CloudScriptException("CloudScript was not called within a http request");
|
|
}
|
|
var userId = context.User.FindAuthUserId();
|
|
var squadId = string.IsNullOrEmpty(request.SquadID) ? userId : request.SquadID;
|
|
|
|
// Register the caller into the squad (party is formed client-side; each member's client
|
|
// calls this with the shared squadId) and record their readiness / selected map.
|
|
var displayName = (await _userService.FindByIdAsync(userId))?.DisplayName ?? "";
|
|
_squadService.JoinOrCreate(squadId, userId, displayName);
|
|
var ready = request.matchmakingSettings?.isReadyForMatch ?? false;
|
|
_squadService.SetReady(squadId, userId, ready, request.matchmakingSettings?.selectedMapName);
|
|
|
|
var squad = _squadService.Get(squadId)!;
|
|
var isSquadReady = _squadService.IsSquadReady(squadId);
|
|
_logger.LogInformation("SquadMemberReadyForMatch: {User} ready={Ready} in squad {Squad} ({Count} member(s), squadReady={SquadReady})",
|
|
userId, ready, squadId, squad.Members.Count, isSquadReady);
|
|
|
|
return new SquadMemberReadyForMatchResponse
|
|
{
|
|
Result = 0, // EYSquadActionResult::OK
|
|
Squad = _squadService.ToClientSquad(squad),
|
|
IsSquadReadyForMatch = isSquadReady,
|
|
};
|
|
}
|
|
}
|