Snowflake/RPG.Services.Gateserver/Network/Command/GateserverCommandHandler.cs

60 lines
2 KiB
C#
Raw Normal View History

2024-01-18 22:13:40 +00:00
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))
{
session.ServiceBound(result.ServiceType);
if (result.ServiceType == RPGServiceType.Gameserver)
2024-01-18 22:13:40 +00:00
{
PlayerGetTokenScRsp rsp;
if (result.Retcode != 0)
2024-01-18 22:13:40 +00:00
{
rsp = new() { Retcode = 1 };
}
else
{
rsp = new()
{
Retcode = 0,
Msg = "OK",
Uid = session.PlayerUid
};
}
2024-01-18 22:13:40 +00:00
await session.SendAsync((ushort)CmdType.CmdPlayerGetTokenScRsp, rsp);
}
2024-01-19 14:45:18 +00:00
}
}
[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));
2024-01-18 22:13:40 +00:00
}
}
}