Snowflake/RPG.Services.Gameserver/Session/PlayerSession.cs
2024-01-19 17:45:18 +03:00

28 lines
880 B
C#

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 HandleGameCommand(ushort cmdType, ReadOnlyMemory<byte> body)
{
await _moduleManager.HandleAsync(this, (CmdType)cmdType, body);
}
public override void Dispose()
{
_scope.Dispose();
}
}