WutheringWaves/GameServer/Network/Rpc/RpcManager.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2024-02-09 22:15:05 +00:00
using GameServer.Network.Messages;
using GameServer.Systems.Event;
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;
private readonly EventSystem _eventSystem;
2024-02-07 21:41:39 +00:00
public RpcManager(MessageManager messageManager, IRpcEndPoint endPoint, ILogger<RpcManager> logger, EventSystem eventSystem)
2024-02-07 21:41:39 +00:00
{
_endPoint = endPoint;
_logger = logger;
_messageManager = messageManager;
_eventSystem = eventSystem;
2024-02-07 21:41:39 +00:00
}
2024-02-09 22:15:05 +00:00
public async Task Execute(RequestMessage request)
2024-02-07 21:41:39 +00:00
{
RpcResult? result = await _messageManager.ExecuteRpc(request.MessageId, request.Payload);
if (result == 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
}
result.Response.RpcID = request.RpcID;
await _endPoint.SendRpcResult(result.Response);
2024-02-07 21:41:39 +00:00
foreach (GameEventType postEvent in result.PostEvents)
{
await _eventSystem.Emit(postEvent);
}
_logger.LogInformation("Rpc with id {rpc_id} was handled, return message: {msg_id}", request.RpcID, result.Response.MessageId);
2024-02-07 21:41:39 +00:00
}
}