|
2 | 2 | using Microsoft.AspNetCore.Authorization; |
3 | 3 | using Microsoft.AspNetCore.Mvc; |
4 | 4 |
|
| 5 | +using XtremeIdiots.Portal.Repository.Abstractions.Constants.V1; |
5 | 6 | using XtremeIdiots.Portal.Repository.Api.Client.V1; |
6 | 7 | using XtremeIdiots.Portal.Web.Auth.Constants; |
7 | 8 | using XtremeIdiots.Portal.Web.Extensions; |
@@ -70,7 +71,43 @@ public async Task<IActionResult> Index(CancellationToken cancellationToken = def |
70 | 71 | // Agent telemetry (non-critical — dashboard renders without it) |
71 | 72 | try |
72 | 73 | { |
73 | | - viewModel.AgentStatuses = await agentTelemetryService.GetAllServersStatusAsync(cancellationToken).ConfigureAwait(false); |
| 74 | + var telemetryTask = agentTelemetryService.GetAllServersStatusAsync(cancellationToken); |
| 75 | + var gameServersTask = repositoryApiClient.GameServers.V1.GetGameServers( |
| 76 | + null, null, GameServerFilter.AgentEnabled, 0, 100, |
| 77 | + GameServerOrder.BannerServerListPosition, cancellationToken); |
| 78 | + |
| 79 | + await Task.WhenAll(telemetryTask, gameServersTask).ConfigureAwait(false); |
| 80 | + |
| 81 | + var telemetry = await telemetryTask.ConfigureAwait(false); |
| 82 | + var gameServersResponse = await gameServersTask.ConfigureAwait(false); |
| 83 | + |
| 84 | + var serverLookup = gameServersResponse.IsSuccess && gameServersResponse.Result?.Data?.Items is not null |
| 85 | + ? gameServersResponse.Result.Data.Items |
| 86 | + .GroupBy(gs => gs.GameServerId) |
| 87 | + .ToDictionary(g => g.Key, g => g.First()) |
| 88 | + : []; |
| 89 | + |
| 90 | + // Enrich telemetry with server names from the repository API |
| 91 | + var telemetryByServer = telemetry |
| 92 | + .GroupBy(t => t.ServerId) |
| 93 | + .ToDictionary(g => g.Key, g => g.First()); |
| 94 | + viewModel.AgentStatuses = serverLookup.Values.Select(gs => |
| 95 | + { |
| 96 | + telemetryByServer.TryGetValue(gs.GameServerId, out var summary); |
| 97 | + |
| 98 | + return new AgentServerSummary |
| 99 | + { |
| 100 | + ServerId = gs.GameServerId, |
| 101 | + ServerTitle = string.IsNullOrWhiteSpace(gs.LiveTitle) ? gs.Title : gs.LiveTitle, |
| 102 | + GameType = gs.GameType.ToString(), |
| 103 | + LastEventReceived = summary?.LastEventReceived, |
| 104 | + EventsLastHour = summary?.EventsLastHour ?? 0, |
| 105 | + PlayerCount = summary?.PlayerCount ?? 0, |
| 106 | + CurrentMap = summary?.CurrentMap ?? gs.LiveMap, |
| 107 | + IsAgentActive = summary?.IsAgentActive ?? false, |
| 108 | + ActivityStatus = summary?.ActivityStatus ?? AgentActivityStatus.Offline |
| 109 | + }; |
| 110 | + }).ToList(); |
74 | 111 | } |
75 | 112 | catch (Exception ex) |
76 | 113 | { |
|
0 commit comments