Skip to content

Commit

Permalink
state
Browse files Browse the repository at this point in the history
  • Loading branch information
X39 committed Nov 1, 2023
1 parent 481e7ba commit 5784e3c
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 19 deletions.
10 changes: 7 additions & 3 deletions source/X39.UnitedTacticalForces.Api/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ namespace X39.UnitedTacticalForces.Api;
internal static class Constants
{
public const string PasswordReplacement = "****************";

public static class Steam
{
public static class AppId
{
public const long Arma3Server = 233780;
public const long Arma3 = 107410;
public const long Arma3Server = 233780;
public const long Arma3 = 107410;
public const long DayZStandalone = 221100;
public const long DayZStandaloneServer = 223350;
}
}

Expand Down Expand Up @@ -42,6 +45,7 @@ public static class AuthorizationSchemas
public const string Api = "api";
public const string Banned = "banned";
}

public static class Discord
{
public static class Commands
Expand Down Expand Up @@ -80,7 +84,7 @@ public static class Bot
public const string ApplicationId = nameof(Discord) + ":" + nameof(Bot) + ":" + nameof(ApplicationId);
public const string PublicKey = nameof(Discord) + ":" + nameof(Bot) + ":" + nameof(PublicKey);
public const string BotToken = nameof(Discord) + ":" + nameof(Bot) + ":" + nameof(BotToken);
public const string EmbedColor = nameof(Discord) + ":" + nameof(Bot) + ":" + nameof(EmbedColor);
public const string EmbedColor = nameof(Discord) + ":" + nameof(Bot) + ":" + nameof(EmbedColor);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using X39.UnitedTacticalForces.Api.Data;
using X39.UnitedTacticalForces.Api.Data.Authority;
using X39.UnitedTacticalForces.Api.Data.Hosting;
using X39.UnitedTacticalForces.Api.Services.UpdateStreamService;

namespace X39.UnitedTacticalForces.Api.Services.GameServerController.Controllers;

/// <summary>
/// Implementation of <see cref="IGameServerController"/> for DayZ Standalone game servers.
/// </summary>
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
public class DayZStandaloneGameServerController : SteamGameServerControllerBase, IGameServerControllerCreatable
{
/// <inheritdoc />
public DayZStandaloneGameServerController(
GameServer gameServer,
IDbContextFactory<ApiDbContext> dbContextFactory,
ILogger<DayZStandaloneGameServerController> logger,
IConfiguration configuration,
IUpdateStreamService updateStreamService)
: base(configuration, gameServer, dbContextFactory, updateStreamService, logger)
{
}

/// <inheritdoc />
public override bool AllowAnyConfigurationEntry => false;

/// <inheritdoc />
public override bool CanModifyGameFiles => false;

/// <inheritdoc />
protected override long ServerAppId => Constants.Steam.AppId.DayZStandaloneServer;

/// <inheritdoc />
protected override long GameAppId => Constants.Steam.AppId.DayZStandalone;

/// <inheritdoc />
protected override bool RequireLogin => true;

/// <inheritdoc />
protected override bool RequirePurchaseForWorkshop => true;

/// <inheritdoc />
public static string Identifier => $"dayz-{Constants.Steam.AppId.DayZStandaloneServer}";

/// <inheritdoc />
public override IEnumerable<ConfigurationEntryDefinition> GetConfigurationEntryDefinitions(CultureInfo cultureInfo)
{
return Enumerable.Empty<ConfigurationEntryDefinition>();
}

/// <inheritdoc />
public override Task<IEnumerable<GameFolder>> GetGameFoldersAsync(
CultureInfo cultureInfo,
CancellationToken cancellationToken = default)
{
return Task.FromResult<IEnumerable<GameFolder>>(Array.Empty<GameFolder>());
}

/// <inheritdoc />
public override Task<IEnumerable<GameFileInfo>> GetGameFolderFilesAsync(
GameFolder folder,
CultureInfo cultureInfo,
CancellationToken cancellationToken = default)
{
return Task.FromResult<IEnumerable<GameFileInfo>>(Array.Empty<GameFileInfo>());
}

/// <inheritdoc />
public override Task<Stream> GetGameFolderFileAsync(
GameFolder folder,
GameFileInfo file,
CancellationToken cancellationToken = default)
{
return Task.FromResult<Stream>(new MemoryStream());
}

/// <inheritdoc />
public override Task UploadFileAsync(GameFolder folder, GameFileInfo file, Stream stream)
{
throw new NotSupportedException();
}

/// <inheritdoc />
public override Task DeleteFileAsync(GameFolder folder, GameFileInfo file)
{
throw new NotSupportedException();
}

/// <inheritdoc />
public override Task<string?> GetCommonConfigurationAsync(
ECommonConfiguration commonConfig,
CultureInfo cultureInfo,
CancellationToken cancellationToken = default)
{
return commonConfig switch
{
ECommonConfiguration.Title => Task.FromResult<string?>("DayZ Standalone"),
ECommonConfiguration.Port => Task.FromResult<string?>("2302"),
ECommonConfiguration.Password => Task.FromResult<string?>(""),
_ => throw new ArgumentOutOfRangeException(nameof(commonConfig), commonConfig, null)
};
}

/// <inheritdoc />
protected override Task DoUpdateConfigurationAsync()
{
return Task.CompletedTask;
}

/// <inheritdoc />
protected override ValueTask<ProcessStartInfo> GetProcessStartInfoAsync(ApiDbContext dbContext, User? executingUser)
{
var fileName = Path.Combine(
GameInstallPath,
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? "DayZServer_x64.exe"
: "dayzserver_x64");
var psi = new ProcessStartInfo
{
FileName = fileName,
RedirectStandardError = true,
RedirectStandardInput = false,
RedirectStandardOutput = true,
StandardErrorEncoding = Encoding.UTF8,
// StandardInputEncoding = Encoding.UTF8,
StandardOutputEncoding = Encoding.UTF8,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false,
WorkingDirectory = GameInstallPath,
};
return ValueTask.FromResult(psi);
}

/// <inheritdoc />
public static Task<IGameServerController> CreateAsync(
IServiceProvider serviceProvider,
IConfiguration configuration,
GameServer gameServer,
IUpdateStreamService updateStreamService)
{
var controller = new DayZStandaloneGameServerController(
gameServer,
serviceProvider.GetRequiredService<IDbContextFactory<ApiDbContext>>(),
serviceProvider.GetRequiredService<ILoggerFactory>().CreateLogger<DayZStandaloneGameServerController>(),
configuration,
updateStreamService);
return Task.FromResult<IGameServerController>(controller);
}
}
40 changes: 24 additions & 16 deletions source/X39.UnitedTacticalForces.WebApp/Api.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ public string BaseUrl

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Changes the calling users acceptance status for the given event to X39.UnitedTacticalForces.Api.Data.Authority.EEventAcceptance.Accepted.
/// Changes the calling users acceptance status for the given event to X39.UnitedTacticalForces.Contract.Event.EEventAcceptance.Accepted.
/// </summary>
/// <param name="eventId">The id for the X39.UnitedTacticalForces.Api.Data.Eventing.Event to change the acceptance of.</param>
/// <returns>No Content</returns>
Expand Down Expand Up @@ -737,7 +737,7 @@ public string BaseUrl

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Changes the calling users acceptance status for the given event to X39.UnitedTacticalForces.Api.Data.Authority.EEventAcceptance.Maybe.
/// Changes the calling users acceptance status for the given event to X39.UnitedTacticalForces.Contract.Event.EEventAcceptance.Maybe.
/// </summary>
/// <remarks>
/// Any slot selection for the X39.UnitedTacticalForces.Api.Data.Eventing.Event will be removed in this process.
Expand Down Expand Up @@ -816,7 +816,7 @@ public string BaseUrl

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Changes the calling users acceptance status for the given event to X39.UnitedTacticalForces.Api.Data.Authority.EEventAcceptance.Rejected.
/// Changes the calling users acceptance status for the given event to X39.UnitedTacticalForces.Contract.Event.EEventAcceptance.Rejected.
/// </summary>
/// <remarks>
/// Any slot selection for the X39.UnitedTacticalForces.Api.Data.Eventing.Event will be removed in this process.
Expand Down Expand Up @@ -1168,7 +1168,7 @@ public string BaseUrl
/// <param name="slotNumber">The id of the X39.UnitedTacticalForces.Api.Data.Eventing.EventSlot.</param>
/// <returns>No Content</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task EventsSlottingAssignPostAsync(System.Guid eventId, long slotNumber, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
public virtual async System.Threading.Tasks.Task EventsSlottingAssignPostAsync(System.Guid eventId, int slotNumber, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
if (eventId == null)
throw new System.ArgumentNullException("eventId");
Expand Down Expand Up @@ -7585,13 +7585,15 @@ public enum EEventAcceptance
/// <summary>
///
/// <br/>
/// <br/>0 = Stopped (Status indicating that something is currently not running in any way.)
/// <br/>0 = Stopped
/// <br/>
/// <br/>1 = Starting (Status indicating a transition from X39.UnitedTacticalForces.Api.Data.Hosting.ELifetimeStatus.Stopped to X39.UnitedTacticalForces.Api.Data.Hosting.ELifetimeStatus.Running. (Implies that a lifetime change was requested.))
/// <br/>1 = Starting
/// <br/>
/// <br/>2 = Stopping (Status indicating a transition from X39.UnitedTacticalForces.Api.Data.Hosting.ELifetimeStatus.Running to X39.UnitedTacticalForces.Api.Data.Hosting.ELifetimeStatus.Stopped. (Implies that a lifetime change was requested.))
/// <br/>2 = Stopping
/// <br/>
/// <br/>3 = Running (Status indicating that something is currently running.)
/// <br/>3 = Running
/// <br/>
/// <br/>4 = Updating
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
public enum ELifetimeStatus
Expand All @@ -7605,6 +7607,8 @@ public enum ELifetimeStatus

Running = 3,

Updating = 4,

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
Expand Down Expand Up @@ -7978,13 +7982,15 @@ public partial class GameServer
/// <summary>
/// The lifetime state of this entity.
/// <br/>
/// <br/>0 = Stopped (Status indicating that something is currently not running in any way.)
/// <br/>0 = Stopped
/// <br/>
/// <br/>1 = Starting (Status indicating a transition from X39.UnitedTacticalForces.Api.Data.Hosting.ELifetimeStatus.Stopped to X39.UnitedTacticalForces.Api.Data.Hosting.ELifetimeStatus.Running. (Implies that a lifetime change was requested.))
/// <br/>1 = Starting
/// <br/>
/// <br/>2 = Stopping (Status indicating a transition from X39.UnitedTacticalForces.Api.Data.Hosting.ELifetimeStatus.Running to X39.UnitedTacticalForces.Api.Data.Hosting.ELifetimeStatus.Stopped. (Implies that a lifetime change was requested.))
/// <br/>2 = Stopping
/// <br/>
/// <br/>3 = Running (Status indicating that something is currently running.)
/// <br/>3 = Running
/// <br/>
/// <br/>4 = Updating
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("status")]
Expand Down Expand Up @@ -8256,13 +8262,15 @@ public partial class LifetimeEvent
/// <summary>
/// The status changed into.
/// <br/>
/// <br/>0 = Stopped (Status indicating that something is currently not running in any way.)
/// <br/>0 = Stopped
/// <br/>
/// <br/>1 = Starting
/// <br/>
/// <br/>1 = Starting (Status indicating a transition from X39.UnitedTacticalForces.Api.Data.Hosting.ELifetimeStatus.Stopped to X39.UnitedTacticalForces.Api.Data.Hosting.ELifetimeStatus.Running. (Implies that a lifetime change was requested.))
/// <br/>2 = Stopping
/// <br/>
/// <br/>2 = Stopping (Status indicating a transition from X39.UnitedTacticalForces.Api.Data.Hosting.ELifetimeStatus.Running to X39.UnitedTacticalForces.Api.Data.Hosting.ELifetimeStatus.Stopped. (Implies that a lifetime change was requested.))
/// <br/>3 = Running
/// <br/>
/// <br/>3 = Running (Status indicating that something is currently running.)
/// <br/>4 = Updating
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("status")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class LifetimeStatusExtensions
ELifetimeStatus.Starting => Icons.Material.Filled.ChangeCircle,
ELifetimeStatus.Stopping => Icons.Material.Filled.ChangeCircle,
ELifetimeStatus.Running => Icons.Material.Filled.PlayCircle,
ELifetimeStatus.Updating => Icons.Material.Filled.ChangeCircle,
null => Icons.Material.Filled.Circle,
_ => throw new ArgumentOutOfRangeException(nameof(self), self, null),
};
Expand Down

0 comments on commit 5784e3c

Please sign in to comment.