1
0
mirror of synced 2024-11-23 22:41:01 +01:00

Move settings to separate files

Add data settings
This commit is contained in:
asesidaa 2022-10-20 02:28:53 +08:00
parent 059d053ea7
commit 466baadbe3
10 changed files with 129 additions and 68 deletions

View File

@ -0,0 +1,7 @@
{
"DataSettings" : {
"DanDataFileName" : "dan_data.json",
"EventDataFileName" : "event_data.json",
"IntroDataFileName" : "intro_data.json"
}
}

View File

@ -0,0 +1,3 @@
{
"DbFileName" : "taiko.db3"
}

View File

@ -0,0 +1,28 @@
{
"Kestrel": {
"Endpoints": {
"BaseServer": {
"Url": "http://0.0.0.0:5000"
},
"AmAuthServer": {
"Url": "http://0.0.0.0:80"
},
"MuchaServer": {
"Url": "https://0.0.0.0:10122"
},
"GameServer1": {
"Url": "https://0.0.0.0:54430"
},
"GameServer2": {
"Url": "https://0.0.0.0:54431"
}
},
"Certificates": {
"Default": {
"Path": "Certificates/cert.pfx",
"Password": "",
"AllowInvalid": true
}
}
}
}

View File

@ -0,0 +1,27 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.AspNetCore": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "@mt = 'An unhandled exception has occurred while executing the request.'"
}
}
],
"WriteTo": [
{
"Name": "File",
"Args": { "path": "./Logs/log-.txt", "rollingInterval": "Day" }
}
]
}
}

View File

@ -0,0 +1,7 @@
{
"ServerSettings": {
"MuchaUrl": "https://v402-front.mucha-prd.nbgi-amnet.jp:10122",
"GameUrl": "vsapi.taiko-p.jp",
"EnableMoreSongs": true
}
}

View File

@ -20,6 +20,17 @@ Log.Information("Server starting up...");
try
{
var builder = WebApplication.CreateBuilder(args);
builder.Host.ConfigureAppConfiguration((hostingContext, config) =>
{
const string configurationsDirectory = "Configurations";
config.AddJsonFile($"{configurationsDirectory}/Kestrel.json", optional: true, reloadOnChange: false);
config.AddJsonFile($"{configurationsDirectory}/Logging.json", optional: false, reloadOnChange: false);
config.AddJsonFile($"{configurationsDirectory}/Database.json", optional: false, reloadOnChange: false);
config.AddJsonFile($"{configurationsDirectory}/ServerSettings.json", optional: false, reloadOnChange: false);
config.AddJsonFile($"{configurationsDirectory}/DataSettings.json", optional: true, reloadOnChange: false);
});
// Manually enable tls 1.0
builder.WebHost.UseKestrel(kestrelOptions =>
{
@ -34,15 +45,14 @@ try
if (builder.Configuration.GetValue<bool>("ServerSettings:EnableMoreSongs"))
{
Log.Warning("Song limit expanded! Currently the game has issue loading crown/score rank and " +
"probably more server related data for songs with id > 1599. " +
"Also, the game can have random crashes because of that! Use at your own risk!");
Log.Warning("Song limit expanded! Use at your own risk!");
}
// Add services to the container.
builder.Services.AddOptions();
builder.Services.AddSingleton<IGameDataService, GameDataService>();
builder.Services.Configure<ServerSettings>(builder.Configuration.GetSection(nameof(ServerSettings)));
builder.Services.Configure<DataSettings>(builder.Configuration.GetSection(nameof(DataSettings)));
builder.Services.AddControllers().AddProtoBufNet();
builder.Services.AddDbContext<TaikoDbContext>(option =>
{

View File

@ -1,8 +1,10 @@
using System.Collections.Immutable;
using System.Text.Json;
using ICSharpCode.SharpZipLib.GZip;
using Microsoft.Extensions.Options;
using SharedProject.Models;
using Swan.Mapping;
using TaikoLocalServer.Settings;
using Throw;
namespace TaikoLocalServer.Services;
@ -21,6 +23,13 @@ public class GameDataService : IGameDataService
private List<uint> musics = new();
private List<uint> musicsWithUra = new();
private readonly DataSettings settings;
public GameDataService(IOptions<DataSettings> settings)
{
this.settings = settings.Value;
}
public List<uint> GetMusicList()
{
@ -51,10 +60,11 @@ public class GameDataService : IGameDataService
{
var dataPath = PathHelper.GetDataPath();
var musicAttributePath = Path.Combine(dataPath, Constants.MUSIC_ATTRIBUTE_FILE_NAME);
var danDataPath = Path.Combine(dataPath, Constants.DAN_DATA_FILE_NAME);
var songIntroDataPath = Path.Combine(dataPath, Constants.INTRO_DATA_FILE_NAME);
var compressedMusicAttributePath = Path.Combine(dataPath, Constants.MUSIC_ATTRIBUTE_COMPRESSED_FILE_NAME);
var danDataPath = Path.Combine(dataPath, settings.DanDataFileName);
var songIntroDataPath = Path.Combine(dataPath, settings.IntroDataFileName);
if (!File.Exists(musicAttributePath))
if (File.Exists(compressedMusicAttributePath))
{
TryDecompressMusicAttribute();
}

View File

@ -0,0 +1,10 @@
namespace TaikoLocalServer.Settings;
public class DataSettings
{
public string DanDataFileName { get; set; } = "dan_data.json";
public string EventDataFileName { get; set; } = "event_data.json";
public string IntroDataFileName { get; set; } = "intro_data.json";
}

View File

@ -38,6 +38,26 @@
<None Update="Certificates\root.pfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Remove="Configurations\ServerSettings.json" />
<None Include="Configurations\ServerSettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Remove="Configurations\Database.json" />
<None Include="Configurations\Database.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Remove="Configurations\DataSettings.json" />
<None Include="Configurations\DataSettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Remove="Configurations\Kestrel.json" />
<None Include="Configurations\Kestrel.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Remove="Configurations\Logging.json" />
<None Include="Configurations\Logging.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>

View File

@ -1,64 +1,3 @@
{
"ServerSettings": {
"MuchaUrl": "https://v402-front.mucha-prd.nbgi-amnet.jp:10122",
"GameUrl": "vsapi.taiko-p.jp",
"EnableMoreSongs": false
},
"DbFileName" : "taiko.db3",
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.AspNetCore": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "@mt = 'An unhandled exception has occurred while executing the request.'"
}
}
],
"WriteTo": [
{
"Name": "File",
"Args": { "path": "./Logs/log-.txt", "rollingInterval": "Day" }
}
]
},
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"BaseServer": {
"Url": "http://0.0.0.0:5000"
},
"AmAuthServer": {
"Url": "http://0.0.0.0:80"
},
"MuchaServer": {
"Url": "https://0.0.0.0:10122"
},
"GameServer1": {
"Url": "https://0.0.0.0:54430"
},
"GameServer2": {
"Url": "https://0.0.0.0:54431"
}
},
"Certificates": {
"Default": {
"Path": "Certificates/cert.pfx",
"Password": "",
"AllowInvalid": true
}
}
}
"AllowedHosts": "*"
}