Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ther.Status.Api into dev-1.35.0
  • Loading branch information
cubicgraphics committed May 11, 2024
2 parents cb25368 + 3b8978c commit 619b3ee
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 75 deletions.
1 change: 1 addition & 0 deletions BeatTogether.Status.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

</Project>
13 changes: 0 additions & 13 deletions Configuration/InfoConfiguration.cs

This file was deleted.

7 changes: 7 additions & 0 deletions Configuration/StatusConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@ public class StatusConfiguration
/// 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;
}
}
32 changes: 0 additions & 32 deletions Controllers/InfoController.cs

This file was deleted.

13 changes: 10 additions & 3 deletions Controllers/StatusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,29 @@ public StatusController(IOptionsSnapshot<StatusConfiguration> configuration)
}

[HttpGet]
public MasterServerAvailabilityData Get()
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 MasterServerAvailabilityData(
return new MasterServerStatusData(
_configuration.MinimumAppVersion,
status,
_configuration.MaintenanceStartTime,
_configuration.MaintenanceEndTime,
new UserMessage(_configuration.LocalizedMessages),
_configuration.RequiredMods,
_configuration.UseSsl
_configuration.UseSsl,
_configuration.ServerDisplayName,
_configuration.ServerDescription,
_configuration.ServerImageUrl,
_configuration.MaxPlayers,
_configuration.ServerSupportsPpModifiers,
_configuration.ServerSupportsPpDifficulties,
_configuration.ServerSupportsPpMaps
);
}
}
Expand Down
11 changes: 0 additions & 11 deletions Models/MasterServerInfoData.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
using BeatTogether.Status.Api.Enums;
using System.Collections.Generic;

namespace BeatTogether.Status.Api.Models
{
public record MasterServerAvailabilityData(
string minimumAppVersion,
AvailabilityStatus status,
long maintenanceStartTime,
long maintenanceEndTime,
UserMessage userMessage,
List<RequiredMod> requiredMods,
bool useSsl);
}
using BeatTogether.Status.Api.Enums;
using System.Collections.Generic;

namespace BeatTogether.Status.Api.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);
}
15 changes: 13 additions & 2 deletions Models/RequiredMod.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
namespace BeatTogether.Status.Api.Models
{
public record RequiredMod {
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;
}
}
}
8 changes: 8 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Serialization;

namespace BeatTogether.Status.Api
{
Expand All @@ -25,6 +26,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
.Configure<QuickplayConfiguration>(hostBuilderContext.Configuration.GetSection("Quickplay"))
.Configure<InfoConfiguration>(hostBuilderContext.Configuration.GetSection("Info"))
.AddControllers()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
};
})
)
.Configure(applicationBuilder =>
applicationBuilder
Expand Down

0 comments on commit 619b3ee

Please sign in to comment.