Add race mode, serilog
This commit is contained in:
@@ -12,6 +12,10 @@
|
||||
<PackageReference Include="Azure.Identity" Version="1.13.2" />
|
||||
<PackageReference Include="Azure.Storage.Blobs" Version="12.23.0" />
|
||||
<PackageReference Include="Microsoft.Azure.WebPubSub.AspNetCore" Version="1.4.0" />
|
||||
<PackageReference Include="Serilog" Version="4.2.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public static class JsonOptions {
|
||||
public static JsonSerializerOptions Default = new JsonSerializerOptions() {
|
||||
public static JsonSerializerOptions Default = new JsonSerializerOptions(JsonSerializerDefaults.Web) {
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
|
||||
NumberHandling = JsonNumberHandling.Strict,
|
||||
}.WithStringEnum();
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public class SeedSettings {
|
||||
[NoSettingName]
|
||||
public RaceMode Race { get; set; } = RaceMode.Normal;
|
||||
|
||||
public Mode Mode { get; set; } = Mode.Open;
|
||||
|
||||
[SettingName("swords")]
|
||||
@@ -54,6 +57,11 @@
|
||||
public PrizeShuffle PrizeShuffle { get; set; } = PrizeShuffle.Vanilla;
|
||||
}
|
||||
|
||||
public enum RaceMode {
|
||||
Normal,
|
||||
[AdditionalSetting("--securerandom")] Race,
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
Open,
|
||||
Standard,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace ALttPRandomizer
|
||||
{
|
||||
using System.Text.Json.Serialization;
|
||||
using ALttPRandomizer.Azure;
|
||||
using ALttPRandomizer.Options;
|
||||
using ALttPRandomizer.Service;
|
||||
@@ -12,6 +11,7 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Serilog;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
@@ -26,8 +26,13 @@
|
||||
|
||||
builder.Services.Configure<ServiceOptions>(builder.Configuration.GetSection("ALttPRandomizer"));
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(builder.Configuration)
|
||||
.CreateLogger();
|
||||
|
||||
builder.Services.AddLogging(logger => {
|
||||
logger.AddConsole();
|
||||
logger.ClearProviders();
|
||||
logger.AddSerilog();
|
||||
});
|
||||
|
||||
var provider = builder.Services.BuildServiceProvider();
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
private ServiceOptions Configuration => this.OptionsMonitor.CurrentValue;
|
||||
|
||||
public void Randomize(string id, SeedSettings settings) {
|
||||
this.Logger.LogDebug("Recieved request for id {id} to randomize settings {@settings}", id, settings);
|
||||
|
||||
var start = new ProcessStartInfo() {
|
||||
FileName = Configuration.PythonPath,
|
||||
WorkingDirectory = Configuration.RandomizerPath,
|
||||
@@ -112,7 +114,7 @@
|
||||
this.Logger.LogDebug("Deleting file {filepath}", rom);
|
||||
File.Delete(rom);
|
||||
|
||||
this.Logger.LogDebug("Finished uploading seed id {id}", id);
|
||||
this.Logger.LogInformation("Finished uploading seed id {id}", id);
|
||||
}
|
||||
|
||||
private JsonDocument ProcessMetadata(string path) {
|
||||
|
||||
@@ -2,16 +2,19 @@
|
||||
using ALttPRandomizer.Model;
|
||||
using ALttPRandomizer.Service;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class GenerateController : Controller {
|
||||
public GenerateController(RandomizeService randomizeService, SeedService seedService) {
|
||||
public class SeedController : Controller {
|
||||
public SeedController(RandomizeService randomizeService, SeedService seedService, ILogger<SeedController> logger) {
|
||||
this.RandomizeService = randomizeService;
|
||||
this.SeedService = seedService;
|
||||
this.Logger = logger;
|
||||
}
|
||||
|
||||
private RandomizeService RandomizeService { get; }
|
||||
private SeedService SeedService { get; }
|
||||
private ILogger<SeedController> Logger { get; }
|
||||
|
||||
[Route("/generate")]
|
||||
[HttpPost]
|
||||
@@ -25,7 +28,19 @@
|
||||
[HttpGet]
|
||||
public async Task<ActionResult> GetSeed(string id) {
|
||||
var result = await this.SeedService.GetSeed(id);
|
||||
return Ok(result);
|
||||
if (result.TryGetValue("status", out var responseCode)) {
|
||||
switch (responseCode) {
|
||||
case 200:
|
||||
return Ok(result);
|
||||
case 404:
|
||||
return NotFound(result);
|
||||
case 409:
|
||||
return Conflict(result);
|
||||
}
|
||||
}
|
||||
|
||||
this.Logger.LogWarning("Unexpected result from SeedService: {@result}", result);
|
||||
return StatusCode(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
namespace ALttPRandomizer.Service {
|
||||
using ALttPRandomizer.Azure;
|
||||
using ALttPRandomizer.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
@@ -17,24 +18,41 @@
|
||||
|
||||
var result = new Dictionary<string, object>();
|
||||
|
||||
if (files.TryGetValue("settings.json", out var settingsData)) {
|
||||
var json = JsonDocument.Parse(settingsData.ToString());
|
||||
result["settings"] = json;
|
||||
if (!files.TryGetValue("settings.json", out var settingsData)) {
|
||||
result["status"] = 404;
|
||||
result["error"] = "seed not found";
|
||||
return result;
|
||||
}
|
||||
|
||||
var settingsJson = JsonDocument.Parse(settingsData.ToString());
|
||||
result["settings"] = settingsJson;
|
||||
|
||||
var settings = settingsJson.Deserialize<SeedSettings>(JsonOptions.Default) ?? new SeedSettings();
|
||||
|
||||
if (!files.TryGetValue("patch.bps", out var patchData)) {
|
||||
if (files.ContainsKey("generating")) {
|
||||
result["status"] = 409;
|
||||
result["error"] = "generation still in progress";
|
||||
return result;
|
||||
} else {
|
||||
result["status"] = 404;
|
||||
result["error"] = "generation failed";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
result["patch"] = Convert.ToBase64String(patchData.ToArray());
|
||||
|
||||
if (files.TryGetValue("meta.json", out var metaData)) {
|
||||
var json = JsonDocument.Parse(metaData.ToString());
|
||||
result["meta"] = json;
|
||||
}
|
||||
|
||||
if (files.TryGetValue("spoiler.json", out var spoilerData)) {
|
||||
if (settings.Race != RaceMode.Race && files.TryGetValue("spoiler.json", out var spoilerData)) {
|
||||
var json = JsonDocument.Parse(spoilerData.ToString());
|
||||
result["spoiler"] = json;
|
||||
}
|
||||
|
||||
if (files.TryGetValue("patch.bps", out var patchData)) {
|
||||
result["patch.bps"] = Convert.ToBase64String(patchData.ToArray());
|
||||
}
|
||||
result["status"] = 200;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -12,9 +12,12 @@
|
||||
"blobstoreEndpoint": "https://alttprstorage.blob.core.windows.net/seeds"
|
||||
}
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information"
|
||||
}
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.Console" ],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{ "Name": "Console" }
|
||||
],
|
||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,12 @@
|
||||
{
|
||||
"ALttPRandomizer": {
|
||||
},
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.Console" ],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{ "Name": "Console" }
|
||||
],
|
||||
"Enrich": [ "FromLogContext" ]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user