Snowflake/RPG.Services.Gateserver/Network/Command/GateserverCommandHandler.cs
2024-01-19 17:45:18 +03:00

55 lines
1.8 KiB
C#

using Microsoft.Extensions.Logging;
using RPG.Network.Proto;
using RPG.Services.Core.Network;
using RPG.Services.Core.Network.Attributes;
using RPG.Services.Core.Network.Command;
using RPG.Services.Core.Session;
using RPG.Services.Gateserver.Session;
namespace RPG.Services.Gateserver.Network.Command;
internal class GateserverCommandHandler : ServiceCommandHandler
{
private readonly SessionManager _sessionManager;
public GateserverCommandHandler(ILogger<ServiceCommandHandler> logger, ServiceBox services, SessionManager sessionManager) : base(logger, services)
{
_sessionManager = sessionManager;
}
[ServiceCommand(ServiceCommandType.BindContainerResult)]
public async Task OnBindContainerResult(ServiceCommand command)
{
CmdBindContainerResult result = CmdBindContainerResult.Parser.ParseFrom(command.Body.Span);
if (_sessionManager.TryGet(result.SessionId, out NetworkSession? session))
{
PlayerGetTokenScRsp rsp;
if (result.Retcode != 0)
{
rsp = new() { Retcode = 1 };
}
else
{
rsp = new()
{
Retcode = 0,
Msg = "OK",
Uid = session.PlayerUid
};
}
await session.SendAsync((ushort)CmdType.CmdPlayerGetTokenScRsp, rsp);
}
}
[ServiceCommand(ServiceCommandType.ForwardGameMessage)]
public async Task OnForwardGameMessage(ServiceCommand command)
{
CmdForwardGameMessage cmd = CmdForwardGameMessage.Parser.ParseFrom(command.Body.Span);
if (_sessionManager.TryGet(cmd.SessionId, out NetworkSession? session))
{
await session.SendAsync(new((ushort)cmd.CmdType, ReadOnlyMemory<byte>.Empty, cmd.Payload.Memory));
}
}
}