Skip to content

Commit

Permalink
Merge pull request #6 from BeatTogether/1.37.0
Browse files Browse the repository at this point in the history
1.37.0
  • Loading branch information
cubicgraphics authored Aug 24, 2024
2 parents decf0d6 + 12f16b6 commit 353998f
Show file tree
Hide file tree
Showing 34 changed files with 283 additions and 207 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="BeatTogether.Extensions.Serilog" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.29" />
</ItemGroup>

</Project>
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
@@ -0,0 +1,25 @@
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,40 +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 MasterServerAvailabilityData 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 MasterServerAvailabilityData(
_configuration.MinimumAppVersion,
status,
_configuration.MaintenanceStartTime,
_configuration.MaintenanceEndTime,
new UserMessage(_configuration.LocalizedMessages),
_configuration.RequiredMods
);
}
}
}
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
@@ -0,0 +1,21 @@
using BeatTogether.Status.Api.Controllers.Enums;
using System.Collections.Generic;

namespace BeatTogether.Status.Api.Controllers.Models
{
public record MasterServerStatusData(
string minimumAppVersion,
AvailabilityStatus status,
long maintenanceStartTime,
long maintenanceEndTime,
UserMessage userMessage,
List<RequiredMod> requiredMods,
bool useSsl,
string name,
string description,
string imageUrl,
int maxPlayers,
bool supportsPpModifiers,
bool supportsPpDifficulties,
bool supportsPpMaps);
}
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
18 changes: 18 additions & 0 deletions BeatTogether.Status.Api.Controllers/Models/RequiredMod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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);
}
13 changes: 0 additions & 13 deletions BeatTogether.Status.Api.csproj

This file was deleted.

12 changes: 9 additions & 3 deletions BeatTogether.Status.Api.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30626.31
# Visual Studio Version 17
VisualStudioVersion = 17.8.34316.72
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeatTogether.Status.Api", "BeatTogether.Status.Api.csproj", "{EF1C2D6B-3B1A-48A6-BD7F-554910E7E957}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeatTogether.Status.Api", "BeatTogether.Status.Api\BeatTogether.Status.Api.csproj", "{EF1C2D6B-3B1A-48A6-BD7F-554910E7E957}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeatTogether.Status.Api.Controllers", "BeatTogether.Status.Api.Controllers\BeatTogether.Status.Api.Controllers.csproj", "{5E167F5A-625A-4F74-8424-FE6FD428D904}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{EF1C2D6B-3B1A-48A6-BD7F-554910E7E957}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF1C2D6B-3B1A-48A6-BD7F-554910E7E957}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF1C2D6B-3B1A-48A6-BD7F-554910E7E957}.Release|Any CPU.Build.0 = Release|Any CPU
{5E167F5A-625A-4F74-8424-FE6FD428D904}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E167F5A-625A-4F74-8424-FE6FD428D904}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E167F5A-625A-4F74-8424-FE6FD428D904}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E167F5A-625A-4F74-8424-FE6FD428D904}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions BeatTogether.Status.Api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.*
run
out
Dockerfile
Loading

0 comments on commit 353998f

Please sign in to comment.