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

33 lines
1,020 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 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();
}
}