mirror of
https://github.com/Caraxi/mare.server.git
synced 2026-01-03 04:03:40 +01:00
* 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>
46 lines
1.7 KiB
C#
46 lines
1.7 KiB
C#
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();
|
|
}
|
|
}
|