WutheringWaves/GameServer/Network/Rpc/RpcManager.cs

33 lines
1.1 KiB
C#
Raw Normal View History

2024-02-09 22:15:05 +00:00
using GameServer.Network.Messages;
2024-02-07 21:41:39 +00:00
using Microsoft.Extensions.Logging;
namespace GameServer.Network.Rpc;
internal class RpcManager
{
private readonly IRpcEndPoint _endPoint;
private readonly ILogger _logger;
private readonly MessageManager _messageManager;
public RpcManager(MessageManager messageManager, IRpcEndPoint endPoint, ILogger<RpcManager> logger)
{
_endPoint = endPoint;
_logger = logger;
_messageManager = messageManager;
}
2024-02-09 22:15:05 +00:00
public async Task Execute(RequestMessage request)
2024-02-07 21:41:39 +00:00
{
2024-02-09 22:15:05 +00:00
ResponseMessage? response = await _messageManager.ExecuteRpc(request.MessageId, request.Payload);
if (response == null)
2024-02-07 21:41:39 +00:00
{
_logger.LogWarning("Rpc was not handled properly (message: {msg_id}, id: {rpc_id})", request.MessageId, request.RpcID);
2024-02-09 22:15:05 +00:00
return;
2024-02-07 21:41:39 +00:00
}
2024-02-09 22:15:05 +00:00
response.RpcID = request.RpcID;
await _endPoint.SendRpcResult(response);
2024-02-07 21:41:39 +00:00
2024-02-09 22:15:05 +00:00
_logger.LogInformation("Rpc with id {rpc_id} was handled, return message: {msg_id}", request.RpcID, response.MessageId);
2024-02-07 21:41:39 +00:00
}
}