From bdc7125d5f07993a68aa0eef3262226002af6af6 Mon Sep 17 00:00:00 2001 From: raphaeIl Date: Wed, 29 May 2024 23:59:32 +0800 Subject: [PATCH] Remove AutoMapper and Auto Generate Password --- .../Api/ProtocolHandlers/Echelon.cs | 27 +++++-------------- SCHALE.GameServer/GameServer.cs | 5 ++-- SCHALE.GameServer/SCHALE.GameServer.csproj | 3 +-- SCHALE.GameServer/Services/AutoMapper.cs | 13 --------- .../Services/ExcelTableService.cs | 8 +++++- 5 files changed, 17 insertions(+), 39 deletions(-) delete mode 100644 SCHALE.GameServer/Services/AutoMapper.cs diff --git a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Echelon.cs b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Echelon.cs index ec6b436..8a286e1 100644 --- a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Echelon.cs +++ b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Echelon.cs @@ -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 _logger, - IMapper _mapper + ILogger _logger ) : ProtocolHandlerBase(protocolHandlerFactory) { private readonly ISessionKeyService sessionKeyService = _sessionKeyService; private readonly SCHALEContext context = _context; private readonly ExcelTableService excelTableService = _excelTableService; private readonly ILogger 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, }; } } } diff --git a/SCHALE.GameServer/GameServer.cs b/SCHALE.GameServer/GameServer.cs index 60d7145..2992010 100644 --- a/SCHALE.GameServer/GameServer.cs +++ b/SCHALE.GameServer/GameServer.cs @@ -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(); diff --git a/SCHALE.GameServer/SCHALE.GameServer.csproj b/SCHALE.GameServer/SCHALE.GameServer.csproj index c4f58f7..d9be2df 100644 --- a/SCHALE.GameServer/SCHALE.GameServer.csproj +++ b/SCHALE.GameServer/SCHALE.GameServer.csproj @@ -7,8 +7,7 @@ - - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/SCHALE.GameServer/Services/AutoMapper.cs b/SCHALE.GameServer/Services/AutoMapper.cs deleted file mode 100644 index e040326..0000000 --- a/SCHALE.GameServer/Services/AutoMapper.cs +++ /dev/null @@ -1,13 +0,0 @@ -using AutoMapper; -using SCHALE.Common.Database; - -namespace SCHALE.GameServer.Services -{ - public class MappingProfile : Profile - { - public MappingProfile() - { - CreateMap().ForMember(x => x.ServerId, opt => opt.Ignore()); - } - } -} diff --git a/SCHALE.GameServer/Services/ExcelTableService.cs b/SCHALE.GameServer/Services/ExcelTableService.cs index 8951b9d..3d63def 100644 --- a/SCHALE.GameServer/Services/ExcelTableService.cs +++ b/SCHALE.GameServer/Services/ExcelTableService.cs @@ -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);