KafkaSR/RPG.Services.Gameserver/Session/PlayerSession.cs

27 lines
985 B
C#
Raw Permalink Normal View History

2024-01-29 23:49:21 +00:00
using Microsoft.Extensions.DependencyInjection;
using RPG.Network.Proto;
using RPG.Services.Core.Network;
using RPG.Services.Core.Session;
using RPG.Services.Gameserver.Modules;
namespace RPG.Services.Gameserver.Session;
internal class PlayerSession : RPGSession
{
private readonly IServiceScope _scope;
private readonly ModuleManager _moduleManager;
public PlayerSession(ulong sessionId, ServiceBox serviceBox, IServiceScopeFactory scopeFactory) : base(sessionId, serviceBox)
{
_scope = scopeFactory.CreateScope();
_moduleManager = _scope.ServiceProvider.GetRequiredService<ModuleManager>();
}
public async Task HandleGmTalkCommand(string cmd) =>
await _moduleManager.HandleGmCommandAsync(this, cmd.Split(' '));
public async Task HandleGameCommand(ushort cmdType, ReadOnlyMemory<byte> body) =>
await _moduleManager.HandleAsync(this, (CmdType)cmdType, body);
public override void Dispose() => _scope.Dispose();
}