Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using CoreRCON;
|
|
using LANCommander.SDK.Enums;
|
|
using LANCommander.Server.Data;
|
|
using LANCommander.Server.Data.Models;
|
|
using Microsoft.Extensions.Logging;
|
|
using AutoMapper;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using ZiggyCreatures.Caching.Fusion;
|
|
|
|
namespace LANCommander.Server.Services
|
|
{
|
|
public sealed class ServerConsoleService(
|
|
ILogger<ServerConsoleService> logger,
|
|
SettingsProvider<Settings.Settings> settingsProvider,
|
|
IFusionCache cache,
|
|
IMapper mapper,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
IDbContextFactory<DatabaseContext> contextFactory) : BaseDatabaseService<ServerConsole>(logger, settingsProvider, cache, mapper, httpContextAccessor, contextFactory)
|
|
{
|
|
public override async Task<ServerConsole> AddAsync(ServerConsole entity)
|
|
{
|
|
return await base.AddAsync(entity, async context =>
|
|
{
|
|
await context.UpdateRelationshipAsync(sc => sc.Server);
|
|
});
|
|
}
|
|
|
|
public override async Task<ServerConsole> UpdateAsync(ServerConsole entity)
|
|
{
|
|
return await base.UpdateAsync(entity, async context =>
|
|
{
|
|
await context.UpdateRelationshipAsync(sc => sc.Server);
|
|
});
|
|
}
|
|
|
|
public async Task<string[]> ReadLogAsync(Guid logId)
|
|
{
|
|
var log = await GetAsync(logId);
|
|
|
|
if (log.Type != ServerConsoleType.LogFile)
|
|
throw new Exception("Invalid console type");
|
|
|
|
var logPath = Path.Combine(log.Server.WorkingDirectory, log.Path);
|
|
|
|
return await File.ReadAllLinesAsync(logPath);
|
|
}
|
|
}
|
|
}
|