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,
|
2024-01-19 22:39:12 +00:00
|
|
|
|
SessionId = cmdBindContainer.SessionId,
|
|
|
|
|
ServiceType = RPGServiceType.Gameserver
|
2024-01-18 22:13:40 +00:00
|
|
|
|
}, command.SenderType);
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
session.PlayerUid = cmdBindContainer.PlayerUid;
|
|
|
|
|
Send(ServiceCommandType.BindContainerResult, new CmdBindContainerResult
|
|
|
|
|
{
|
|
|
|
|
Retcode = 0,
|
2024-01-19 22:39:12 +00:00
|
|
|
|
SessionId = cmdBindContainer.SessionId,
|
|
|
|
|
ServiceType = RPGServiceType.Gameserver
|
2024-01-18 22:13:40 +00:00
|
|
|
|
}, command.SenderType);
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
2024-01-19 14:45:18 +00:00
|
|
|
|
|
|
|
|
|
[ServiceCommand(ServiceCommandType.UnbindContainer)]
|
|
|
|
|
public Task OnCmdUnbindContainer(ServiceCommand command)
|
|
|
|
|
{
|
|
|
|
|
CmdUnbindContainer cmdUnbindContainer = CmdUnbindContainer.Parser.ParseFrom(command.Body.Span);
|
|
|
|
|
|
|
|
|
|
if (_sessionManager.TryGet(cmdUnbindContainer.SessionId, out PlayerSession? session))
|
|
|
|
|
{
|
|
|
|
|
_sessionManager.Remove(session);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ServiceCommand(ServiceCommandType.ForwardGameMessage)]
|
|
|
|
|
public async Task OnCmdForwardGameMessage(ServiceCommand command)
|
|
|
|
|
{
|
|
|
|
|
CmdForwardGameMessage cmd = CmdForwardGameMessage.Parser.ParseFrom(command.Body.Span);
|
|
|
|
|
|
|
|
|
|
if (_sessionManager.TryGet(cmd.SessionId, out PlayerSession? session))
|
|
|
|
|
{
|
|
|
|
|
await session.HandleGameCommand((ushort)cmd.CmdType, cmd.Payload.Memory);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-21 15:34:19 +00:00
|
|
|
|
|
|
|
|
|
[ServiceCommand(ServiceCommandType.GmtalkByMuip)]
|
|
|
|
|
public async Task OnCmdGmtalkByMuip(ServiceCommand command)
|
|
|
|
|
{
|
|
|
|
|
CmdGmtalkByMuip cmd = CmdGmtalkByMuip.Parser.ParseFrom(command.Body.Span);
|
|
|
|
|
|
|
|
|
|
if (_sessionManager.TryGet(cmd.SessionId, out PlayerSession? session))
|
|
|
|
|
{
|
|
|
|
|
await session.HandleGmTalkCommand(cmd.Msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-18 22:13:40 +00:00
|
|
|
|
}
|