forked from Raphael/SCHALE.GameServer
🛠️Protocol.Echelon_Save
This commit is contained in:
parent
1b042d98e6
commit
f7e0027b86
|
@ -1,4 +1,5 @@
|
||||||
using SCHALE.Common.Database;
|
using AutoMapper;
|
||||||
|
using SCHALE.Common.Database;
|
||||||
using SCHALE.Common.Database.ModelExtensions;
|
using SCHALE.Common.Database.ModelExtensions;
|
||||||
using SCHALE.Common.FlatData;
|
using SCHALE.Common.FlatData;
|
||||||
using SCHALE.Common.NetworkProtocol;
|
using SCHALE.Common.NetworkProtocol;
|
||||||
|
@ -10,13 +11,16 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
|
||||||
IProtocolHandlerFactory protocolHandlerFactory,
|
IProtocolHandlerFactory protocolHandlerFactory,
|
||||||
ISessionKeyService _sessionKeyService,
|
ISessionKeyService _sessionKeyService,
|
||||||
SCHALEContext _context,
|
SCHALEContext _context,
|
||||||
ExcelTableService _excelTableService
|
ExcelTableService _excelTableService,
|
||||||
|
IMapper _mapper
|
||||||
) : ProtocolHandlerBase(protocolHandlerFactory)
|
) : ProtocolHandlerBase(protocolHandlerFactory)
|
||||||
{
|
{
|
||||||
private readonly ISessionKeyService sessionKeyService = _sessionKeyService;
|
private readonly ISessionKeyService sessionKeyService = _sessionKeyService;
|
||||||
private readonly SCHALEContext context = _context;
|
private readonly SCHALEContext context = _context;
|
||||||
private readonly ExcelTableService excelTableService = _excelTableService;
|
private readonly ExcelTableService excelTableService = _excelTableService;
|
||||||
|
|
||||||
|
private readonly IMapper mapper = _mapper;
|
||||||
|
|
||||||
[ProtocolHandler(Protocol.Echelon_List)]
|
[ProtocolHandler(Protocol.Echelon_List)]
|
||||||
public ResponsePacket ListHandler(EchelonListRequest req)
|
public ResponsePacket ListHandler(EchelonListRequest req)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +33,19 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
|
||||||
public ResponsePacket SaveHandler(EchelonSaveRequest req)
|
public ResponsePacket SaveHandler(EchelonSaveRequest req)
|
||||||
{
|
{
|
||||||
var db = req.EchelonDB;
|
var db = req.EchelonDB;
|
||||||
context.Echelons.Add(db);
|
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
|
||||||
|
{
|
||||||
|
db.ServerId = old.ServerId;
|
||||||
|
mapper.Map(db, old);
|
||||||
|
}
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return new EchelonSaveResponse() { EchelonDB = db, };
|
return new EchelonSaveResponse() { EchelonDB = db, };
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
using System.Net.NetworkInformation;
|
||||||
using Serilog.Events;
|
|
||||||
using Serilog;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using AutoMapper;
|
||||||
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using SCHALE.Common.Database;
|
using SCHALE.Common.Database;
|
||||||
|
using SCHALE.GameServer.Commands;
|
||||||
using SCHALE.GameServer.Controllers.Api.ProtocolHandlers;
|
using SCHALE.GameServer.Controllers.Api.ProtocolHandlers;
|
||||||
using SCHALE.GameServer.Services;
|
using SCHALE.GameServer.Services;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using SCHALE.GameServer.Services.Irc;
|
using SCHALE.GameServer.Services.Irc;
|
||||||
using SCHALE.GameServer.Commands;
|
|
||||||
using SCHALE.GameServer.Utils;
|
using SCHALE.GameServer.Utils;
|
||||||
using System.Net.NetworkInformation;
|
using Serilog;
|
||||||
|
using Serilog.Events;
|
||||||
|
|
||||||
namespace SCHALE.GameServer
|
namespace SCHALE.GameServer
|
||||||
{
|
{
|
||||||
|
@ -20,16 +21,26 @@ namespace SCHALE.GameServer
|
||||||
var config = new ConfigurationBuilder()
|
var config = new ConfigurationBuilder()
|
||||||
.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)!)
|
.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)!)
|
||||||
.AddJsonFile("appsettings.json")
|
.AddJsonFile("appsettings.json")
|
||||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
.AddJsonFile(
|
||||||
|
$"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json",
|
||||||
|
true
|
||||||
|
)
|
||||||
.AddJsonFile("appsettings.Local.json", true)
|
.AddJsonFile("appsettings.Local.json", true)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
{
|
{
|
||||||
var logFilePath = Path.Combine(Path.GetDirectoryName(AppContext.BaseDirectory)!, "logs", "log.txt");
|
var logFilePath = Path.Combine(
|
||||||
|
Path.GetDirectoryName(AppContext.BaseDirectory)!,
|
||||||
|
"logs",
|
||||||
|
"log.txt"
|
||||||
|
);
|
||||||
|
|
||||||
if (File.Exists(logFilePath))
|
if (File.Exists(logFilePath))
|
||||||
{
|
{
|
||||||
var prevLogFilePath = Path.Combine(Path.GetDirectoryName(logFilePath)!, "log-prev.txt");
|
var prevLogFilePath = Path.Combine(
|
||||||
|
Path.GetDirectoryName(logFilePath)!,
|
||||||
|
"log-prev.txt"
|
||||||
|
);
|
||||||
if (File.Exists(prevLogFilePath))
|
if (File.Exists(prevLogFilePath))
|
||||||
File.Delete(prevLogFilePath);
|
File.Delete(prevLogFilePath);
|
||||||
|
|
||||||
|
@ -37,10 +48,14 @@ namespace SCHALE.GameServer
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Logger = new LoggerConfiguration()
|
Log.Logger = new LoggerConfiguration()
|
||||||
.WriteTo.Console()
|
.WriteTo.Console()
|
||||||
.WriteTo.File(logFilePath, restrictedToMinimumLevel: LogEventLevel.Verbose, shared: true)
|
.WriteTo.File(
|
||||||
.ReadFrom.Configuration(config)
|
logFilePath,
|
||||||
.CreateBootstrapLogger();
|
restrictedToMinimumLevel: LogEventLevel.Verbose,
|
||||||
|
shared: true
|
||||||
|
)
|
||||||
|
.ReadFrom.Configuration(config)
|
||||||
|
.CreateBootstrapLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Information("Starting...");
|
Log.Information("Starting...");
|
||||||
|
@ -54,26 +69,49 @@ namespace SCHALE.GameServer
|
||||||
|
|
||||||
if (Config.Instance.Address == "127.0.0.1")
|
if (Config.Instance.Address == "127.0.0.1")
|
||||||
{
|
{
|
||||||
Config.Instance.Address = NetworkInterface.GetAllNetworkInterfaces().Where(i => i.NetworkInterfaceType != NetworkInterfaceType.Loopback && i.OperationalStatus == OperationalStatus.Up).First().GetIPProperties().UnicastAddresses.Where(a => a.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).First().Address.ToString();
|
Config.Instance.Address = NetworkInterface
|
||||||
|
.GetAllNetworkInterfaces()
|
||||||
|
.Where(i =>
|
||||||
|
i.NetworkInterfaceType != NetworkInterfaceType.Loopback
|
||||||
|
&& i.OperationalStatus == OperationalStatus.Up
|
||||||
|
)
|
||||||
|
.First()
|
||||||
|
.GetIPProperties()
|
||||||
|
.UnicastAddresses.Where(a =>
|
||||||
|
a.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork
|
||||||
|
)
|
||||||
|
.First()
|
||||||
|
.Address.ToString();
|
||||||
Config.Save();
|
Config.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
builder.Services.Configure<KestrelServerOptions>(op => op.AllowSynchronousIO = true);
|
builder.Services.Configure<KestrelServerOptions>(op =>
|
||||||
|
op.AllowSynchronousIO = true
|
||||||
|
);
|
||||||
builder.Host.UseSerilog();
|
builder.Host.UseSerilog();
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddSQLServerProvider(config.GetConnectionString("SQLServer") ?? throw new ArgumentNullException("ConnectionStrings/SQLServer in appsettings is missing"));
|
builder.Services.AddSQLServerProvider(
|
||||||
|
config.GetConnectionString("SQLServer")
|
||||||
|
?? throw new ArgumentNullException(
|
||||||
|
"ConnectionStrings/SQLServer in appsettings is missing"
|
||||||
|
)
|
||||||
|
);
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
builder.Services.AddAutoMapper(typeof(GameServer));
|
||||||
builder.Services.AddProtocolHandlerFactory();
|
builder.Services.AddProtocolHandlerFactory();
|
||||||
builder.Services.AddMemorySessionKeyService();
|
builder.Services.AddMemorySessionKeyService();
|
||||||
builder.Services.AddExcelTableService();
|
builder.Services.AddExcelTableService();
|
||||||
builder.Services.AddIrcService();
|
builder.Services.AddIrcService();
|
||||||
|
|
||||||
// Add all Handler Groups
|
// Add all Handler Groups
|
||||||
var handlerGroups = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(ProtocolHandlerBase)));
|
var handlerGroups = Assembly
|
||||||
|
.GetExecutingAssembly()
|
||||||
|
.GetTypes()
|
||||||
|
.Where(t => t.IsSubclassOf(typeof(ProtocolHandlerBase)));
|
||||||
|
|
||||||
foreach (var handlerGroup in handlerGroups)
|
foreach (var handlerGroup in handlerGroups)
|
||||||
builder.Services.AddProtocolHandlerGroupByType(handlerGroup);
|
builder.Services.AddProtocolHandlerGroupByType(handlerGroup);
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
using AutoMapper;
|
||||||
|
using SCHALE.Common.Database;
|
||||||
|
|
||||||
|
namespace SCHALE.GameServer.Services
|
||||||
|
{
|
||||||
|
public class MappingProfile : Profile
|
||||||
|
{
|
||||||
|
public MappingProfile()
|
||||||
|
{
|
||||||
|
CreateMap<EchelonDB, EchelonDB>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue