move marehub to strong api usage (#14)
* move marehub to strong api usage * fix merge issues * latest api * further optimizations
This commit is contained in:
2
MareAPI
2
MareAPI
Submodule MareAPI updated: 1c3327f9bc...5db43c8e7a
@@ -19,8 +19,7 @@ public partial class MareHub
|
|||||||
private List<string> OnlineAdmins => _dbContext.Users.Where(u => (u.IsModerator || u.IsAdmin)).Select(u => u.UID).ToList();
|
private List<string> OnlineAdmins => _dbContext.Users.Where(u => (u.IsModerator || u.IsAdmin)).Select(u => u.UID).ToList();
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendAdminChangeModeratorStatus)]
|
public async Task AdminChangeModeratorStatus(string uid, bool isModerator)
|
||||||
public async Task ChangeModeratorStatus(string uid, bool isModerator)
|
|
||||||
{
|
{
|
||||||
if (!IsAdmin) return;
|
if (!IsAdmin) return;
|
||||||
var user = await _dbContext.Users.SingleOrDefaultAsync(u => u.UID == uid).ConfigureAwait(false);
|
var user = await _dbContext.Users.SingleOrDefaultAsync(u => u.UID == uid).ConfigureAwait(false);
|
||||||
@@ -30,12 +29,11 @@ public partial class MareHub
|
|||||||
user.IsModerator = isModerator;
|
user.IsModerator = isModerator;
|
||||||
_dbContext.Update(user);
|
_dbContext.Update(user);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
await Clients.Users(user.UID).SendAsync(Api.OnAdminForcedReconnect).ConfigureAwait(false);
|
await Clients.Users(user.UID).Client_AdminForcedReconnect().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendAdminDeleteBannedUser)]
|
public async Task AdminDeleteBannedUser(BannedUserDto dto)
|
||||||
public async Task DeleteBannedUser(BannedUserDto dto)
|
|
||||||
{
|
{
|
||||||
if (!IsModerator || string.IsNullOrEmpty(dto.CharacterHash)) return;
|
if (!IsModerator || string.IsNullOrEmpty(dto.CharacterHash)) return;
|
||||||
|
|
||||||
@@ -48,12 +46,11 @@ public partial class MareHub
|
|||||||
|
|
||||||
_dbContext.Remove(existingUser);
|
_dbContext.Remove(existingUser);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
await Clients.Users(OnlineAdmins).SendAsync(Api.OnAdminDeleteBannedUser, dto).ConfigureAwait(false);
|
await Clients.Users(OnlineAdmins).Client_AdminDeleteBannedUser(dto).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendAdminDeleteForbiddenFile)]
|
public async Task AdminDeleteForbiddenFile(ForbiddenFileDto dto)
|
||||||
public async Task DeleteForbiddenFile(ForbiddenFileDto dto)
|
|
||||||
{
|
{
|
||||||
if (!IsAdmin || string.IsNullOrEmpty(dto.Hash)) return;
|
if (!IsAdmin || string.IsNullOrEmpty(dto.Hash)) return;
|
||||||
|
|
||||||
@@ -66,12 +63,11 @@ public partial class MareHub
|
|||||||
|
|
||||||
_dbContext.Remove(existingFile);
|
_dbContext.Remove(existingFile);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
await Clients.Users(OnlineAdmins).SendAsync(Api.OnAdminDeleteForbiddenFile, dto).ConfigureAwait(false);
|
await Clients.Users(OnlineAdmins).Client_AdminDeleteForbiddenFile(dto).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeAdminGetBannedUsers)]
|
public async Task<List<BannedUserDto>> AdminGetBannedUsers()
|
||||||
public async Task<List<BannedUserDto>> GetBannedUsers()
|
|
||||||
{
|
{
|
||||||
if (!IsModerator) return null;
|
if (!IsModerator) return null;
|
||||||
|
|
||||||
@@ -83,8 +79,7 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeAdminGetForbiddenFiles)]
|
public async Task<List<ForbiddenFileDto>> AdminGetForbiddenFiles()
|
||||||
public async Task<List<ForbiddenFileDto>> GetForbiddenFiles()
|
|
||||||
{
|
{
|
||||||
if (!IsModerator) return null;
|
if (!IsModerator) return null;
|
||||||
|
|
||||||
@@ -96,7 +91,6 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeAdminGetOnlineUsers)]
|
|
||||||
public async Task<List<OnlineUserDto>> AdminGetOnlineUsers()
|
public async Task<List<OnlineUserDto>> AdminGetOnlineUsers()
|
||||||
{
|
{
|
||||||
if (!IsModerator) return null;
|
if (!IsModerator) return null;
|
||||||
@@ -112,8 +106,7 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendAdminUpdateOrAddBannedUser)]
|
public async Task AdminUpdateOrAddBannedUser(BannedUserDto dto)
|
||||||
public async Task UpdateOrAddBannedUser(BannedUserDto dto)
|
|
||||||
{
|
{
|
||||||
if (!IsModerator || string.IsNullOrEmpty(dto.CharacterHash)) return;
|
if (!IsModerator || string.IsNullOrEmpty(dto.CharacterHash)) return;
|
||||||
|
|
||||||
@@ -134,17 +127,16 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
await Clients.Users(OnlineAdmins).SendAsync(Api.OnAdminUpdateOrAddBannedUser, dto).ConfigureAwait(false);
|
await Clients.Users(OnlineAdmins).Client_AdminUpdateOrAddBannedUser(dto).ConfigureAwait(false);
|
||||||
var bannedUser = await _clientIdentService.GetUidForCharacterIdent(dto.CharacterHash).ConfigureAwait(false);
|
var bannedUser = await _clientIdentService.GetUidForCharacterIdent(dto.CharacterHash).ConfigureAwait(false);
|
||||||
if (!string.IsNullOrEmpty(bannedUser))
|
if (!string.IsNullOrEmpty(bannedUser))
|
||||||
{
|
{
|
||||||
await Clients.User(bannedUser).SendAsync(Api.OnAdminForcedReconnect).ConfigureAwait(false);
|
await Clients.User(bannedUser).Client_AdminForcedReconnect().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendAdminUpdateOrAddForbiddenFile)]
|
public async Task AdminUpdateOrAddForbiddenFile(ForbiddenFileDto dto)
|
||||||
public async Task UpdateOrAddForbiddenFile(ForbiddenFileDto dto)
|
|
||||||
{
|
{
|
||||||
if (!IsAdmin || string.IsNullOrEmpty(dto.Hash)) return;
|
if (!IsAdmin || string.IsNullOrEmpty(dto.Hash)) return;
|
||||||
|
|
||||||
@@ -166,6 +158,6 @@ public partial class MareHub
|
|||||||
|
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
await Clients.Users(OnlineAdmins).SendAsync(Api.OnAdminUpdateOrAddForbiddenFile, dto).ConfigureAwait(false);
|
await Clients.Users(OnlineAdmins).Client_AdminUpdateOrAddForbiddenFile(dto).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
using MareSynchronos.API;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MareSynchronosServer.Hubs
|
||||||
|
{
|
||||||
|
public partial class MareHub
|
||||||
|
{
|
||||||
|
public Task Client_UserUpdateClientPairs(ClientPairDto clientPairDto)
|
||||||
|
{
|
||||||
|
throw new PlatformNotSupportedException("Calling clientside method on server not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Client_UpdateSystemInfo(SystemInfoDto systemInfo)
|
||||||
|
{
|
||||||
|
throw new PlatformNotSupportedException("Calling clientside method on server not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Client_UserReceiveCharacterData(CharacterCacheDto clientPairDto, string characterIdent)
|
||||||
|
{
|
||||||
|
throw new PlatformNotSupportedException("Calling clientside method on server not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Client_UserChangePairedPlayer(string characterIdent, bool isOnline)
|
||||||
|
{
|
||||||
|
throw new PlatformNotSupportedException("Calling clientside method on server not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Client_GroupChange(GroupDto groupDto)
|
||||||
|
{
|
||||||
|
throw new PlatformNotSupportedException("Calling clientside method on server not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Client_GroupUserChange(GroupPairDto groupPairDto)
|
||||||
|
{
|
||||||
|
throw new PlatformNotSupportedException("Calling clientside method on server not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Client_AdminForcedReconnect()
|
||||||
|
{
|
||||||
|
throw new PlatformNotSupportedException("Calling clientside method on server not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Client_AdminDeleteBannedUser(BannedUserDto dto)
|
||||||
|
{
|
||||||
|
throw new PlatformNotSupportedException("Calling clientside method on server not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Client_AdminDeleteForbiddenFile(ForbiddenFileDto dto)
|
||||||
|
{
|
||||||
|
throw new PlatformNotSupportedException("Calling clientside method on server not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Client_AdminUpdateOrAddBannedUser(BannedUserDto dto)
|
||||||
|
{
|
||||||
|
throw new PlatformNotSupportedException("Calling clientside method on server not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Client_AdminUpdateOrAddForbiddenFile(ForbiddenFileDto dto)
|
||||||
|
{
|
||||||
|
throw new PlatformNotSupportedException("Calling clientside method on server not supported");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
|||||||
using Google.Protobuf;
|
using Google.Protobuf;
|
||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using MareSynchronos.API;
|
using MareSynchronos.API;
|
||||||
|
using MareSynchronosServer.Utils;
|
||||||
using MareSynchronosShared.Authentication;
|
using MareSynchronosShared.Authentication;
|
||||||
using MareSynchronosShared.Models;
|
using MareSynchronosShared.Models;
|
||||||
using MareSynchronosShared.Protos;
|
using MareSynchronosShared.Protos;
|
||||||
@@ -21,10 +22,9 @@ namespace MareSynchronosServer.Hubs;
|
|||||||
public partial class MareHub
|
public partial class MareHub
|
||||||
{
|
{
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendFileAbortUpload)]
|
public async Task FilesAbortUpload()
|
||||||
public async Task AbortUpload()
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendFileAbortUpload);
|
_logger.LogCallInfo();
|
||||||
var userId = AuthenticatedUserId;
|
var userId = AuthenticatedUserId;
|
||||||
var notUploadedFiles = _dbContext.Files.Where(f => !f.Uploaded && f.Uploader.UID == userId).ToList();
|
var notUploadedFiles = _dbContext.Files.Where(f => !f.Uploaded && f.Uploader.UID == userId).ToList();
|
||||||
_dbContext.RemoveRange(notUploadedFiles);
|
_dbContext.RemoveRange(notUploadedFiles);
|
||||||
@@ -32,10 +32,9 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendFileDeleteAllFiles)]
|
public async Task FilesDeleteAll()
|
||||||
public async Task DeleteAllFiles()
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendFileDeleteAllFiles);
|
_logger.LogCallInfo();
|
||||||
|
|
||||||
var ownFiles = await _dbContext.Files.Where(f => f.Uploaded && f.Uploader.UID == AuthenticatedUserId).ToListAsync().ConfigureAwait(false);
|
var ownFiles = await _dbContext.Files.Where(f => f.Uploaded && f.Uploader.UID == AuthenticatedUserId).ToListAsync().ConfigureAwait(false);
|
||||||
var request = new DeleteFilesRequest();
|
var request = new DeleteFilesRequest();
|
||||||
@@ -48,10 +47,9 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeGetFilesSizes)]
|
public async Task<List<DownloadFileDto>> FilesGetSizes(List<string> hashes)
|
||||||
public async Task<List<DownloadFileDto>> GetFilesSizes(List<string> hashes)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.InvokeGetFilesSizes, hashes.Count.ToString());
|
_logger.LogCallInfo(MareHubLogger.Args(hashes.Count.ToString()));
|
||||||
|
|
||||||
var allFiles = await _dbContext.Files.Where(f => hashes.Contains(f.Hash)).ToListAsync().ConfigureAwait(false);
|
var allFiles = await _dbContext.Files.Where(f => hashes.Contains(f.Hash)).ToListAsync().ConfigureAwait(false);
|
||||||
var forbiddenFiles = await _dbContext.ForbiddenUploadEntries.
|
var forbiddenFiles = await _dbContext.ForbiddenUploadEntries.
|
||||||
@@ -86,24 +84,22 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeFileIsUploadFinished)]
|
public async Task<bool> FilesIsUploadFinished()
|
||||||
public async Task<bool> IsUploadFinished()
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.InvokeFileIsUploadFinished);
|
_logger.LogCallInfo();
|
||||||
var userUid = AuthenticatedUserId;
|
var userUid = AuthenticatedUserId;
|
||||||
return await _dbContext.Files.AsNoTracking()
|
return await _dbContext.Files.AsNoTracking()
|
||||||
.AnyAsync(f => f.Uploader.UID == userUid && !f.Uploaded).ConfigureAwait(false);
|
.AnyAsync(f => f.Uploader.UID == userUid && !f.Uploaded).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeFileSendFiles)]
|
public async Task<List<UploadFileDto>> FilesSend(List<string> fileListHashes)
|
||||||
public async Task<List<UploadFileDto>> SendFiles(List<string> fileListHashes)
|
|
||||||
{
|
{
|
||||||
var userSentHashes = new HashSet<string>(fileListHashes.Distinct(StringComparer.Ordinal), StringComparer.Ordinal);
|
var userSentHashes = new HashSet<string>(fileListHashes.Distinct(StringComparer.Ordinal), StringComparer.Ordinal);
|
||||||
_logger.LogCallInfo(Api.InvokeFileSendFiles, userSentHashes.Count.ToString());
|
_logger.LogCallInfo(MareHubLogger.Args(userSentHashes.Count.ToString()));
|
||||||
var notCoveredFiles = new Dictionary<string, UploadFileDto>(StringComparer.Ordinal);
|
var notCoveredFiles = new Dictionary<string, UploadFileDto>(StringComparer.Ordinal);
|
||||||
var forbiddenFiles = await _dbContext.ForbiddenUploadEntries.AsNoTracking().Where(f => userSentHashes.Contains(f.Hash)).ToDictionaryAsync(f => f.Hash, f => f).ConfigureAwait(false);
|
var forbiddenFiles = await _dbContext.ForbiddenUploadEntries.AsNoTracking().Where(f => userSentHashes.Contains(f.Hash)).AsNoTracking().ToDictionaryAsync(f => f.Hash, f => f).ConfigureAwait(false);
|
||||||
var existingFiles = await _dbContext.Files.AsNoTracking().Where(f => userSentHashes.Contains(f.Hash)).ToDictionaryAsync(f => f.Hash, f => f).ConfigureAwait(false);
|
var existingFiles = await _dbContext.Files.AsNoTracking().Where(f => userSentHashes.Contains(f.Hash)).AsNoTracking().ToDictionaryAsync(f => f.Hash, f => f).ConfigureAwait(false);
|
||||||
var uploader = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false);
|
var uploader = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false);
|
||||||
|
|
||||||
List<FileCache> fileCachesToUpload = new();
|
List<FileCache> fileCachesToUpload = new();
|
||||||
@@ -125,7 +121,7 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
if (existingFiles.ContainsKey(file)) { continue; }
|
if (existingFiles.ContainsKey(file)) { continue; }
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.InvokeFileSendFiles, file, "Missing");
|
_logger.LogCallInfo(MareHubLogger.Args(file, "Missing"));
|
||||||
|
|
||||||
var userId = AuthenticatedUserId;
|
var userId = AuthenticatedUserId;
|
||||||
fileCachesToUpload.Add(new FileCache()
|
fileCachesToUpload.Add(new FileCache()
|
||||||
@@ -147,10 +143,9 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendFileUploadFileStreamAsync)]
|
public async Task FilesUploadStreamAsync(string hash, IAsyncEnumerable<byte[]> fileContent)
|
||||||
public async Task UploadFileStreamAsync(string hash, IAsyncEnumerable<byte[]> fileContent)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendFileUploadFileStreamAsync, hash);
|
_logger.LogCallInfo(MareHubLogger.Args(hash));
|
||||||
|
|
||||||
var relatedFile = _dbContext.Files.SingleOrDefault(f => f.Hash == hash && f.Uploader.UID == AuthenticatedUserId && !f.Uploaded);
|
var relatedFile = _dbContext.Files.SingleOrDefault(f => f.Hash == hash && f.Uploader.UID == AuthenticatedUserId && !f.Uploaded);
|
||||||
if (relatedFile == null) return;
|
if (relatedFile == null) return;
|
||||||
@@ -192,7 +187,7 @@ public partial class MareHub
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendFileUploadFileStreamAsync, hash, "Uploaded");
|
_logger.LogCallInfo(MareHubLogger.Args(hash, "Uploaded"));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -203,7 +198,7 @@ public partial class MareHub
|
|||||||
var computedHashString = BitConverter.ToString(computedHash).Replace("-", "", StringComparison.Ordinal);
|
var computedHashString = BitConverter.ToString(computedHash).Replace("-", "", StringComparison.Ordinal);
|
||||||
if (!string.Equals(hash, computedHashString, StringComparison.Ordinal))
|
if (!string.Equals(hash, computedHashString, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
_logger.LogCallWarning(Api.SendFileUploadFileStreamAsync, hash, "Invalid", computedHashString);
|
_logger.LogCallWarning(MareHubLogger.Args(hash, "Invalid", computedHashString));
|
||||||
_dbContext.Remove(relatedFile);
|
_dbContext.Remove(relatedFile);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
@@ -232,11 +227,11 @@ public partial class MareHub
|
|||||||
tempFileStream.Close();
|
tempFileStream.Close();
|
||||||
await tempFileStream.DisposeAsync().ConfigureAwait(false);
|
await tempFileStream.DisposeAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendFileUploadFileStreamAsync, hash, "Pushed");
|
_logger.LogCallInfo(MareHubLogger.Args(hash, "Pushed"));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogCallWarning(Api.SendFileUploadFileStreamAsync, "Failed", hash, ex.Message);
|
_logger.LogCallWarning(MareHubLogger.Args("Failed", hash, ex.Message));
|
||||||
_dbContext.Remove(relatedFile);
|
_dbContext.Remove(relatedFile);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public partial class MareHub
|
|||||||
GID = Convert.ToString(otherGroupPair.GroupGID),
|
GID = Convert.ToString(otherGroupPair.GroupGID),
|
||||||
PauseState = (userGroupPair.IsPaused || otherGroupPair.IsPaused)
|
PauseState = (userGroupPair.IsPaused || otherGroupPair.IsPaused)
|
||||||
})
|
})
|
||||||
).ToListAsync().ConfigureAwait(false);
|
).AsNoTracking().ToListAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
return query.GroupBy(g => g.UID, g => (g.GID, g.PauseState),
|
return query.GroupBy(g => g.UID, g => (g.GID, g.PauseState),
|
||||||
(key, g) => new PausedEntry
|
(key, g) => new PausedEntry
|
||||||
@@ -58,21 +58,24 @@ public partial class MareHub
|
|||||||
return ret.Where(k => !k.IsPaused).Select(k => k.UID).ToList();
|
return ret.Where(k => !k.IsPaused).Select(k => k.UID).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<List<string>> SendDataToAllPairedUsers(string apiMethod, object arg)
|
private async Task<List<string>> SendOnlineToAllPairedUsers(string arg)
|
||||||
{
|
{
|
||||||
var usersToSendDataTo = await GetAllPairedUnpausedUsers().ConfigureAwait(false);
|
var usersToSendDataTo = await GetAllPairedUnpausedUsers().ConfigureAwait(false);
|
||||||
await Clients.Users(usersToSendDataTo).SendAsync(apiMethod, arg).ConfigureAwait(false);
|
await Clients.Users(usersToSendDataTo).Client_UserChangePairedPlayer(arg, true).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return usersToSendDataTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<List<string>> SendOfflineToAllPairedUsers(string arg)
|
||||||
|
{
|
||||||
|
var usersToSendDataTo = await GetAllPairedUnpausedUsers().ConfigureAwait(false);
|
||||||
|
await Clients.Users(usersToSendDataTo).Client_UserChangePairedPlayer(arg, false).ConfigureAwait(false);
|
||||||
|
|
||||||
return usersToSendDataTo;
|
return usersToSendDataTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string AuthenticatedUserId => Context.User?.Claims?.SingleOrDefault(c => string.Equals(c.Type, ClaimTypes.NameIdentifier, StringComparison.Ordinal))?.Value ?? "Unknown";
|
public string AuthenticatedUserId => Context.User?.Claims?.SingleOrDefault(c => string.Equals(c.Type, ClaimTypes.NameIdentifier, StringComparison.Ordinal))?.Value ?? "Unknown";
|
||||||
|
|
||||||
protected async Task<User> GetAuthenticatedUserUntrackedAsync()
|
|
||||||
{
|
|
||||||
return await _dbContext.Users.AsNoTrackingWithIdentityResolution().SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task UserGroupLeave(GroupPair groupUserPair, List<PausedEntry> allUserPairs, string userIdent, string? uid = null)
|
private async Task UserGroupLeave(GroupPair groupUserPair, List<PausedEntry> allUserPairs, string userIdent, string? uid = null)
|
||||||
{
|
{
|
||||||
uid ??= AuthenticatedUserId;
|
uid ??= AuthenticatedUserId;
|
||||||
@@ -86,8 +89,8 @@ public partial class MareHub
|
|||||||
var groupUserIdent = await _clientIdentService.GetCharacterIdentForUid(groupUserPair.GroupUserUID).ConfigureAwait(false);
|
var groupUserIdent = await _clientIdentService.GetCharacterIdentForUid(groupUserPair.GroupUserUID).ConfigureAwait(false);
|
||||||
if (!string.IsNullOrEmpty(groupUserIdent))
|
if (!string.IsNullOrEmpty(groupUserIdent))
|
||||||
{
|
{
|
||||||
await Clients.User(uid).SendAsync(Api.OnUserRemoveOnlinePairedPlayer, groupUserIdent).ConfigureAwait(false);
|
await Clients.User(uid).Client_UserChangePairedPlayer(groupUserIdent, false).ConfigureAwait(false);
|
||||||
await Clients.User(groupUserPair.GroupUserUID).SendAsync(Api.OnUserRemoveOnlinePairedPlayer, userIdent).ConfigureAwait(false);
|
await Clients.User(groupUserPair.GroupUserUID).Client_UserChangePairedPlayer(userIdent, false).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,11 @@ namespace MareSynchronosServer.Hubs;
|
|||||||
public partial class MareHub
|
public partial class MareHub
|
||||||
{
|
{
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeGroupCreate)]
|
public async Task<GroupCreatedDto> GroupCreate()
|
||||||
public async Task<GroupCreatedDto> CreateGroup()
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.InvokeGroupCreate);
|
_logger.LogCallInfo();
|
||||||
var existingGroupsByUser = _dbContext.Groups.Count(u => u.OwnerUID == AuthenticatedUserId);
|
var existingGroupsByUser = await _dbContext.Groups.CountAsync(u => u.OwnerUID == AuthenticatedUserId).ConfigureAwait(false);
|
||||||
var existingJoinedGroups = _dbContext.GroupPairs.Count(u => u.GroupUserUID == AuthenticatedUserId);
|
var existingJoinedGroups = await _dbContext.GroupPairs.CountAsync(u => u.GroupUserUID == AuthenticatedUserId).ConfigureAwait(false);
|
||||||
if (existingGroupsByUser >= _maxExistingGroupsByUser || existingJoinedGroups >= _maxJoinedGroupsByUser)
|
if (existingGroupsByUser >= _maxExistingGroupsByUser || existingJoinedGroups >= _maxJoinedGroupsByUser)
|
||||||
{
|
{
|
||||||
throw new System.Exception($"Max groups for user is {_maxExistingGroupsByUser}, max joined groups is {_maxJoinedGroupsByUser}.");
|
throw new System.Exception($"Max groups for user is {_maxExistingGroupsByUser}, max joined groups is {_maxJoinedGroupsByUser}.");
|
||||||
@@ -59,9 +58,9 @@ public partial class MareHub
|
|||||||
await _dbContext.GroupPairs.AddAsync(initialPair).ConfigureAwait(false);
|
await _dbContext.GroupPairs.AddAsync(initialPair).ConfigureAwait(false);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
var self = _dbContext.Users.Single(u => u.UID == AuthenticatedUserId);
|
var self = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false);
|
||||||
|
|
||||||
await Clients.User(AuthenticatedUserId).SendAsync(Api.OnGroupChange, new GroupDto()
|
await Clients.User(AuthenticatedUserId).Client_GroupChange(new GroupDto()
|
||||||
{
|
{
|
||||||
GID = newGroup.GID,
|
GID = newGroup.GID,
|
||||||
OwnedBy = string.IsNullOrEmpty(self.Alias) ? self.UID : self.Alias,
|
OwnedBy = string.IsNullOrEmpty(self.Alias) ? self.UID : self.Alias,
|
||||||
@@ -70,7 +69,7 @@ public partial class MareHub
|
|||||||
InvitesEnabled = true
|
InvitesEnabled = true
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.InvokeGroupCreate, gid);
|
_logger.LogCallInfo(MareHubLogger.Args(gid));
|
||||||
|
|
||||||
return new GroupCreatedDto()
|
return new GroupCreatedDto()
|
||||||
{
|
{
|
||||||
@@ -80,12 +79,11 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeGroupGetGroups)]
|
public async Task<List<GroupDto>> GroupsGetAll()
|
||||||
public async Task<List<GroupDto>> GetGroups()
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.InvokeGroupGetGroups);
|
_logger.LogCallInfo();
|
||||||
|
|
||||||
var groups = await _dbContext.GroupPairs.Include(g => g.Group).Include(g => g.Group.Owner).Where(g => g.GroupUserUID == AuthenticatedUserId).ToListAsync().ConfigureAwait(false);
|
var groups = await _dbContext.GroupPairs.Include(g => g.Group).Include(g => g.Group.Owner).Where(g => g.GroupUserUID == AuthenticatedUserId).AsNoTracking().ToListAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
return groups.Select(g => new GroupDto()
|
return groups.Select(g => new GroupDto()
|
||||||
{
|
{
|
||||||
@@ -99,15 +97,14 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeGroupGetUsersInGroup)]
|
public async Task<List<GroupPairDto>> GroupsGetUsersInGroup(string gid)
|
||||||
public async Task<List<GroupPairDto>> GetUsersInGroup(string gid)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.InvokeGroupGetUsersInGroup, gid);
|
_logger.LogCallInfo(MareHubLogger.Args(gid));
|
||||||
|
|
||||||
var (inGroup, _) = await TryValidateUserInGroup(gid).ConfigureAwait(false);
|
var (inGroup, _) = await TryValidateUserInGroup(gid).ConfigureAwait(false);
|
||||||
if (!inGroup) return new List<GroupPairDto>();
|
if (!inGroup) return new List<GroupPairDto>();
|
||||||
|
|
||||||
var allPairs = await _dbContext.GroupPairs.Include(g => g.GroupUser).Where(g => g.GroupGID == gid && g.GroupUserUID != AuthenticatedUserId).ToListAsync().ConfigureAwait(false);
|
var allPairs = await _dbContext.GroupPairs.Include(g => g.GroupUser).Where(g => g.GroupGID == gid && g.GroupUserUID != AuthenticatedUserId).AsNoTracking().ToListAsync().ConfigureAwait(false);
|
||||||
return allPairs.Select(p => new GroupPairDto()
|
return allPairs.Select(p => new GroupPairDto()
|
||||||
{
|
{
|
||||||
GroupGID = gid,
|
GroupGID = gid,
|
||||||
@@ -121,10 +118,9 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendGroupChangeInviteState)]
|
|
||||||
public async Task GroupChangeInviteState(string gid, bool enabled)
|
public async Task GroupChangeInviteState(string gid, bool enabled)
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendGroupChangeInviteState, gid, enabled.ToString());
|
_logger.LogCallInfo(MareHubLogger.Args(gid, enabled.ToString()));
|
||||||
|
|
||||||
var (hasRights, group) = await TryValidateOwner(gid).ConfigureAwait(false);
|
var (hasRights, group) = await TryValidateOwner(gid).ConfigureAwait(false);
|
||||||
if (!hasRights) return;
|
if (!hasRights) return;
|
||||||
@@ -132,10 +128,10 @@ public partial class MareHub
|
|||||||
group.InvitesEnabled = enabled;
|
group.InvitesEnabled = enabled;
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendGroupChangeInviteState, gid, enabled.ToString(), "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, enabled.ToString(), "Success"));
|
||||||
|
|
||||||
var groupPairs = _dbContext.GroupPairs.Where(p => p.GroupGID == gid).Select(p => p.GroupUserUID).ToList();
|
var groupPairs = _dbContext.GroupPairs.Where(p => p.GroupGID == gid).Select(p => p.GroupUserUID).ToList();
|
||||||
await Clients.Users(groupPairs).SendAsync(Api.OnGroupChange, new GroupDto()
|
await Clients.Users(groupPairs).Client_GroupChange(new GroupDto()
|
||||||
{
|
{
|
||||||
GID = gid,
|
GID = gid,
|
||||||
InvitesEnabled = enabled,
|
InvitesEnabled = enabled,
|
||||||
@@ -143,21 +139,20 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendGroupDelete)]
|
|
||||||
public async Task GroupDelete(string gid)
|
public async Task GroupDelete(string gid)
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendGroupDelete, gid);
|
_logger.LogCallInfo(MareHubLogger.Args(gid));
|
||||||
|
|
||||||
var (hasRights, group) = await TryValidateOwner(gid).ConfigureAwait(false);
|
var (hasRights, group) = await TryValidateOwner(gid).ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendGroupDelete, gid, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, "Success"));
|
||||||
|
|
||||||
var groupPairs = await _dbContext.GroupPairs.Where(p => p.GroupGID == gid).ToListAsync().ConfigureAwait(false);
|
var groupPairs = await _dbContext.GroupPairs.Where(p => p.GroupGID == gid).ToListAsync().ConfigureAwait(false);
|
||||||
_dbContext.RemoveRange(groupPairs);
|
_dbContext.RemoveRange(groupPairs);
|
||||||
_dbContext.Remove(group);
|
_dbContext.Remove(group);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
await Clients.Users(groupPairs.Select(g => g.GroupUserUID)).SendAsync(Api.OnGroupChange, new GroupDto()
|
await Clients.Users(groupPairs.Select(g => g.GroupUserUID)).Client_GroupChange(new GroupDto()
|
||||||
{
|
{
|
||||||
GID = group.GID,
|
GID = group.GID,
|
||||||
IsDeleted = true,
|
IsDeleted = true,
|
||||||
@@ -168,15 +163,14 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeGroupJoin)]
|
|
||||||
public async Task<bool> GroupJoin(string gid, string password)
|
public async Task<bool> GroupJoin(string gid, string password)
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.InvokeGroupJoin, gid);
|
_logger.LogCallInfo(MareHubLogger.Args(gid));
|
||||||
|
|
||||||
var group = await _dbContext.Groups.Include(g => g.Owner).SingleOrDefaultAsync(g => g.GID == gid || g.Alias == gid).ConfigureAwait(false);
|
var group = await _dbContext.Groups.Include(g => g.Owner).AsNoTracking().SingleOrDefaultAsync(g => g.GID == gid || g.Alias == gid).ConfigureAwait(false);
|
||||||
var existingPair = await _dbContext.GroupPairs.SingleOrDefaultAsync(g => g.GroupGID == gid && g.GroupUserUID == AuthenticatedUserId).ConfigureAwait(false);
|
var existingPair = await _dbContext.GroupPairs.AsNoTracking().SingleOrDefaultAsync(g => g.GroupGID == gid && g.GroupUserUID == AuthenticatedUserId).ConfigureAwait(false);
|
||||||
var hashedPw = StringUtils.Sha256String(password);
|
var hashedPw = StringUtils.Sha256String(password);
|
||||||
var existingUserCount = await _dbContext.GroupPairs.CountAsync(g => g.GroupGID == gid).ConfigureAwait(false);
|
var existingUserCount = await _dbContext.GroupPairs.AsNoTracking().CountAsync(g => g.GroupGID == gid).ConfigureAwait(false);
|
||||||
var joinedGroups = await _dbContext.GroupPairs.CountAsync(g => g.GroupUserUID == AuthenticatedUserId).ConfigureAwait(false);
|
var joinedGroups = await _dbContext.GroupPairs.CountAsync(g => g.GroupUserUID == AuthenticatedUserId).ConfigureAwait(false);
|
||||||
var isBanned = await _dbContext.GroupBans.AnyAsync(g => g.GroupGID == gid && g.BannedUserUID == AuthenticatedUserId).ConfigureAwait(false);
|
var isBanned = await _dbContext.GroupBans.AnyAsync(g => g.GroupGID == gid && g.BannedUserUID == AuthenticatedUserId).ConfigureAwait(false);
|
||||||
|
|
||||||
@@ -198,9 +192,9 @@ public partial class MareHub
|
|||||||
await _dbContext.GroupPairs.AddAsync(newPair).ConfigureAwait(false);
|
await _dbContext.GroupPairs.AddAsync(newPair).ConfigureAwait(false);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.InvokeGroupJoin, gid, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, "Success"));
|
||||||
|
|
||||||
await Clients.User(AuthenticatedUserId).SendAsync(Api.OnGroupChange, new GroupDto()
|
await Clients.User(AuthenticatedUserId).Client_GroupChange(new GroupDto()
|
||||||
{
|
{
|
||||||
GID = group.GID,
|
GID = group.GID,
|
||||||
OwnedBy = string.IsNullOrEmpty(group.Owner.Alias) ? group.Owner.UID : group.Owner.Alias,
|
OwnedBy = string.IsNullOrEmpty(group.Owner.Alias) ? group.Owner.UID : group.Owner.Alias,
|
||||||
@@ -213,7 +207,7 @@ public partial class MareHub
|
|||||||
var self = _dbContext.Users.Single(u => u.UID == AuthenticatedUserId);
|
var self = _dbContext.Users.Single(u => u.UID == AuthenticatedUserId);
|
||||||
|
|
||||||
var groupPairs = await _dbContext.GroupPairs.Where(p => p.GroupGID == group.GID && p.GroupUserUID != AuthenticatedUserId).ToListAsync().ConfigureAwait(false);
|
var groupPairs = await _dbContext.GroupPairs.Where(p => p.GroupGID == group.GID && p.GroupUserUID != AuthenticatedUserId).ToListAsync().ConfigureAwait(false);
|
||||||
await Clients.Users(groupPairs.Select(p => p.GroupUserUID)).SendAsync(Api.OnGroupUserChange, new GroupPairDto()
|
await Clients.Users(groupPairs.Select(p => p.GroupUserUID)).Client_GroupUserChange(new GroupPairDto()
|
||||||
{
|
{
|
||||||
GroupGID = group.GID,
|
GroupGID = group.GID,
|
||||||
IsPaused = false,
|
IsPaused = false,
|
||||||
@@ -237,8 +231,8 @@ public partial class MareHub
|
|||||||
var groupUserIdent = await _clientIdentService.GetCharacterIdentForUid(groupUserPair.GroupUserUID).ConfigureAwait(false);
|
var groupUserIdent = await _clientIdentService.GetCharacterIdentForUid(groupUserPair.GroupUserUID).ConfigureAwait(false);
|
||||||
if (!string.IsNullOrEmpty(groupUserIdent))
|
if (!string.IsNullOrEmpty(groupUserIdent))
|
||||||
{
|
{
|
||||||
await Clients.User(AuthenticatedUserId).SendAsync(Api.OnUserAddOnlinePairedPlayer, groupUserIdent).ConfigureAwait(false);
|
await Clients.User(AuthenticatedUserId).Client_UserChangePairedPlayer(groupUserIdent, true).ConfigureAwait(false);
|
||||||
await Clients.User(groupUserPair.GroupUserUID).SendAsync(Api.OnUserAddOnlinePairedPlayer, userIdent).ConfigureAwait(false);
|
await Clients.User(groupUserPair.GroupUserUID).Client_UserChangePairedPlayer(userIdent, true).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,10 +240,9 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendGroupLeave)]
|
|
||||||
public async Task GroupLeave(string gid)
|
public async Task GroupLeave(string gid)
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendGroupLeave, gid);
|
_logger.LogCallInfo(MareHubLogger.Args(gid));
|
||||||
|
|
||||||
var (exists, groupPair) = await TryValidateUserInGroup(gid).ConfigureAwait(false);
|
var (exists, groupPair) = await TryValidateUserInGroup(gid).ConfigureAwait(false);
|
||||||
if (!exists) return;
|
if (!exists) return;
|
||||||
@@ -262,7 +255,7 @@ public partial class MareHub
|
|||||||
_dbContext.GroupPairs.Remove(groupPair);
|
_dbContext.GroupPairs.Remove(groupPair);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
await Clients.User(AuthenticatedUserId).SendAsync(Api.OnGroupChange, new GroupDto()
|
await Clients.User(AuthenticatedUserId).Client_GroupChange(new GroupDto()
|
||||||
{
|
{
|
||||||
GID = group.GID,
|
GID = group.GID,
|
||||||
IsDeleted = true
|
IsDeleted = true
|
||||||
@@ -273,7 +266,7 @@ public partial class MareHub
|
|||||||
{
|
{
|
||||||
if (!groupPairsWithoutSelf.Any())
|
if (!groupPairsWithoutSelf.Any())
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendGroupLeave, gid, "Deleted");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, "Deleted"));
|
||||||
|
|
||||||
_dbContext.Remove(group);
|
_dbContext.Remove(group);
|
||||||
}
|
}
|
||||||
@@ -283,9 +276,9 @@ public partial class MareHub
|
|||||||
|
|
||||||
if (groupHasMigrated.Item1)
|
if (groupHasMigrated.Item1)
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendGroupLeave, gid, "Migrated", groupHasMigrated.Item2);
|
_logger.LogCallInfo(MareHubLogger.Args(gid, "Migrated", groupHasMigrated.Item2));
|
||||||
|
|
||||||
await Clients.Users(groupPairsWithoutSelf.Select(p => p.GroupUserUID)).SendAsync(Api.OnGroupChange, new GroupDto()
|
await Clients.Users(groupPairsWithoutSelf.Select(p => p.GroupUserUID)).Client_GroupChange(new GroupDto()
|
||||||
{
|
{
|
||||||
GID = group.GID,
|
GID = group.GID,
|
||||||
OwnedBy = groupHasMigrated.Item2,
|
OwnedBy = groupHasMigrated.Item2,
|
||||||
@@ -294,9 +287,9 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendGroupLeave, gid, "Deleted");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, "Deleted"));
|
||||||
|
|
||||||
await Clients.Users(groupPairsWithoutSelf.Select(p => p.GroupUserUID)).SendAsync(Api.OnGroupChange, new GroupDto()
|
await Clients.Users(groupPairsWithoutSelf.Select(p => p.GroupUserUID)).Client_GroupChange(new GroupDto()
|
||||||
{
|
{
|
||||||
GID = group.GID,
|
GID = group.GID,
|
||||||
IsDeleted = true
|
IsDeleted = true
|
||||||
@@ -311,9 +304,9 @@ public partial class MareHub
|
|||||||
|
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendGroupLeave, gid, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, "Success"));
|
||||||
|
|
||||||
await Clients.Users(groupPairsWithoutSelf.Select(p => p.GroupUserUID)).SendAsync(Api.OnGroupUserChange, new GroupPairDto()
|
await Clients.Users(groupPairsWithoutSelf.Select(p => p.GroupUserUID)).Client_GroupUserChange(new GroupPairDto()
|
||||||
{
|
{
|
||||||
GroupGID = group.GID,
|
GroupGID = group.GID,
|
||||||
IsRemoved = true,
|
IsRemoved = true,
|
||||||
@@ -330,10 +323,9 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendGroupPause)]
|
|
||||||
public async Task GroupChangePauseState(string gid, bool isPaused)
|
public async Task GroupChangePauseState(string gid, bool isPaused)
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendGroupPause, gid, isPaused);
|
_logger.LogCallInfo(MareHubLogger.Args(gid, isPaused));
|
||||||
|
|
||||||
var (exists, groupPair) = await TryValidateUserInGroup(gid).ConfigureAwait(false);
|
var (exists, groupPair) = await TryValidateUserInGroup(gid).ConfigureAwait(false);
|
||||||
if (!exists) return;
|
if (!exists) return;
|
||||||
@@ -341,17 +333,17 @@ public partial class MareHub
|
|||||||
groupPair.IsPaused = isPaused;
|
groupPair.IsPaused = isPaused;
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendGroupPause, gid, isPaused, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, isPaused, "Success"));
|
||||||
|
|
||||||
var groupPairs = await _dbContext.GroupPairs.Where(p => p.GroupGID == gid && p.GroupUserUID != AuthenticatedUserId).ToListAsync().ConfigureAwait(false);
|
var groupPairs = await _dbContext.GroupPairs.Where(p => p.GroupGID == gid && p.GroupUserUID != AuthenticatedUserId).AsNoTracking().ToListAsync().ConfigureAwait(false);
|
||||||
await Clients.Users(groupPairs.Select(p => p.GroupUserUID)).SendAsync(Api.OnGroupUserChange, new GroupPairDto()
|
await Clients.Users(groupPairs.Select(p => p.GroupUserUID)).Client_GroupUserChange(new GroupPairDto()
|
||||||
{
|
{
|
||||||
GroupGID = gid,
|
GroupGID = gid,
|
||||||
IsPaused = isPaused,
|
IsPaused = isPaused,
|
||||||
UserUID = AuthenticatedUserId,
|
UserUID = AuthenticatedUserId,
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
await Clients.User(AuthenticatedUserId).SendAsync(Api.OnGroupChange, new GroupDto
|
await Clients.User(AuthenticatedUserId).Client_GroupChange(new GroupDto
|
||||||
{
|
{
|
||||||
GID = gid,
|
GID = gid,
|
||||||
IsPaused = isPaused
|
IsPaused = isPaused
|
||||||
@@ -372,17 +364,16 @@ public partial class MareHub
|
|||||||
var groupUserIdent = await _clientIdentService.GetCharacterIdentForUid(groupUserPair.GroupUserUID).ConfigureAwait(false);
|
var groupUserIdent = await _clientIdentService.GetCharacterIdentForUid(groupUserPair.GroupUserUID).ConfigureAwait(false);
|
||||||
if (!string.IsNullOrEmpty(groupUserIdent))
|
if (!string.IsNullOrEmpty(groupUserIdent))
|
||||||
{
|
{
|
||||||
await Clients.User(AuthenticatedUserId).SendAsync(isPaused ? Api.OnUserRemoveOnlinePairedPlayer : Api.OnUserAddOnlinePairedPlayer, groupUserIdent).ConfigureAwait(false);
|
await Clients.User(AuthenticatedUserId).Client_UserChangePairedPlayer(groupUserIdent, !isPaused).ConfigureAwait(false);
|
||||||
await Clients.User(groupUserPair.GroupUserUID).SendAsync(isPaused ? Api.OnUserRemoveOnlinePairedPlayer : Api.OnUserAddOnlinePairedPlayer, userIdent).ConfigureAwait(false);
|
await Clients.User(groupUserPair.GroupUserUID).Client_UserChangePairedPlayer(userIdent, !isPaused).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendGroupRemoveUser)]
|
|
||||||
public async Task GroupRemoveUser(string gid, string uid)
|
public async Task GroupRemoveUser(string gid, string uid)
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendGroupRemoveUser, gid, uid);
|
_logger.LogCallInfo(MareHubLogger.Args(gid, uid));
|
||||||
|
|
||||||
var (hasRights, group) = await TryValidateGroupModeratorOrOwner(gid).ConfigureAwait(false);
|
var (hasRights, group) = await TryValidateGroupModeratorOrOwner(gid).ConfigureAwait(false);
|
||||||
if (!hasRights) return;
|
if (!hasRights) return;
|
||||||
@@ -391,14 +382,13 @@ public partial class MareHub
|
|||||||
if (!userExists) return;
|
if (!userExists) return;
|
||||||
|
|
||||||
if (groupPair.IsModerator || string.Equals(group.OwnerUID, uid, StringComparison.Ordinal)) return;
|
if (groupPair.IsModerator || string.Equals(group.OwnerUID, uid, StringComparison.Ordinal)) return;
|
||||||
|
_logger.LogCallInfo(MareHubLogger.Args(gid, uid, "Success"));
|
||||||
_logger.LogCallInfo(Api.SendGroupRemoveUser, gid, uid, "Success");
|
|
||||||
|
|
||||||
_dbContext.GroupPairs.Remove(groupPair);
|
_dbContext.GroupPairs.Remove(groupPair);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
var groupPairs = _dbContext.GroupPairs.Where(p => p.GroupGID == group.GID).ToList();
|
var groupPairs = _dbContext.GroupPairs.Where(p => p.GroupGID == group.GID).AsNoTracking().ToList();
|
||||||
await Clients.Users(groupPairs.Select(p => p.GroupUserUID)).SendAsync(Api.OnGroupUserChange, new GroupPairDto()
|
await Clients.Users(groupPairs.Select(p => p.GroupUserUID)).Client_GroupUserChange(new GroupPairDto()
|
||||||
{
|
{
|
||||||
GroupGID = group.GID,
|
GroupGID = group.GID,
|
||||||
IsRemoved = true,
|
IsRemoved = true,
|
||||||
@@ -408,7 +398,7 @@ public partial class MareHub
|
|||||||
var userIdent = await _clientIdentService.GetCharacterIdentForUid(uid).ConfigureAwait(false);
|
var userIdent = await _clientIdentService.GetCharacterIdentForUid(uid).ConfigureAwait(false);
|
||||||
if (userIdent == null) return;
|
if (userIdent == null) return;
|
||||||
|
|
||||||
await Clients.User(uid).SendAsync(Api.OnGroupChange, new GroupDto()
|
await Clients.User(uid).Client_GroupChange(new GroupDto()
|
||||||
{
|
{
|
||||||
GID = gid,
|
GID = gid,
|
||||||
IsDeleted = true,
|
IsDeleted = true,
|
||||||
@@ -423,10 +413,9 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendBanUserFromGroup)]
|
|
||||||
public async Task GroupBanUser(string gid, string uid, string reason)
|
public async Task GroupBanUser(string gid, string uid, string reason)
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendBanUserFromGroup, gid, uid);
|
_logger.LogCallInfo(MareHubLogger.Args(gid, uid));
|
||||||
|
|
||||||
var (userHasRights, group) = await TryValidateGroupModeratorOrOwner(gid).ConfigureAwait(false);
|
var (userHasRights, group) = await TryValidateGroupModeratorOrOwner(gid).ConfigureAwait(false);
|
||||||
if (!userHasRights) return;
|
if (!userHasRights) return;
|
||||||
@@ -451,14 +440,13 @@ public partial class MareHub
|
|||||||
|
|
||||||
await GroupRemoveUser(gid, uid).ConfigureAwait(false);
|
await GroupRemoveUser(gid, uid).ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendBanUserFromGroup, gid, uid, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, uid, "Success"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendUnbanUserFromGroup)]
|
|
||||||
public async Task GroupUnbanUser(string gid, string uid)
|
public async Task GroupUnbanUser(string gid, string uid)
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendUnbanUserFromGroup, gid, uid);
|
_logger.LogCallInfo(MareHubLogger.Args(gid, uid));
|
||||||
|
|
||||||
var (userHasRights, _) = await TryValidateGroupModeratorOrOwner(gid).ConfigureAwait(false);
|
var (userHasRights, _) = await TryValidateGroupModeratorOrOwner(gid).ConfigureAwait(false);
|
||||||
if (!userHasRights) return;
|
if (!userHasRights) return;
|
||||||
@@ -469,19 +457,18 @@ public partial class MareHub
|
|||||||
_dbContext.Remove(banEntry);
|
_dbContext.Remove(banEntry);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendUnbanUserFromGroup, gid, uid, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, uid, "Success"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeGetBannedUsersForGroup)]
|
public async Task<List<BannedGroupUserDto>> GroupGetBannedUsers(string gid)
|
||||||
public async Task<List<BannedGroupUserDto>> GetGroupBannedUsers(string gid)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.InvokeGetBannedUsersForGroup, gid);
|
_logger.LogCallInfo(MareHubLogger.Args(gid));
|
||||||
|
|
||||||
var (userHasRights, _) = await TryValidateGroupModeratorOrOwner(gid).ConfigureAwait(false);
|
var (userHasRights, _) = await TryValidateGroupModeratorOrOwner(gid).ConfigureAwait(false);
|
||||||
if (!userHasRights) return new List<BannedGroupUserDto>();
|
if (!userHasRights) return new List<BannedGroupUserDto>();
|
||||||
|
|
||||||
var banEntries = await _dbContext.GroupBans.Where(g => g.GroupGID == gid).ToListAsync().ConfigureAwait(false);
|
var banEntries = await _dbContext.GroupBans.Where(g => g.GroupGID == gid).AsNoTracking().ToListAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
List<BannedGroupUserDto> bannedGroupUsers = banEntries.Select(b => new BannedGroupUserDto()
|
List<BannedGroupUserDto> bannedGroupUsers = banEntries.Select(b => new BannedGroupUserDto()
|
||||||
{
|
{
|
||||||
@@ -492,16 +479,15 @@ public partial class MareHub
|
|||||||
|
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.InvokeGetBannedUsersForGroup, gid, bannedGroupUsers.Count);
|
_logger.LogCallInfo(MareHubLogger.Args(gid, bannedGroupUsers.Count));
|
||||||
|
|
||||||
return bannedGroupUsers;
|
return bannedGroupUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendGroupSetModerator)]
|
public async Task GroupSetModerator(string gid, string uid, bool isGroupModerator)
|
||||||
public async Task SetModerator(string gid, string uid, bool isGroupModerator)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendGroupSetModerator, gid, uid, isGroupModerator);
|
_logger.LogCallInfo(MareHubLogger.Args(gid, uid, isGroupModerator));
|
||||||
|
|
||||||
var (userHasRights, _) = await TryValidateOwner(gid).ConfigureAwait(false);
|
var (userHasRights, _) = await TryValidateOwner(gid).ConfigureAwait(false);
|
||||||
if (!userHasRights) return;
|
if (!userHasRights) return;
|
||||||
@@ -512,30 +498,29 @@ public partial class MareHub
|
|||||||
userPair.IsModerator = isGroupModerator;
|
userPair.IsModerator = isGroupModerator;
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
var groupPairs = await _dbContext.GroupPairs.Where(g => g.GroupGID == gid).ToListAsync().ConfigureAwait(false);
|
var groupPairs = await _dbContext.GroupPairs.Where(g => g.GroupGID == gid).AsNoTracking().ToListAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
await Clients.User(uid).SendAsync(Api.OnGroupChange, new GroupDto()
|
await Clients.User(uid).Client_GroupChange(new GroupDto()
|
||||||
{
|
{
|
||||||
GID = gid,
|
GID = gid,
|
||||||
IsModerator = isGroupModerator
|
IsModerator = isGroupModerator
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
await Clients.Users(groupPairs.Where(p => !string.Equals(p.GroupUserUID, uid, StringComparison.Ordinal))
|
await Clients.Users(groupPairs.Where(p => !string.Equals(p.GroupUserUID, uid, StringComparison.Ordinal))
|
||||||
.Select(g => g.GroupUserUID)).SendAsync(Api.OnGroupUserChange, new GroupPairDto()
|
.Select(g => g.GroupUserUID)).Client_GroupUserChange(new GroupPairDto()
|
||||||
{
|
{
|
||||||
GroupGID = gid,
|
GroupGID = gid,
|
||||||
IsModerator = isGroupModerator,
|
IsModerator = isGroupModerator,
|
||||||
UserUID = uid
|
UserUID = uid
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendGroupSetModerator, gid, uid, isGroupModerator, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, uid, isGroupModerator, "Success"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendGroupChangeOwner)]
|
public async Task GroupChangeOwnership(string gid, string uid)
|
||||||
public async Task ChangeOwnership(string gid, string uid)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendGroupChangeOwner, gid, uid);
|
_logger.LogCallInfo(MareHubLogger.Args(gid, uid));
|
||||||
|
|
||||||
var (isOwner, group) = await TryValidateOwner(gid).ConfigureAwait(false);
|
var (isOwner, group) = await TryValidateOwner(gid).ConfigureAwait(false);
|
||||||
if (!isOwner) return;
|
if (!isOwner) return;
|
||||||
@@ -554,25 +539,26 @@ public partial class MareHub
|
|||||||
newOwnerPair.IsModerator = false;
|
newOwnerPair.IsModerator = false;
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendGroupChangeOwner, gid, uid, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, uid, "Success"));
|
||||||
|
|
||||||
var groupPairs = await _dbContext.GroupPairs.Where(p => p.GroupGID == gid).Select(p => p.GroupUserUID).ToListAsync().ConfigureAwait(false);
|
var groupPairs = await _dbContext.GroupPairs.Where(p => p.GroupGID == gid).Select(p => p.GroupUserUID).AsNoTracking().ToListAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
await Clients.Users(uid).SendAsync(Api.OnGroupChange, new GroupDto()
|
await Clients.Users(uid).Client_GroupChange(new GroupDto()
|
||||||
{
|
{
|
||||||
GID = gid,
|
GID = gid,
|
||||||
OwnedBy = string.IsNullOrEmpty(group.Owner.Alias) ? group.Owner.UID : group.Owner.Alias,
|
OwnedBy = string.IsNullOrEmpty(group.Owner.Alias) ? group.Owner.UID : group.Owner.Alias,
|
||||||
IsModerator = false
|
IsModerator = false,
|
||||||
|
Alias = null
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
await Clients.Users(groupPairs).SendAsync(Api.OnGroupChange, new GroupDto()
|
await Clients.Users(groupPairs).Client_GroupChange(new GroupDto()
|
||||||
{
|
{
|
||||||
GID = gid,
|
GID = gid,
|
||||||
OwnedBy = string.IsNullOrEmpty(group.Owner.Alias) ? group.Owner.UID : group.Owner.Alias,
|
OwnedBy = string.IsNullOrEmpty(group.Owner.Alias) ? group.Owner.UID : group.Owner.Alias,
|
||||||
Alias = null
|
Alias = null
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
await Clients.Users(groupPairs.Where(p => !string.Equals(p, uid, StringComparison.Ordinal))).SendAsync(Api.OnGroupUserChange, new GroupPairDto()
|
await Clients.Users(groupPairs.Where(p => !string.Equals(p, uid, StringComparison.Ordinal))).Client_GroupUserChange(new GroupPairDto()
|
||||||
{
|
{
|
||||||
GroupGID = gid,
|
GroupGID = gid,
|
||||||
UserUID = uid,
|
UserUID = uid,
|
||||||
@@ -582,15 +568,14 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeGroupChangePassword)]
|
public async Task<bool> GroupChangePassword(string gid, string password)
|
||||||
public async Task<bool> ChangeGroupPassword(string gid, string password)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.InvokeGroupChangePassword, gid);
|
_logger.LogCallInfo(MareHubLogger.Args(gid));
|
||||||
|
|
||||||
var (isOwner, group) = await TryValidateOwner(gid).ConfigureAwait(false);
|
var (isOwner, group) = await TryValidateOwner(gid).ConfigureAwait(false);
|
||||||
if (!isOwner || password.Length < 10) return false;
|
if (!isOwner || password.Length < 10) return false;
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.InvokeGroupChangePassword, gid, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, "Success"));
|
||||||
|
|
||||||
group.HashedPassword = StringUtils.Sha256String(password);
|
group.HashedPassword = StringUtils.Sha256String(password);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
@@ -599,10 +584,9 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendGroupChangePinned)]
|
public async Task GroupChangePinned(string gid, string uid, bool isPinned)
|
||||||
public async Task ChangePinned(string gid, string uid, bool isPinned)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendGroupChangePinned, gid, uid, isPinned);
|
_logger.LogCallInfo(MareHubLogger.Args(gid, uid, isPinned));
|
||||||
|
|
||||||
var (userHasRights, _) = await TryValidateGroupModeratorOrOwner(gid).ConfigureAwait(false);
|
var (userHasRights, _) = await TryValidateGroupModeratorOrOwner(gid).ConfigureAwait(false);
|
||||||
if (!userHasRights) return;
|
if (!userHasRights) return;
|
||||||
@@ -613,11 +597,11 @@ public partial class MareHub
|
|||||||
groupPair.IsPinned = isPinned;
|
groupPair.IsPinned = isPinned;
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.InvokeGroupChangePassword, gid, uid, isPinned, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, uid, isPinned, "Success"));
|
||||||
|
|
||||||
var groupPairs = await _dbContext.GroupPairs.Where(p => p.GroupGID == gid).Select(p => p.GroupUserUID).ToListAsync().ConfigureAwait(false);
|
var groupPairs = await _dbContext.GroupPairs.Where(p => p.GroupGID == gid).Select(p => p.GroupUserUID).AsNoTracking().ToListAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
await Clients.Users(groupPairs.Where(p => !string.Equals(p, uid, StringComparison.Ordinal))).SendAsync(Api.OnGroupUserChange, new GroupPairDto()
|
await Clients.Users(groupPairs.Where(p => !string.Equals(p, uid, StringComparison.Ordinal))).Client_GroupUserChange(new GroupPairDto()
|
||||||
{
|
{
|
||||||
GroupGID = gid,
|
GroupGID = gid,
|
||||||
UserUID = uid,
|
UserUID = uid,
|
||||||
@@ -626,23 +610,22 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendGroupClear)]
|
public async Task GroupClear(string gid)
|
||||||
public async Task ClearGroup(string gid)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendGroupClear, gid);
|
_logger.LogCallInfo(MareHubLogger.Args(gid));
|
||||||
|
|
||||||
var (hasRights, group) = await TryValidateGroupModeratorOrOwner(gid).ConfigureAwait(false);
|
var (hasRights, group) = await TryValidateGroupModeratorOrOwner(gid).ConfigureAwait(false);
|
||||||
if (!hasRights) return;
|
if (!hasRights) return;
|
||||||
|
|
||||||
var groupPairs = await _dbContext.GroupPairs.Where(p => p.GroupGID == gid).ToListAsync().ConfigureAwait(false);
|
var groupPairs = await _dbContext.GroupPairs.Where(p => p.GroupGID == gid).ToListAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
await Clients.Users(groupPairs.Where(p => !p.IsPinned && !p.IsModerator).Select(g => g.GroupUserUID)).SendAsync(Api.OnGroupChange, new GroupDto()
|
await Clients.Users(groupPairs.Where(p => !p.IsPinned && !p.IsModerator).Select(g => g.GroupUserUID)).Client_GroupChange(new GroupDto()
|
||||||
{
|
{
|
||||||
GID = group.GID,
|
GID = group.GID,
|
||||||
IsDeleted = true,
|
IsDeleted = true,
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendGroupClear, gid, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(gid, "Success"));
|
||||||
|
|
||||||
var notPinned = groupPairs.Where(g => !g.IsPinned).ToList();
|
var notPinned = groupPairs.Where(g => !g.IsPinned).ToList();
|
||||||
|
|
||||||
@@ -651,7 +634,7 @@ public partial class MareHub
|
|||||||
|
|
||||||
foreach (var pair in notPinned)
|
foreach (var pair in notPinned)
|
||||||
{
|
{
|
||||||
await Clients.Users(groupPairs.Where(p => p.IsPinned).Select(g => g.GroupUserUID)).SendAsync(Api.OnGroupUserChange, new GroupPairDto()
|
await Clients.Users(groupPairs.Where(p => p.IsPinned).Select(g => g.GroupUserUID)).Client_GroupUserChange(new GroupPairDto()
|
||||||
{
|
{
|
||||||
GroupGID = pair.GroupGID,
|
GroupGID = pair.GroupGID,
|
||||||
IsRemoved = true,
|
IsRemoved = true,
|
||||||
|
|||||||
@@ -10,17 +10,15 @@ using MareSynchronosShared.Protos;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace MareSynchronosServer.Hubs;
|
namespace MareSynchronosServer.Hubs;
|
||||||
|
|
||||||
public partial class MareHub
|
public partial class MareHub
|
||||||
{
|
{
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendUserDeleteAccount)]
|
public async Task UserDelete()
|
||||||
public async Task DeleteAccount()
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendUserDeleteAccount);
|
_logger.LogCallInfo();
|
||||||
|
|
||||||
string userid = AuthenticatedUserId;
|
string userid = AuthenticatedUserId;
|
||||||
var userEntry = await _dbContext.Users.SingleAsync(u => u.UID == userid).ConfigureAwait(false);
|
var userEntry = await _dbContext.Users.SingleAsync(u => u.UID == userid).ConfigureAwait(false);
|
||||||
@@ -45,15 +43,14 @@ public partial class MareHub
|
|||||||
_dbContext.RemoveRange(ownPairData);
|
_dbContext.RemoveRange(ownPairData);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
var otherPairData = await _dbContext.ClientPairs.Include(u => u.User)
|
var otherPairData = await _dbContext.ClientPairs.Include(u => u.User)
|
||||||
.Where(u => u.OtherUser.UID == userid).ToListAsync().ConfigureAwait(false);
|
.Where(u => u.OtherUser.UID == userid).AsNoTracking().ToListAsync().ConfigureAwait(false);
|
||||||
foreach (var pair in otherPairData)
|
foreach (var pair in otherPairData)
|
||||||
{
|
{
|
||||||
await Clients.User(pair.User.UID)
|
await Clients.User(pair.User.UID).Client_UserUpdateClientPairs(new ClientPairDto()
|
||||||
.SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
{
|
||||||
{
|
OtherUID = userid,
|
||||||
OtherUID = userid,
|
IsRemoved = true
|
||||||
IsRemoved = true
|
}).ConfigureAwait(false);
|
||||||
}, charaIdent).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var pair in groupPairs)
|
foreach (var pair in groupPairs)
|
||||||
@@ -70,22 +67,20 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeUserGetOnlineCharacters)]
|
public async Task<List<string>> UserGetOnlineCharacters()
|
||||||
public async Task<List<string>> GetOnlineCharacters()
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.InvokeUserGetOnlineCharacters);
|
_logger.LogCallInfo();
|
||||||
|
|
||||||
var ownIdent = await _clientIdentService.GetCharacterIdentForUid(AuthenticatedUserId).ConfigureAwait(false);
|
var ownIdent = await _clientIdentService.GetCharacterIdentForUid(AuthenticatedUserId).ConfigureAwait(false);
|
||||||
|
|
||||||
var usersToSendOnlineTo = await SendDataToAllPairedUsers(Api.OnUserAddOnlinePairedPlayer, ownIdent).ConfigureAwait(false);
|
var usersToSendOnlineTo = await SendOnlineToAllPairedUsers(ownIdent).ConfigureAwait(false);
|
||||||
return usersToSendOnlineTo.Select(async e => await _clientIdentService.GetCharacterIdentForUid(e).ConfigureAwait(false)).Select(t => t.Result).Where(t => !string.IsNullOrEmpty(t)).Distinct(System.StringComparer.Ordinal).ToList();
|
return usersToSendOnlineTo.Select(async e => await _clientIdentService.GetCharacterIdentForUid(e).ConfigureAwait(false)).Select(t => t.Result).Where(t => !string.IsNullOrEmpty(t)).Distinct(System.StringComparer.Ordinal).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeUserGetPairedClients)]
|
public async Task<List<ClientPairDto>> UserGetPairedClients()
|
||||||
public async Task<List<ClientPairDto>> GetPairedClients()
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.InvokeUserGetPairedClients);
|
_logger.LogCallInfo();
|
||||||
|
|
||||||
string userid = AuthenticatedUserId;
|
string userid = AuthenticatedUserId;
|
||||||
var query =
|
var query =
|
||||||
@@ -113,7 +108,7 @@ public partial class MareHub
|
|||||||
IsSynced = otherEntry != null
|
IsSynced = otherEntry != null
|
||||||
};
|
};
|
||||||
|
|
||||||
return (await query.ToListAsync().ConfigureAwait(false)).Select(f => new ClientPairDto()
|
return (await query.AsNoTracking().ToListAsync().ConfigureAwait(false)).Select(f => new ClientPairDto()
|
||||||
{
|
{
|
||||||
VanityUID = f.Alias,
|
VanityUID = f.Alias,
|
||||||
IsPaused = f.IsPaused,
|
IsPaused = f.IsPaused,
|
||||||
@@ -124,10 +119,9 @@ public partial class MareHub
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeUserPushCharacterDataToVisibleClients)]
|
public async Task UserPushData(CharacterCacheDto characterCache, List<string> visibleCharacterIds)
|
||||||
public async Task PushCharacterDataToVisibleClients(CharacterCacheDto characterCache, List<string> visibleCharacterIds)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.InvokeUserPushCharacterDataToVisibleClients, visibleCharacterIds.Count);
|
_logger.LogCallInfo(MareHubLogger.Args(visibleCharacterIds.Count));
|
||||||
|
|
||||||
var allPairedUsers = await GetAllPairedUnpausedUsers().ConfigureAwait(false);
|
var allPairedUsers = await GetAllPairedUnpausedUsers().ConfigureAwait(false);
|
||||||
|
|
||||||
@@ -136,19 +130,18 @@ public partial class MareHub
|
|||||||
|
|
||||||
var ownIdent = await _clientIdentService.GetCharacterIdentForUid(AuthenticatedUserId).ConfigureAwait(false);
|
var ownIdent = await _clientIdentService.GetCharacterIdentForUid(AuthenticatedUserId).ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.InvokeUserPushCharacterDataToVisibleClients, visibleCharacterIds.Count, allPairedUsersDict.Count());
|
_logger.LogCallInfo(MareHubLogger.Args(visibleCharacterIds.Count, allPairedUsersDict.Count()));
|
||||||
|
|
||||||
await Clients.Users(allPairedUsersDict.Select(f => f.Key)).SendAsync(Api.OnUserReceiveCharacterData, characterCache, ownIdent).ConfigureAwait(false);
|
await Clients.Users(allPairedUsersDict.Select(f => f.Key)).Client_UserReceiveCharacterData(characterCache, ownIdent).ConfigureAwait(false);
|
||||||
|
|
||||||
_mareMetrics.IncCounter(MetricsAPI.CounterUserPushData);
|
_mareMetrics.IncCounter(MetricsAPI.CounterUserPushData);
|
||||||
_mareMetrics.IncCounter(MetricsAPI.CounterUserPushDataTo, allPairedUsersDict.Count());
|
_mareMetrics.IncCounter(MetricsAPI.CounterUserPushDataTo, allPairedUsersDict.Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendUserPairedClientAddition)]
|
public async Task UserAddPair(string uid)
|
||||||
public async Task SendPairedClientAddition(string uid)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendUserPairedClientAddition, uid);
|
_logger.LogCallInfo(MareHubLogger.Args(uid));
|
||||||
|
|
||||||
// don't allow adding yourself or nothing
|
// don't allow adding yourself or nothing
|
||||||
uid = uid.Trim();
|
uid = uid.Trim();
|
||||||
@@ -165,7 +158,7 @@ public partial class MareHub
|
|||||||
// grab self create new client pair and save
|
// grab self create new client pair and save
|
||||||
var user = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false);
|
var user = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendUserPairedClientAddition, uid, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(uid, "Success"));
|
||||||
|
|
||||||
ClientPair wl = new ClientPair()
|
ClientPair wl = new ClientPair()
|
||||||
{
|
{
|
||||||
@@ -178,8 +171,8 @@ public partial class MareHub
|
|||||||
|
|
||||||
// get the opposite entry of the client pair
|
// get the opposite entry of the client pair
|
||||||
var otherEntry = OppositeEntry(otherUser.UID);
|
var otherEntry = OppositeEntry(otherUser.UID);
|
||||||
await Clients.User(user.UID)
|
await Clients.User(user.UID).Client_UserUpdateClientPairs(
|
||||||
.SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
new ClientPairDto()
|
||||||
{
|
{
|
||||||
VanityUID = otherUser.Alias,
|
VanityUID = otherUser.Alias,
|
||||||
OtherUID = otherUser.UID,
|
OtherUID = otherUser.UID,
|
||||||
@@ -196,7 +189,7 @@ public partial class MareHub
|
|||||||
if (otherIdent == null) return;
|
if (otherIdent == null) return;
|
||||||
|
|
||||||
// send push with update to other user if other user is online
|
// send push with update to other user if other user is online
|
||||||
await Clients.User(otherUser.UID).SendAsync(Api.OnUserUpdateClientPairs,
|
await Clients.User(otherUser.UID).Client_UserUpdateClientPairs(
|
||||||
new ClientPairDto()
|
new ClientPairDto()
|
||||||
{
|
{
|
||||||
VanityUID = user.Alias,
|
VanityUID = user.Alias,
|
||||||
@@ -213,18 +206,15 @@ public partial class MareHub
|
|||||||
// if the other user has paused the main user and there was no previous group connection don't send anything
|
// if the other user has paused the main user and there was no previous group connection don't send anything
|
||||||
if (!otherEntry.IsPaused && allUserPairs.Any(p => string.Equals(p.UID, uid, System.StringComparison.Ordinal) && p.IsPausedPerGroup is PauseInfo.Paused or PauseInfo.NoConnection))
|
if (!otherEntry.IsPaused && allUserPairs.Any(p => string.Equals(p.UID, uid, System.StringComparison.Ordinal) && p.IsPausedPerGroup is PauseInfo.Paused or PauseInfo.NoConnection))
|
||||||
{
|
{
|
||||||
await Clients.User(user.UID)
|
await Clients.User(user.UID).Client_UserChangePairedPlayer(otherIdent, true).ConfigureAwait(false);
|
||||||
.SendAsync(Api.OnUserAddOnlinePairedPlayer, otherIdent).ConfigureAwait(false);
|
await Clients.User(otherUser.UID).Client_UserChangePairedPlayer(userIdent, true).ConfigureAwait(false);
|
||||||
await Clients.User(otherUser.UID)
|
|
||||||
.SendAsync(Api.OnUserAddOnlinePairedPlayer, userIdent).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendUserPairedClientPauseChange)]
|
public async Task UserChangePairPauseStatus(string otherUserUid, bool isPaused)
|
||||||
public async Task SendPairedClientPauseChange(string otherUserUid, bool isPaused)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendUserPairedClientPauseChange, otherUserUid, isPaused);
|
_logger.LogCallInfo(MareHubLogger.Args(otherUserUid, isPaused));
|
||||||
|
|
||||||
if (string.Equals(otherUserUid, AuthenticatedUserId, System.StringComparison.Ordinal)) return;
|
if (string.Equals(otherUserUid, AuthenticatedUserId, System.StringComparison.Ordinal)) return;
|
||||||
ClientPair pair = await _dbContext.ClientPairs.SingleOrDefaultAsync(w => w.UserUID == AuthenticatedUserId && w.OtherUserUID == otherUserUid).ConfigureAwait(false);
|
ClientPair pair = await _dbContext.ClientPairs.SingleOrDefaultAsync(w => w.UserUID == AuthenticatedUserId && w.OtherUserUID == otherUserUid).ConfigureAwait(false);
|
||||||
@@ -234,12 +224,12 @@ public partial class MareHub
|
|||||||
_dbContext.Update(pair);
|
_dbContext.Update(pair);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendUserPairedClientPauseChange, otherUserUid, isPaused, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(otherUserUid, isPaused, "Success"));
|
||||||
|
|
||||||
var otherEntry = OppositeEntry(otherUserUid);
|
var otherEntry = OppositeEntry(otherUserUid);
|
||||||
|
|
||||||
await Clients.User(AuthenticatedUserId)
|
await Clients.User(AuthenticatedUserId).Client_UserUpdateClientPairs(
|
||||||
.SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
new ClientPairDto()
|
||||||
{
|
{
|
||||||
OtherUID = otherUserUid,
|
OtherUID = otherUserUid,
|
||||||
IsPaused = isPaused,
|
IsPaused = isPaused,
|
||||||
@@ -248,7 +238,7 @@ public partial class MareHub
|
|||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
if (otherEntry != null)
|
if (otherEntry != null)
|
||||||
{
|
{
|
||||||
await Clients.User(otherUserUid).SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
await Clients.User(otherUserUid).Client_UserUpdateClientPairs(new ClientPairDto()
|
||||||
{
|
{
|
||||||
OtherUID = AuthenticatedUserId,
|
OtherUID = AuthenticatedUserId,
|
||||||
IsPaused = otherEntry.IsPaused,
|
IsPaused = otherEntry.IsPaused,
|
||||||
@@ -261,24 +251,15 @@ public partial class MareHub
|
|||||||
|
|
||||||
if (selfCharaIdent == null || otherCharaIdent == null || otherEntry.IsPaused) return;
|
if (selfCharaIdent == null || otherCharaIdent == null || otherEntry.IsPaused) return;
|
||||||
|
|
||||||
if (isPaused)
|
await Clients.User(AuthenticatedUserId).Client_UserChangePairedPlayer(otherCharaIdent, !isPaused).ConfigureAwait(false);
|
||||||
{
|
await Clients.User(otherUserUid).Client_UserChangePairedPlayer(selfCharaIdent, !isPaused).ConfigureAwait(false);
|
||||||
await Clients.User(AuthenticatedUserId).SendAsync(Api.OnUserRemoveOnlinePairedPlayer, otherCharaIdent).ConfigureAwait(false);
|
|
||||||
await Clients.User(otherUserUid).SendAsync(Api.OnUserRemoveOnlinePairedPlayer, selfCharaIdent).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await Clients.User(AuthenticatedUserId).SendAsync(Api.OnUserAddOnlinePairedPlayer, otherCharaIdent).ConfigureAwait(false);
|
|
||||||
await Clients.User(otherUserUid).SendAsync(Api.OnUserAddOnlinePairedPlayer, selfCharaIdent).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendUserPairedClientRemoval)]
|
public async Task UserRemovePair(string otherUserUid)
|
||||||
public async Task SendPairedClientRemoval(string otherUserUid)
|
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.SendUserPairedClientRemoval, otherUserUid);
|
_logger.LogCallInfo(MareHubLogger.Args(otherUserUid));
|
||||||
|
|
||||||
if (string.Equals(otherUserUid, AuthenticatedUserId, System.StringComparison.Ordinal)) return;
|
if (string.Equals(otherUserUid, AuthenticatedUserId, System.StringComparison.Ordinal)) return;
|
||||||
|
|
||||||
@@ -292,10 +273,10 @@ public partial class MareHub
|
|||||||
_dbContext.ClientPairs.Remove(callerPair);
|
_dbContext.ClientPairs.Remove(callerPair);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.SendUserPairedClientRemoval, otherUserUid, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(otherUserUid, "Success"));
|
||||||
|
|
||||||
await Clients.User(AuthenticatedUserId)
|
await Clients.User(AuthenticatedUserId)
|
||||||
.SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
.Client_UserUpdateClientPairs(new ClientPairDto()
|
||||||
{
|
{
|
||||||
OtherUID = otherUserUid,
|
OtherUID = otherUserUid,
|
||||||
IsRemoved = true
|
IsRemoved = true
|
||||||
@@ -310,7 +291,7 @@ public partial class MareHub
|
|||||||
if (otherIdent == null) return;
|
if (otherIdent == null) return;
|
||||||
|
|
||||||
// get own ident and
|
// get own ident and
|
||||||
await Clients.User(otherUserUid).SendAsync(Api.OnUserUpdateClientPairs,
|
await Clients.User(otherUserUid).Client_UserUpdateClientPairs(
|
||||||
new ClientPairDto()
|
new ClientPairDto()
|
||||||
{
|
{
|
||||||
OtherUID = AuthenticatedUserId,
|
OtherUID = AuthenticatedUserId,
|
||||||
@@ -333,16 +314,16 @@ public partial class MareHub
|
|||||||
if (!callerHadPaused && !otherHadPaused && isPausedInGroup)
|
if (!callerHadPaused && !otherHadPaused && isPausedInGroup)
|
||||||
{
|
{
|
||||||
var userIdent = await _clientIdentService.GetCharacterIdentForUid(AuthenticatedUserId).ConfigureAwait(false);
|
var userIdent = await _clientIdentService.GetCharacterIdentForUid(AuthenticatedUserId).ConfigureAwait(false);
|
||||||
await Clients.User(AuthenticatedUserId).SendAsync(Api.OnUserRemoveOnlinePairedPlayer, otherIdent).ConfigureAwait(false);
|
await Clients.User(AuthenticatedUserId).Client_UserChangePairedPlayer(otherIdent, false).ConfigureAwait(false);
|
||||||
await Clients.User(otherUserUid).SendAsync(Api.OnUserRemoveOnlinePairedPlayer, userIdent).ConfigureAwait(false);
|
await Clients.User(otherUserUid).Client_UserChangePairedPlayer(userIdent, false).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the caller had paused other but not the other has paused the caller and they are in an unpaused group together, change state to online
|
// if the caller had paused other but not the other has paused the caller and they are in an unpaused group together, change state to online
|
||||||
if (callerHadPaused && !otherHadPaused && !isPausedInGroup)
|
if (callerHadPaused && !otherHadPaused && !isPausedInGroup)
|
||||||
{
|
{
|
||||||
var userIdent = await _clientIdentService.GetCharacterIdentForUid(AuthenticatedUserId).ConfigureAwait(false);
|
var userIdent = await _clientIdentService.GetCharacterIdentForUid(AuthenticatedUserId).ConfigureAwait(false);
|
||||||
await Clients.User(AuthenticatedUserId).SendAsync(Api.OnUserAddOnlinePairedPlayer, otherIdent).ConfigureAwait(false);
|
await Clients.User(AuthenticatedUserId).Client_UserChangePairedPlayer(otherIdent, true).ConfigureAwait(false);
|
||||||
await Clients.User(otherUserUid).SendAsync(Api.OnUserAddOnlinePairedPlayer, userIdent).ConfigureAwait(false);
|
await Clients.User(otherUserUid).Client_UserChangePairedPlayer(userIdent, true).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
|
|
||||||
namespace MareSynchronosServer.Hubs;
|
namespace MareSynchronosServer.Hubs;
|
||||||
|
|
||||||
public partial class MareHub : Hub
|
public partial class MareHub : Hub<IMareHub>, IMareHub
|
||||||
{
|
{
|
||||||
private readonly MareMetrics _mareMetrics;
|
private readonly MareMetrics _mareMetrics;
|
||||||
private readonly AuthService.AuthServiceClient _authServiceClient;
|
private readonly AuthService.AuthServiceClient _authServiceClient;
|
||||||
@@ -54,7 +54,6 @@ public partial class MareHub : Hub
|
|||||||
_dbContext = mareDbContext;
|
_dbContext = mareDbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HubMethodName(Api.InvokeHeartbeat)]
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
public async Task<ConnectionDto> Heartbeat(string characterIdentification)
|
public async Task<ConnectionDto> Heartbeat(string characterIdentification)
|
||||||
{
|
{
|
||||||
@@ -62,9 +61,9 @@ public partial class MareHub : Hub
|
|||||||
|
|
||||||
var userId = Context.User!.Claims.SingleOrDefault(c => string.Equals(c.Type, ClaimTypes.NameIdentifier, StringComparison.Ordinal))?.Value;
|
var userId = Context.User!.Claims.SingleOrDefault(c => string.Equals(c.Type, ClaimTypes.NameIdentifier, StringComparison.Ordinal))?.Value;
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.InvokeHeartbeat, characterIdentification);
|
_logger.LogCallInfo(MareHubLogger.Args(characterIdentification));
|
||||||
|
|
||||||
await Clients.Caller.SendAsync(Api.OnUpdateSystemInfo, _systemInfoService.SystemInfoDto).ConfigureAwait(false);
|
await Clients.Caller.Client_UpdateSystemInfo(_systemInfoService.SystemInfoDto).ConfigureAwait(false);
|
||||||
|
|
||||||
var isBanned = await _dbContext.BannedUsers.AsNoTracking().AnyAsync(u => u.CharacterIdentification == characterIdentification).ConfigureAwait(false);
|
var isBanned = await _dbContext.BannedUsers.AsNoTracking().AnyAsync(u => u.CharacterIdentification == characterIdentification).ConfigureAwait(false);
|
||||||
|
|
||||||
@@ -74,11 +73,11 @@ public partial class MareHub : Hub
|
|||||||
var existingIdent = await _clientIdentService.GetCharacterIdentForUid(userId).ConfigureAwait(false);
|
var existingIdent = await _clientIdentService.GetCharacterIdentForUid(userId).ConfigureAwait(false);
|
||||||
if (!string.IsNullOrEmpty(existingIdent) && !string.Equals(characterIdentification, existingIdent, StringComparison.Ordinal))
|
if (!string.IsNullOrEmpty(existingIdent) && !string.Equals(characterIdentification, existingIdent, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo(Api.InvokeHeartbeat, characterIdentification, "Failure", "LoggedIn");
|
_logger.LogCallWarning(MareHubLogger.Args(characterIdentification, "Failure", "LoggedIn"));
|
||||||
|
|
||||||
return new ConnectionDto()
|
return new ConnectionDto()
|
||||||
{
|
{
|
||||||
ServerVersion = Api.Version
|
ServerVersion = IMareHub.ApiVersion
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,11 +85,11 @@ public partial class MareHub : Hub
|
|||||||
await _clientIdentService.MarkUserOnline(user.UID, characterIdentification).ConfigureAwait(false);
|
await _clientIdentService.MarkUserOnline(user.UID, characterIdentification).ConfigureAwait(false);
|
||||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.InvokeHeartbeat, characterIdentification, "Success");
|
_logger.LogCallInfo(MareHubLogger.Args(characterIdentification, "Success"));
|
||||||
|
|
||||||
return new ConnectionDto
|
return new ConnectionDto
|
||||||
{
|
{
|
||||||
ServerVersion = Api.Version,
|
ServerVersion = IMareHub.ApiVersion,
|
||||||
UID = string.IsNullOrEmpty(user.Alias) ? user.UID : user.Alias,
|
UID = string.IsNullOrEmpty(user.Alias) ? user.UID : user.Alias,
|
||||||
IsModerator = user.IsModerator,
|
IsModerator = user.IsModerator,
|
||||||
IsAdmin = user.IsAdmin,
|
IsAdmin = user.IsAdmin,
|
||||||
@@ -104,15 +103,14 @@ public partial class MareHub : Hub
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogCallInfo(Api.InvokeHeartbeat, characterIdentification, "Failure");
|
_logger.LogCallWarning(MareHubLogger.Args(characterIdentification, "Failure"));
|
||||||
|
|
||||||
return new ConnectionDto()
|
return new ConnectionDto()
|
||||||
{
|
{
|
||||||
ServerVersion = Api.Version
|
ServerVersion = IMareHub.ApiVersion
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[HubMethodName(Api.InvokeCheckClientHealth)]
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||||
public async Task<bool> CheckClientHealth()
|
public async Task<bool> CheckClientHealth()
|
||||||
{
|
{
|
||||||
@@ -121,14 +119,14 @@ public partial class MareHub : Hub
|
|||||||
if (string.IsNullOrEmpty(serverId) || !string.Equals(serverId, _shardName, StringComparison.Ordinal))
|
if (string.IsNullOrEmpty(serverId) || !string.Equals(serverId, _shardName, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
needsReconnect = true;
|
needsReconnect = true;
|
||||||
_logger.LogCallWarning(Api.InvokeCheckClientHealth, needsReconnect);
|
_logger.LogCallWarning(MareHubLogger.Args(needsReconnect));
|
||||||
}
|
}
|
||||||
return needsReconnect;
|
return needsReconnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnConnectedAsync()
|
public override async Task OnConnectedAsync()
|
||||||
{
|
{
|
||||||
_logger.LogCallInfo("Connect", _contextAccessor.GetIpAddress());
|
_logger.LogCallInfo(MareHubLogger.Args(_contextAccessor.GetIpAddress()));
|
||||||
_mareMetrics.IncGauge(MetricsAPI.GaugeConnections);
|
_mareMetrics.IncGauge(MetricsAPI.GaugeConnections);
|
||||||
await base.OnConnectedAsync().ConfigureAwait(false);
|
await base.OnConnectedAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@@ -143,9 +141,9 @@ public partial class MareHub : Hub
|
|||||||
{
|
{
|
||||||
_mareMetrics.DecGauge(MetricsAPI.GaugeAuthorizedConnections);
|
_mareMetrics.DecGauge(MetricsAPI.GaugeAuthorizedConnections);
|
||||||
|
|
||||||
_logger.LogCallInfo("Disconnect");
|
_logger.LogCallInfo();
|
||||||
|
|
||||||
await SendDataToAllPairedUsers(Api.OnUserRemoveOnlinePairedPlayer, userCharaIdent).ConfigureAwait(false);
|
await SendOfflineToAllPairedUsers(userCharaIdent).ConfigureAwait(false);
|
||||||
|
|
||||||
_dbContext.RemoveRange(_dbContext.Files.Where(f => !f.Uploaded && f.UploaderUID == AuthenticatedUserId));
|
_dbContext.RemoveRange(_dbContext.Files.Where(f => !f.Uploaded && f.UploaderUID == AuthenticatedUserId));
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,10 @@ public class GrpcClientIdentificationService : IHostedService
|
|||||||
private readonly IdentificationService.IdentificationServiceClient _grpcIdentClient;
|
private readonly IdentificationService.IdentificationServiceClient _grpcIdentClient;
|
||||||
private readonly MareMetrics _metrics;
|
private readonly MareMetrics _metrics;
|
||||||
protected ConcurrentDictionary<string, string> OnlineClients = new(StringComparer.Ordinal);
|
protected ConcurrentDictionary<string, string> OnlineClients = new(StringComparer.Ordinal);
|
||||||
|
private ConcurrentDictionary<string, string> RemoteCachedIdents = new(StringComparer.Ordinal);
|
||||||
|
private readonly TimeSpan InvalidateCachedIdent = TimeSpan.FromSeconds(30);
|
||||||
private bool _grpcIsFaulty = false;
|
private bool _grpcIsFaulty = false;
|
||||||
|
private CancellationTokenSource _cacheVerificationCts = new();
|
||||||
|
|
||||||
public GrpcClientIdentificationService(ILogger<GrpcClientIdentificationService> logger, IdentificationService.IdentificationServiceClient gprcIdentClient, MareMetrics metrics, IConfiguration configuration)
|
public GrpcClientIdentificationService(ILogger<GrpcClientIdentificationService> logger, IdentificationService.IdentificationServiceClient gprcIdentClient, MareMetrics metrics, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
@@ -30,6 +33,46 @@ public class GrpcClientIdentificationService : IHostedService
|
|||||||
_metrics = metrics;
|
_metrics = metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task HandleCacheVerification(CancellationToken ct)
|
||||||
|
{
|
||||||
|
while (!ct.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (RemoteCachedIdents.Any())
|
||||||
|
{
|
||||||
|
MultiUidMessage req = new();
|
||||||
|
req.Uids.AddRange(RemoteCachedIdents.Select(k => new UidMessage() { Uid = k.Key }));
|
||||||
|
var cacheResponse = await InvokeOnGrpc(_grpcIdentClient.ValidateCachedIdentsAsync(req)).ConfigureAwait(false);
|
||||||
|
|
||||||
|
foreach (var entry in cacheResponse.UidWithIdent)
|
||||||
|
{
|
||||||
|
if (!RemoteCachedIdents.TryGetValue(entry.Uid.Uid, out var ident))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(entry.Ident.Ident))
|
||||||
|
{
|
||||||
|
RemoteCachedIdents.TryRemove(entry.Uid.Uid, out var _);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoteCachedIdents[entry.Uid.Uid] = entry.Ident.Ident;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Error during cached idents verification");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
await Task.Delay(InvalidateCachedIdent, ct).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<string?> GetCharacterIdentForUid(string uid)
|
public async Task<string?> GetCharacterIdentForUid(string uid)
|
||||||
{
|
{
|
||||||
if (OnlineClients.TryGetValue(uid, out string ident))
|
if (OnlineClients.TryGetValue(uid, out string ident))
|
||||||
@@ -37,8 +80,14 @@ public class GrpcClientIdentificationService : IHostedService
|
|||||||
return ident;
|
return ident;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (RemoteCachedIdents.TryGetValue(uid, out var cachedIdent))
|
||||||
|
{
|
||||||
|
return cachedIdent;
|
||||||
|
}
|
||||||
|
|
||||||
var result = await InvokeOnGrpc(_grpcIdentClient.GetIdentForUidAsync(new UidMessage { Uid = uid })).ConfigureAwait(false);
|
var result = await InvokeOnGrpc(_grpcIdentClient.GetIdentForUidAsync(new UidMessage { Uid = uid })).ConfigureAwait(false);
|
||||||
if (result == default(CharacterIdentMessage)) return null;
|
if (result == default(CharacterIdentMessage)) return null;
|
||||||
|
RemoteCachedIdents[uid] = result.Ident;
|
||||||
return result.Ident;
|
return result.Ident;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,10 +140,13 @@ public class GrpcClientIdentificationService : IHostedService
|
|||||||
public async Task StartAsync(CancellationToken cancellationToken)
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await ExecuteOnGrpc(_grpcIdentClient.ClearIdentsForServerAsync(new ServerMessage() { ServerId = _shardName })).ConfigureAwait(false);
|
await ExecuteOnGrpc(_grpcIdentClient.ClearIdentsForServerAsync(new ServerMessage() { ServerId = _shardName })).ConfigureAwait(false);
|
||||||
|
|
||||||
|
_ = HandleCacheVerification(_cacheVerificationCts.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task StopAsync(CancellationToken cancellationToken)
|
public async Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
_cacheVerificationCts.Cancel();
|
||||||
await ExecuteOnGrpc(_grpcIdentClient.ClearIdentsForServerAsync(new ServerMessage() { ServerId = _shardName })).ConfigureAwait(false);
|
await ExecuteOnGrpc(_grpcIdentClient.ClearIdentsForServerAsync(new ServerMessage() { ServerId = _shardName })).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using MareSynchronosServer.Hubs;
|
|||||||
using MareSynchronosShared.Data;
|
using MareSynchronosShared.Data;
|
||||||
using MareSynchronosShared.Metrics;
|
using MareSynchronosShared.Metrics;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
@@ -20,12 +21,11 @@ public class SystemInfoService : IHostedService, IDisposable
|
|||||||
private readonly IServiceProvider _services;
|
private readonly IServiceProvider _services;
|
||||||
private readonly GrpcClientIdentificationService _clientIdentService;
|
private readonly GrpcClientIdentificationService _clientIdentService;
|
||||||
private readonly ILogger<SystemInfoService> _logger;
|
private readonly ILogger<SystemInfoService> _logger;
|
||||||
private readonly IHubContext<MareHub> _hubContext;
|
private readonly IHubContext<MareHub, IMareHub> _hubContext;
|
||||||
private Timer _timer;
|
private Timer _timer;
|
||||||
private string _shardName;
|
|
||||||
public SystemInfoDto SystemInfoDto { get; private set; } = new();
|
public SystemInfoDto SystemInfoDto { get; private set; } = new();
|
||||||
|
|
||||||
public SystemInfoService(MareMetrics mareMetrics, IConfiguration configuration, IServiceProvider services, GrpcClientIdentificationService clientIdentService, ILogger<SystemInfoService> logger, IHubContext<MareHub> hubContext)
|
public SystemInfoService(MareMetrics mareMetrics, IConfiguration configuration, IServiceProvider services, GrpcClientIdentificationService clientIdentService, ILogger<SystemInfoService> logger, IHubContext<MareHub, IMareHub> hubContext)
|
||||||
{
|
{
|
||||||
_mareMetrics = mareMetrics;
|
_mareMetrics = mareMetrics;
|
||||||
_services = services;
|
_services = services;
|
||||||
@@ -58,16 +58,16 @@ public class SystemInfoService : IHostedService, IDisposable
|
|||||||
OnlineUsers = (int)_clientIdentService.GetOnlineUsers().Result,
|
OnlineUsers = (int)_clientIdentService.GetOnlineUsers().Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
_hubContext.Clients.All.SendAsync(Api.OnUpdateSystemInfo, SystemInfoDto);
|
_hubContext.Clients.All.Client_UpdateSystemInfo(SystemInfoDto);
|
||||||
|
|
||||||
using var scope = _services.CreateScope();
|
using var scope = _services.CreateScope();
|
||||||
using var db = scope.ServiceProvider.GetService<MareDbContext>()!;
|
using var db = scope.ServiceProvider.GetService<MareDbContext>()!;
|
||||||
|
|
||||||
_mareMetrics.SetGaugeTo(MetricsAPI.GaugePairs, db.ClientPairs.Count());
|
_mareMetrics.SetGaugeTo(MetricsAPI.GaugePairs, db.ClientPairs.AsNoTracking().Count());
|
||||||
_mareMetrics.SetGaugeTo(MetricsAPI.GaugePairsPaused, db.ClientPairs.Count(p => p.IsPaused));
|
_mareMetrics.SetGaugeTo(MetricsAPI.GaugePairsPaused, db.ClientPairs.AsNoTracking().Count(p => p.IsPaused));
|
||||||
_mareMetrics.SetGaugeTo(MetricsAPI.GaugeGroups, db.Groups.Count());
|
_mareMetrics.SetGaugeTo(MetricsAPI.GaugeGroups, db.Groups.AsNoTracking().Count());
|
||||||
_mareMetrics.SetGaugeTo(MetricsAPI.GaugeGroupPairs, db.GroupPairs.Count());
|
_mareMetrics.SetGaugeTo(MetricsAPI.GaugeGroupPairs, db.GroupPairs.AsNoTracking().Count());
|
||||||
_mareMetrics.SetGaugeTo(MetricsAPI.GaugeGroupPairsPaused, db.GroupPairs.Count(p => p.IsPaused));
|
_mareMetrics.SetGaugeTo(MetricsAPI.GaugeGroupPairsPaused, db.GroupPairs.AsNoTracking().Count(p => p.IsPaused));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ public class Startup
|
|||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
endpoints.MapHub<MareHub>(Api.Path, options =>
|
endpoints.MapHub<MareHub>(IMareHub.Path, options =>
|
||||||
{
|
{
|
||||||
options.ApplicationMaxBufferSize = 5242880;
|
options.ApplicationMaxBufferSize = 5242880;
|
||||||
options.TransportMaxBufferSize = 5242880;
|
options.TransportMaxBufferSize = 5242880;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using MareSynchronosServer.Hubs;
|
using MareSynchronosServer.Hubs;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace MareSynchronosServer.Utils;
|
namespace MareSynchronosServer.Utils;
|
||||||
|
|
||||||
@@ -13,16 +14,20 @@ public class MareHubLogger
|
|||||||
_hub = hub;
|
_hub = hub;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
public static object[] Args(params object[] args)
|
||||||
public void LogCallInfo(string methodName, params object[] args)
|
|
||||||
{
|
{
|
||||||
string formattedArgs = args.Length != 0 ? "|" + string.Join(":", args) : string.Empty;
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogCallInfo(object[] args = null, [CallerMemberName] string methodName = "")
|
||||||
|
{
|
||||||
|
string formattedArgs = args != null && args.Length != 0 ? "|" + string.Join(":", args) : string.Empty;
|
||||||
_logger.LogInformation("{uid}:{method}{args}", _hub.AuthenticatedUserId, methodName, formattedArgs);
|
_logger.LogInformation("{uid}:{method}{args}", _hub.AuthenticatedUserId, methodName, formattedArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LogCallWarning(string methodName, params object[] args)
|
public void LogCallWarning(object[] args = null, [CallerMemberName] string methodName = "")
|
||||||
{
|
{
|
||||||
string formattedArgs = args.Length != 0 ? "|" + string.Join(":", args) : string.Empty;
|
string formattedArgs = args != null && args.Length != 0 ? "|" + string.Join(":", args) : string.Empty;
|
||||||
_logger.LogWarning("{uid}:{method}{args}", _hub.AuthenticatedUserId, methodName, formattedArgs);
|
_logger.LogWarning("{uid}:{method}{args}", _hub.AuthenticatedUserId, methodName, formattedArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,4 +66,23 @@ internal class IdentityService : IdentificationService.IdentificationServiceBase
|
|||||||
}
|
}
|
||||||
return Task.FromResult(new Empty());
|
return Task.FromResult(new Empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task<UidWithIdentMessage> ValidateCachedIdents(MultiUidMessage request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
UidWithIdentMessage response = new UidWithIdentMessage();
|
||||||
|
foreach (var msg in request.Uids)
|
||||||
|
{
|
||||||
|
UidWithIdent msgResp = new()
|
||||||
|
{
|
||||||
|
Uid = msg,
|
||||||
|
Ident = new()
|
||||||
|
};
|
||||||
|
var ident = await _handler.GetIdentForuid(msg.Uid);
|
||||||
|
msgResp.Ident.Ident = ident.CharacterIdent;
|
||||||
|
msgResp.Ident.ServerId = ident.ServerId;
|
||||||
|
response.UidWithIdent.Add(msgResp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -24,14 +24,32 @@ service IdentificationService {
|
|||||||
rpc GetIdentForUid (UidMessage) returns (CharacterIdentMessage);
|
rpc GetIdentForUid (UidMessage) returns (CharacterIdentMessage);
|
||||||
rpc ClearIdentsForServer (ServerMessage) returns (Empty);
|
rpc ClearIdentsForServer (ServerMessage) returns (Empty);
|
||||||
rpc RecreateServerIdents (ServerIdentMessage) returns (Empty);
|
rpc RecreateServerIdents (ServerIdentMessage) returns (Empty);
|
||||||
|
rpc ValidateCachedIdents (MultiUidMessage) returns (UidWithIdentMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
message Empty { }
|
message Empty { }
|
||||||
|
|
||||||
|
message MultiUidMessage {
|
||||||
|
repeated UidMessage uids = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UidWithIdentMessage {
|
||||||
|
repeated UidWithIdent uidWithIdent = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UidWithIdent {
|
||||||
|
UidMessage uid = 1;
|
||||||
|
CharacterIdentMessage ident = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message ServerIdentMessage {
|
message ServerIdentMessage {
|
||||||
repeated SetIdentMessage idents = 1;
|
repeated SetIdentMessage idents = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message UidMessage {
|
||||||
|
string uid = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message ServerMessage {
|
message ServerMessage {
|
||||||
string server_id = 1;
|
string server_id = 1;
|
||||||
}
|
}
|
||||||
@@ -56,10 +74,6 @@ message CharacterIdentMessage {
|
|||||||
string ident = 2;
|
string ident = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UidMessage {
|
|
||||||
string uid = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message UploadFileRequest {
|
message UploadFileRequest {
|
||||||
string hash = 1;
|
string hash = 1;
|
||||||
string uploader = 2;
|
string uploader = 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user