Snowflake/RPG.Services.Gameserver/Network/Command/GameserverCommandHandler.cs

44 lines
1.5 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.Gameserver.Session;
namespace RPG.Services.Gameserver.Network.Command;
internal class GameserverCommandHandler : ServiceCommandHandler
{
private readonly SessionManager _sessionManager;
public GameserverCommandHandler(ILogger<ServiceCommandHandler> logger, ServiceBox services, SessionManager sessionManager) : base(logger, services)
{
_sessionManager = sessionManager;
}
[ServiceCommand(ServiceCommandType.BindContainer)]
public Task OnCmdBindContainer(ServiceCommand command)
{
CmdBindContainer cmdBindContainer = CmdBindContainer.Parser.ParseFrom(command.Body.Span);
PlayerSession? session = _sessionManager.Create<PlayerSession>(cmdBindContainer.SessionId);
if (session == null)
{
Send(ServiceCommandType.BindContainerResult, new CmdBindContainerResult
{
Retcode = 1,
SessionId = cmdBindContainer.SessionId
}, command.SenderType);
return Task.CompletedTask;
}
session.PlayerUid = cmdBindContainer.PlayerUid;
Send(ServiceCommandType.BindContainerResult, new CmdBindContainerResult
{
Retcode = 0,
SessionId = cmdBindContainer.SessionId
}, command.SenderType);
return Task.CompletedTask;
}
}