mirror of
https://github.com/Caraxi/mare.server.git
synced 2026-01-03 17:43:39 +01:00
Refactoring using Claims more, add Server Side Messaging (#20)
* add some refactoring based on claims, handle chara ident inside claim, fix discord userid in log * improve authentication responses, add server side messaging * update server to mainline api Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
parent
5f0c12ecfa
commit
74b7fcdf89
25 changed files with 350 additions and 204 deletions
|
|
@ -0,0 +1,46 @@
|
|||
using Grpc.Core;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronosServer.Hubs;
|
||||
using MareSynchronosShared.Protos;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using static MareSynchronosShared.Protos.ClientMessageService;
|
||||
|
||||
namespace MareSynchronosServer.Services;
|
||||
|
||||
public class GrpcClientMessageService : ClientMessageServiceBase
|
||||
{
|
||||
private readonly ILogger<GrpcClientMessageService> _logger;
|
||||
private readonly IHubContext<MareHub, IMareHub> _hubContext;
|
||||
|
||||
public GrpcClientMessageService(ILogger<GrpcClientMessageService> logger, IHubContext<MareHub, IMareHub> hubContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_hubContext = hubContext;
|
||||
}
|
||||
|
||||
public override async Task<Empty> SendClientMessage(ClientMessage request, ServerCallContext context)
|
||||
{
|
||||
bool hasUid = !string.IsNullOrEmpty(request.Uid);
|
||||
|
||||
var severity = request.Type switch
|
||||
{
|
||||
MessageType.Info => MessageSeverity.Information,
|
||||
MessageType.Warning => MessageSeverity.Warning,
|
||||
MessageType.Error => MessageSeverity.Error,
|
||||
_ => MessageSeverity.Information,
|
||||
};
|
||||
|
||||
if (!hasUid)
|
||||
{
|
||||
_logger.LogInformation("Sending Message of severity {severity} to all online users: {message}", severity, request.Message);
|
||||
await _hubContext.Clients.All.Client_ReceiveServerMessage(severity, request.Message).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("Sending Message of severity {severity} to user {uid}: {message}", severity, request.Uid, request.Message);
|
||||
await _hubContext.Clients.User(request.Uid).Client_ReceiveServerMessage(severity, request.Message).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return new Empty();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue