add SystemInfoService, increase API to 3

This commit is contained in:
Stanley Dimant
2022-07-06 11:37:06 +02:00
parent 64f6380294
commit f307c9c486
7 changed files with 184 additions and 20 deletions

View File

@@ -1,6 +1,8 @@
using System.Linq;
using System;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Security.Claims;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using MareSynchronos.API;
using MareSynchronosServer.Data;
@@ -12,15 +14,19 @@ namespace MareSynchronosServer.Hubs
{
public class ConnectionHub : BaseHub<ConnectionHub>
{
public ConnectionHub(MareDbContext mareDbContext, ILogger<ConnectionHub> logger) : base(mareDbContext, logger)
private readonly SystemInfoService _systemInfoService;
public ConnectionHub(MareDbContext mareDbContext, ILogger<ConnectionHub> logger, SystemInfoService systemInfoService) : base(mareDbContext, logger)
{
_systemInfoService = systemInfoService;
}
[HubMethodName(ConnectionHubAPI.InvokeHeartbeat)]
public async Task<ConnectionDto> Heartbeat()
{
var userId = Context.User!.Claims.SingleOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
await Clients.Caller.SendAsync(ConnectionHubAPI.OnUpdateSystemInfo, _systemInfoService.SystemInfoDto);
if (userId != null)
{
@@ -37,5 +43,11 @@ namespace MareSynchronosServer.Hubs
return new ConnectionDto();
}
[HubMethodName(ConnectionHubAPI.InvokeGetSystemInfo)]
public async Task<SystemInfoDto> GetSystemInfo()
{
return _systemInfoService.SystemInfoDto;
}
}
}

View File

@@ -65,8 +65,6 @@ namespace MareSynchronosServer.Hubs
.Where(u => otherUsers.Any(e => e == u.User) && u.OtherUser == ownUser && !u.IsPaused).ToListAsync();
await Clients.Users(otherEntries.Select(e => e.User.UID)).SendAsync(UserHubAPI.OnAddOnlinePairedPlayer, ownUser.CharacterIdentification);
await Clients.All.SendAsync(UserHubAPI.OnUsersOnline,
await DbContext.Users.CountAsync(u => !string.IsNullOrEmpty(u.CharacterIdentification)));
return otherEntries.Select(e => e.User.CharacterIdentification).Distinct().ToList();
}
@@ -82,22 +80,22 @@ namespace MareSynchronosServer.Hubs
{
string userid = AuthenticatedUserId;
var user = GetAuthenticatedUser();
return DbContext.ClientPairs
var pairs = await DbContext.ClientPairs
.Include(u => u.OtherUser)
.Include(u => u.User)
.Where(w => w.User.UID == userid)
.ToList()
.Select(w =>
.ToListAsync();
return pairs.Select(w =>
{
var otherEntry = OppositeEntry(w.OtherUser.UID);
return new ClientPairDto
{
var otherEntry = OppositeEntry(w.OtherUser.UID);
return new ClientPairDto
{
IsPaused = w.IsPaused,
OtherUID = w.OtherUser.UID,
IsSynced = otherEntry != null,
IsPausedFromOthers = otherEntry?.IsPaused ?? false,
};
}).ToList();
IsPaused = w.IsPaused,
OtherUID = w.OtherUser.UID,
IsSynced = otherEntry != null,
IsPausedFromOthers = otherEntry?.IsPaused ?? false,
};
}).ToList();
}
public override async Task OnDisconnectedAsync(Exception exception)