Protocol: Echelon_List

This commit is contained in:
game4353 2024-05-28 21:28:13 +08:00
parent 1da6abb46f
commit c8a1d72e2a
1 changed files with 14 additions and 19 deletions

View File

@ -6,37 +6,32 @@ using SCHALE.GameServer.Services;
namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
{
public class Echelon : ProtocolHandlerBase
public class Echelon(
IProtocolHandlerFactory protocolHandlerFactory,
ISessionKeyService _sessionKeyService,
SCHALEContext _context,
ExcelTableService _excelTableService
) : ProtocolHandlerBase(protocolHandlerFactory)
{
private readonly ISessionKeyService sessionKeyService;
private readonly SCHALEContext context;
private readonly ExcelTableService excelTableService;
public Echelon(IProtocolHandlerFactory protocolHandlerFactory, ISessionKeyService _sessionKeyService, SCHALEContext _context, ExcelTableService _excelTableService) : base(protocolHandlerFactory)
{
sessionKeyService = _sessionKeyService;
context = _context;
excelTableService = _excelTableService;
}
private readonly ISessionKeyService sessionKeyService = _sessionKeyService;
private readonly SCHALEContext context = _context;
private readonly ExcelTableService excelTableService = _excelTableService;
[ProtocolHandler(Protocol.Echelon_List)]
public ResponsePacket ListHandler(EchelonListRequest req)
{
var account = sessionKeyService.GetAccount(req.SessionKey);
return new EchelonListResponse()
{
EchelonDBs = account.Echelons.ToList()
};
return new EchelonListResponse() { EchelonDBs = [.. account.Echelons] };
}
[ProtocolHandler(Protocol.Echelon_Save)]
public ResponsePacket SaveHandler(EchelonSaveRequest req)
{
return new EchelonSaveResponse()
{
EchelonDB = req.EchelonDB,
};
var db = req.EchelonDB;
context.Echelons.Add(db);
context.SaveChanges();
return new EchelonSaveResponse() { EchelonDB = db, };
}
}
}