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 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.Empty, cmd.Payload.Memory)); } } }