Skip to content

Commit

Permalink
Seperate server executeable and api controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
cubicgraphics committed May 14, 2024
1 parent 8dec8da commit 946fada
Show file tree
Hide file tree
Showing 26 changed files with 202 additions and 179 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Title>$(AssemblyName)</Title>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using BeatTogether.Status.Api.Models;
using System.Collections.Generic;

namespace BeatTogether.Status.Api.Configuration
{
public class QuickplayConfiguration
{
public List<PredefinedPack> PredefinedPacks { get; set; } = new();
public List<LocalizedCustomPack> LocalizedCustomPacks { get; set; } = new();
}
}
using BeatTogether.Status.Api.Controllers.Models;
using System.Collections.Generic;

namespace BeatTogether.Status.Api.Controllers.Configuration
{
public class QuickplayConfiguration
{
public List<PredefinedPack> PredefinedPacks { get; set; } = new();
public List<LocalizedCustomPack> LocalizedCustomPacks { get; set; } = new();
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
using System.Collections.Generic;
using BeatTogether.Status.Api.Models;

namespace BeatTogether.Status.Api.Configuration
{
public class StatusConfiguration
{
public string MinimumAppVersion { get; set; } = "1.0.0";
public long MaintenanceStartTime { get; set; }
public long MaintenanceEndTime { get; set; }
public List<LocalizedMessage> LocalizedMessages { get; set; } = new();
public List<RequiredMod> RequiredMods { get; set; } = new();
/// <summary>
/// Prefer SSL (DTLS) for dedicated server connections?
/// </summary>
public bool UseSsl { get; set; } = false;
public string ServerDisplayName { get; set; } = string.Empty;
public string ServerDescription { get; set; } = string.Empty;
public string ServerImageUrl { get; set; } = string.Empty;
public int MaxPlayers { get; set; } = 25;
public bool ServerSupportsPpModifiers { get; set; } = false;
public bool ServerSupportsPpDifficulties { get; set; } = false;
public bool ServerSupportsPpMaps { get; set; } = false;
}
}
using System.Collections.Generic;
using BeatTogether.Status.Api.Controllers.Models;

namespace BeatTogether.Status.Api.Controllers.Configuration
{
public class StatusConfiguration
{
public string MinimumAppVersion { get; set; } = "1.0.0";
public long MaintenanceStartTime { get; set; }
public long MaintenanceEndTime { get; set; }
public List<LocalizedMessage> LocalizedMessages { get; set; } = new();
public List<RequiredMod> RequiredMods { get; set; } = new();
/// <summary>
/// Prefer SSL (DTLS) for dedicated server connections?
/// </summary>
public bool UseSsl { get; set; } = false;
public string ServerDisplayName { get; set; } = string.Empty;
public string ServerDescription { get; set; } = string.Empty;
public string ServerImageUrl { get; set; } = string.Empty;
public int MaxPlayers { get; set; } = 25;
public bool ServerSupportsPpModifiers { get; set; } = false;
public bool ServerSupportsPpDifficulties { get; set; } = false;
public bool ServerSupportsPpMaps { get; set; } = false;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using BeatTogether.Status.Api.Configuration;
using BeatTogether.Status.Api.Models;
using BeatTogether.Status.Api.Controllers.Configuration;
using BeatTogether.Status.Api.Controllers.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

namespace BeatTogether.Status.Api.Controllers
namespace BeatTogether.Status.Api.Controllers.Controllers
{
[ApiController]
[Route("status/mp_override.json")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
using System;
using BeatTogether.Status.Api.Configuration;
using BeatTogether.Status.Api.Enums;
using BeatTogether.Status.Api.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

namespace BeatTogether.Status.Api.Controllers
{
[ApiController]
[Route("status")]
public class StatusController : ControllerBase
{
private readonly StatusConfiguration _configuration;

public StatusController(IOptionsSnapshot<StatusConfiguration> configuration)
{
_configuration = configuration.Value;
}

[HttpGet]
public MasterServerStatusData Get()
{
var status = AvailabilityStatus.Online;
var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
if (timestamp < _configuration.MaintenanceStartTime)
status = AvailabilityStatus.MaintenanceUpcoming;
else if (timestamp < _configuration.MaintenanceEndTime)
status = AvailabilityStatus.Offline;
return new MasterServerStatusData(
_configuration.MinimumAppVersion,
status,
_configuration.MaintenanceStartTime,
_configuration.MaintenanceEndTime,
new UserMessage(_configuration.LocalizedMessages),
_configuration.RequiredMods,
_configuration.UseSsl,
_configuration.ServerDisplayName,
_configuration.ServerDescription,
_configuration.ServerImageUrl,
_configuration.MaxPlayers,
_configuration.ServerSupportsPpModifiers,
_configuration.ServerSupportsPpDifficulties,
_configuration.ServerSupportsPpMaps
);
}
}
}
using System;
using BeatTogether.Status.Api.Controllers.Configuration;
using BeatTogether.Status.Api.Controllers.Enums;
using BeatTogether.Status.Api.Controllers.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

namespace BeatTogether.Status.Api.Controllers.Controllers
{
[ApiController]
[Route("status")]
public class StatusController : ControllerBase
{
private readonly StatusConfiguration _configuration;

public StatusController(IOptionsSnapshot<StatusConfiguration> configuration)
{
_configuration = configuration.Value;
}

[HttpGet]
public MasterServerStatusData Get()
{
var status = AvailabilityStatus.Online;
var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
if (timestamp < _configuration.MaintenanceStartTime)
status = AvailabilityStatus.MaintenanceUpcoming;
else if (timestamp < _configuration.MaintenanceEndTime)
status = AvailabilityStatus.Offline;
return new MasterServerStatusData(
_configuration.MinimumAppVersion,
status,
_configuration.MaintenanceStartTime,
_configuration.MaintenanceEndTime,
new UserMessage(_configuration.LocalizedMessages),
_configuration.RequiredMods,
_configuration.UseSsl,
_configuration.ServerDisplayName,
_configuration.ServerDescription,
_configuration.ServerImageUrl,
_configuration.MaxPlayers,
_configuration.ServerSupportsPpModifiers,
_configuration.ServerSupportsPpDifficulties,
_configuration.ServerSupportsPpMaps
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BeatTogether.Status.Api.Enums
namespace BeatTogether.Status.Api.Controllers.Enums
{
public enum AvailabilityStatus
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BeatTogether.Status.Api.Enums
namespace BeatTogether.Status.Api.Controllers.Enums
{
public enum Language
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Extensions.Hosting;
using BeatTogether.Extensions;
using BeatTogether.Status.Api.Controllers.Configuration;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;

namespace BeatTogether.Status.Api.Controllers.Extensions
{
public static class HostBuilderExtensions
{
public static IHostBuilder UseStatusServer(this IHostBuilder hostBuilder) =>
hostBuilder
.ConfigureAppConfiguration()
.ConfigureServices((hostBuilderContext, services) =>
services
.Configure<StatusConfiguration>(hostBuilderContext.Configuration.GetSection("Status"))
.Configure<QuickplayConfiguration>(hostBuilderContext.Configuration.GetSection("Quickplay"))
);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Collections.Generic;

namespace BeatTogether.Status.Api.Models
{
public class LocalizedCustomPack
{
public string serializedName { get; set; } = string.Empty;
public int order { get; set; }
public List<LocalizedCustomPackName> localizedNames { get; set; } = new();
public List<string> packIds { get; set; } = new();
}
}
using System.Collections.Generic;

namespace BeatTogether.Status.Api.Controllers.Models
{
public class LocalizedCustomPack
{
public string serializedName { get; set; } = string.Empty;
public int order { get; set; }
public List<LocalizedCustomPackName> localizedNames { get; set; } = new();
public List<string> packIds { get; set; } = new();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using BeatTogether.Status.Api.Enums;

namespace BeatTogether.Status.Api.Models
{
public class LocalizedCustomPackName
{
public Language language { get; set; }
public string packName { get; set; } = string.Empty;
}
}
using BeatTogether.Status.Api.Controllers.Enums;

namespace BeatTogether.Status.Api.Controllers.Models
{
public class LocalizedCustomPackName
{
public Language language { get; set; }
public string packName { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using BeatTogether.Status.Api.Enums;

namespace BeatTogether.Status.Api.Models
{
public class LocalizedMessage
{
public Language language { get; set; }
public string message { get; set; } = string.Empty;
}
}
using BeatTogether.Status.Api.Controllers.Enums;

namespace BeatTogether.Status.Api.Controllers.Models
{
public class LocalizedMessage
{
public Language language { get; set; }
public string message { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace BeatTogether.Status.Api.Models
namespace BeatTogether.Status.Api.Controllers.Models
{
public record MasterServerQuickplayData(QuickplaySongPacksOverride quickPlayAvailablePacksOverride);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using BeatTogether.Status.Api.Enums;
using BeatTogether.Status.Api.Controllers.Enums;
using System.Collections.Generic;

namespace BeatTogether.Status.Api.Models
namespace BeatTogether.Status.Api.Controllers.Models
{
public record MasterServerStatusData(
string minimumAppVersion,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace BeatTogether.Status.Api.Models
{
public class PredefinedPack
{
public int order { get; set; }
public string packId { get; set; } = string.Empty;
}
}
namespace BeatTogether.Status.Api.Controllers.Models
{
public class PredefinedPack
{
public int order { get; set; }
public string packId { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BeatTogether.Status.Api.Models

namespace BeatTogether.Status.Api.Controllers.Models
{
public record QuickplaySongPacksOverride(
List<PredefinedPack> predefinedPackIds,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
namespace BeatTogether.Status.Api.Models
{
public record RequiredMod
{
/// <summary>
/// BSIPA Mod ID
/// </summary>
public string id { get; set; } = string.Empty;
/// <summary>
/// Minimum version of the mod required, if installed
/// </summary>
public string version { get; set; } = string.Empty;
/// <summary>
/// Indicates whether the mod must be installed
/// </summary>
public bool required { get; set; } = false;
}
namespace BeatTogether.Status.Api.Controllers.Models
{
public record RequiredMod
{
/// <summary>
/// BSIPA Mod ID
/// </summary>
public string id { get; set; } = string.Empty;
/// <summary>
/// Minimum version of the mod required, if installed
/// </summary>
public string version { get; set; } = string.Empty;
/// <summary>
/// Indicates whether the mod must be installed
/// </summary>
public bool required { get; set; } = false;
}
}
5 changes: 5 additions & 0 deletions BeatTogether.Status.Api.Controllers/Models/UserMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

namespace BeatTogether.Status.Api.Controllers.Models
{
public record UserMessage(List<LocalizedMessage> localizedMessages);
}
File renamed without changes.
Loading

0 comments on commit 946fada

Please sign in to comment.