Remove AutoMapper and Auto Generate Password

This commit is contained in:
raphaeIl 2024-05-29 23:59:32 +08:00
parent 39316c95ff
commit bdc7125d5f
5 changed files with 17 additions and 39 deletions

View File

@ -1,5 +1,4 @@
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using SCHALE.Common.Database;
using SCHALE.Common.Database.ModelExtensions;
using SCHALE.Common.FlatData;
@ -13,15 +12,13 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
ISessionKeyService _sessionKeyService,
SCHALEContext _context,
ExcelTableService _excelTableService,
ILogger<Echelon> _logger,
IMapper _mapper
ILogger<Echelon> _logger
) : ProtocolHandlerBase(protocolHandlerFactory)
{
private readonly ISessionKeyService sessionKeyService = _sessionKeyService;
private readonly SCHALEContext context = _context;
private readonly ExcelTableService excelTableService = _excelTableService;
private readonly ILogger<Echelon> logger = _logger;
private readonly IMapper mapper = _mapper;
[ProtocolHandler(Protocol.Echelon_List)]
public ResponsePacket ListHandler(EchelonListRequest req)
@ -35,23 +32,11 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
public ResponsePacket SaveHandler(EchelonSaveRequest req)
{
var db = req.EchelonDB;
var old = context.Echelons.FirstOrDefault(e =>
e.AccountServerId == db.AccountServerId
&& e.EchelonType == db.EchelonType
&& e.EchelonNumber == db.EchelonNumber
&& e.ExtensionType == db.ExtensionType
);
if (old == null)
context.Echelons.Add(db);
else
{
// https://github.com/dotnet/efcore/issues/9156
context.Entry(old).State = EntityState.Detached;
mapper.Map(db, old);
context.Entry(old).State = EntityState.Modified;
}
context.Echelons.Add(db);
context.SaveChanges();
return new EchelonSaveResponse() { EchelonDB = db, };
return new EchelonSaveResponse() { EchelonDB = req.EchelonDB, };
}
}
}

View File

@ -1,8 +1,10 @@
using System.Collections;
using System.Net.NetworkInformation;
using System.Reflection;
using AutoMapper;
using System.Text;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.EntityFrameworkCore;
using SCHALE.Common.Crypto;
using SCHALE.Common.Database;
using SCHALE.GameServer.Commands;
using SCHALE.GameServer.Controllers.Api.ProtocolHandlers;
@ -103,7 +105,6 @@ namespace SCHALE.GameServer
)
);
builder.Services.AddControllers();
builder.Services.AddAutoMapper(typeof(GameServer));
builder.Services.AddProtocolHandlerFactory();
builder.Services.AddMemorySessionKeyService();
builder.Services.AddExcelTableService();

View File

@ -7,8 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="DotNetZip" Version="1.16.0" />
<PackageReference Include="DotNetZip" Version="1.16.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>

View File

@ -1,13 +0,0 @@
using AutoMapper;
using SCHALE.Common.Database;
namespace SCHALE.GameServer.Services
{
public class MappingProfile : Profile
{
public MappingProfile()
{
CreateMap<EchelonDB, EchelonDB>().ForMember(x => x.ServerId, opt => opt.Ignore());
}
}
}

View File

@ -1,10 +1,12 @@
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Google.FlatBuffers;
using Ionic.Zip;
using SCHALE.Common.Crypto;
using Serilog;
namespace SCHALE.GameServer.Services
{
@ -44,9 +46,11 @@ namespace SCHALE.GameServer.Services
private static async Task GetZip()
{
string url = GetUrl();
string filePath = "TableBundles/Excel.zip";
string zipPath = Path.Combine(ResourcesFolder!, "download", filePath);
ExcelFolder = zipPath[..^4];
if (File.Exists(zipPath))
return;
@ -58,7 +62,9 @@ namespace SCHALE.GameServer.Services
byte[] content = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes(zipPath, content);
using ZipFile zip = ZipFile.Read(zipPath);
zip.Password = "/wy5f3hIGGXLOIUDS9DZ";
//zip.Password = "/wy5f3hIGGXLOIUDS9DZ";
zip.Password = Convert.ToBase64String(TableService.CreatePassword(Path.GetFileName(filePath)));
foreach (ZipEntry e in zip)
{
e.Extract(ExcelFolder, ExtractExistingFileAction.OverwriteSilently);