Skip to content

Commit

Permalink
WIP OpenDream Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Oct 9, 2023
1 parent 24527ef commit ca76ce7
Show file tree
Hide file tree
Showing 25 changed files with 627 additions and 295 deletions.
11 changes: 8 additions & 3 deletions src/DMAPI/tgs.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tgstation-server DMAPI

#define TGS_DMAPI_VERSION "6.5.3"
#define TGS_DMAPI_VERSION "6.6.0"

// All functions and datums outside this document are subject to change with any version and should not be relied on.

Expand Down Expand Up @@ -73,11 +73,11 @@
#define TGS_EVENT_REPO_MERGE_PULL_REQUEST 3
/// Before the repository makes a sychronize operation. Parameters: Absolute repostiory path.
#define TGS_EVENT_REPO_PRE_SYNCHRONIZE 4
/// Before a BYOND install operation begins. Parameters: [/datum/tgs_version] of the installing BYOND.
/// Before a BYOND install operation begins. Parameters: [/datum/tgs_version] of the installing BYOND, engine type of the installing BYOND.
#define TGS_EVENT_BYOND_INSTALL_START 5
/// When a BYOND install operation fails. Parameters: Error message
#define TGS_EVENT_BYOND_INSTALL_FAIL 6
/// When the active BYOND version changes. Parameters: (Nullable) [/datum/tgs_version] of the current BYOND, [/datum/tgs_version] of the new BYOND.
/// When the active BYOND version changes. Parameters: (Nullable) [/datum/tgs_version] of the current BYOND, [/datum/tgs_version] of the new BYOND, engine type of the current BYOND, engine type of the new BYOND.
#define TGS_EVENT_BYOND_ACTIVE_VERSION_CHANGE 7
/// When the compiler starts running. Parameters: Game directory path, origin commit SHA.
#define TGS_EVENT_COMPILE_START 8
Expand Down Expand Up @@ -129,6 +129,11 @@
/// DreamDaemon Ultrasafe security level.
#define TGS_SECURITY_ULTRASAFE 2

/// The Build Your Own Net Dream engine.
#define TGS_ENGINE_TYPE_BYOND 0
/// The OpenDream engine.
#define TGS_ENGINE_TYPE_OPENDREAM 1

//REQUIRED HOOKS

/**
Expand Down
18 changes: 18 additions & 0 deletions src/Tgstation.Server.Api/Models/EngineType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Tgstation.Server.Api.Models
{
/// <summary>
/// The type of engine the codebase is using.
/// </summary>
public enum EngineType
{
/// <summary>
/// Build your own net dream,
/// </summary>
Byond,

/// <summary>
/// The OpenDream BYOND reimplementation.
/// </summary>
OpenDream,
}
}
108 changes: 108 additions & 0 deletions src/Tgstation.Server.Api/Models/Internal/ByondVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace Tgstation.Server.Api.Models.Internal
{
/// <summary>
/// Information about a Byond installation.
/// </summary>
public class ByondVersion : IEquatable<ByondVersion>
{
/// <summary>
/// The <see cref="EngineType"/>.
/// </summary>
[RequestOptions(FieldPresence.Required)]
public EngineType? Engine { get; set; }

/// <summary>
/// The <see cref="System.Version"/> of the engine.
/// </summary>
[RequestOptions(FieldPresence.Required)]
public Version? Version { get; set; }

/// <summary>
/// The git committish of the <see cref="Version"/>. On response, this will always be a commit SHA.
/// </summary>
[ResponseOptions]
[StringLength(Limits.MaximumCommitShaLength)]
public string? SourceCommittish { get; set; }

/// <summary>
/// Parses a stringified <see cref="ByondVersion"/>.
/// </summary>
/// <param name="input">The input <see cref="string"/>.</param>
/// <param name="byondVersion">The output <see cref="ByondVersion"/>.</param>
/// <returns><see langword="true"/> if parsing was successful, <see langword="false"/> otherwise.</returns>
public static bool TryParse(string input, out ByondVersion byondVersion)
{
if (input == null)
throw new ArgumentNullException(nameof(input));

var splits = input.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
byondVersion = new ByondVersion();

if (splits.Length > 2)
return false;

EngineType engine;
if (splits.Length > 1)
{
if (!Enum.TryParse(splits[0], out engine))
return false;
}
else
engine = EngineType.Byond;

byondVersion.Engine = engine;

if (!Version.TryParse(splits.Last(), out var version))
return false;

byondVersion.Version = version;

return true;
}

/// <summary>
/// Initializes a new instance of the <see cref="ByondVersion"/> class.
/// </summary>
public ByondVersion()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ByondVersion"/> class.
/// </summary>
/// <param name="other">The <see cref="ByondVersion"/> to copy.</param>
public ByondVersion(ByondVersion other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

Version = other.Version;
Engine = other.Engine;
SourceCommittish = other.SourceCommittish;
}

/// <inheritdoc />
public bool Equals(ByondVersion other)
{
// https://github.com/dotnet/roslyn-analyzers/issues/2875
#pragma warning disable CA1062 // Validate arguments of public methods
return other!.Version == Version
&& other.Engine == Engine;
#pragma warning restore CA1062 // Validate arguments of public methods
}

/// <inheritdoc />
public override bool Equals(object obj)
=> obj is ByondVersion other && Equals(other);

/// <inheritdoc />
public override string ToString() => $"{(Engine != EngineType.Byond ? $"{Engine}-" : String.Empty)}{Version}"; // BYOND isn't display for backwards compatibility. SourceCommittish is not included

/// <inheritdoc />
public override int GetHashCode() => ToString().GetHashCode();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
using System;

using Tgstation.Server.Api.Models.Internal;

namespace Tgstation.Server.Api.Models.Request
{
/// <summary>
/// A request to delete a specific <see cref="Version"/>.
/// </summary>
public class ByondVersionDeleteRequest
public class ByondVersionDeleteRequest : ByondVersion
{
/// <summary>
/// The BYOND version to install.
/// </summary>
[RequestOptions(FieldPresence.Required)]
public Version? Version { get; set; }
}
}
15 changes: 12 additions & 3 deletions src/Tgstation.Server.Api/Models/Request/ByondVersionRequest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
namespace Tgstation.Server.Api.Models.Request
using System;

using Tgstation.Server.Api.Models.Internal;

namespace Tgstation.Server.Api.Models.Request
{
/// <summary>
/// A request to install a BYOND <see cref="ByondVersionDeleteRequest.Version"/>.
/// A request to install a <see cref="ByondVersion"/>.
/// </summary>
public sealed class ByondVersionRequest : ByondVersionDeleteRequest
public sealed class ByondVersionRequest : ByondVersion
{
/// <summary>
/// If a custom BYOND version is to be uploaded.
/// </summary>
public bool? UploadCustomZip { get; set; }

/// <summary>
/// The remote repository for non-<see cref="EngineType.Byond"/> <see cref="EngineType"/>s. By default, this is the original git repository of the target <see cref="EngineType"/>.
/// </summary>
public Uri? SourceRepository { get; set; }
}
}
15 changes: 9 additions & 6 deletions src/Tgstation.Server.Api/Models/Response/ByondResponse.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
using System;
using Tgstation.Server.Api.Models.Internal;

namespace Tgstation.Server.Api.Models.Response
{
/// <summary>
/// Represents an installed BYOND <see cref="Version"/>.
/// Represents an installed <see cref="ByondVersion"/>.
/// </summary>
public sealed class ByondResponse
public sealed class ByondResponse : ByondVersion
{
/// <summary>
/// The installed BYOND <see cref="System.Version"/>. BYOND itself only considers the <see cref="Version.Major"/> and <see cref="Version.Minor"/> numbers. TGS uses the <see cref="Version.Build"/> number to represent installed custom versions.
/// Initializes a new instance of the <see cref="ByondResponse"/> class.
/// </summary>
[ResponseOptions]
public Version? Version { get; set; }
/// <param name="byondVersion">The <see cref="ByondVersion"/> to copy.</param>
public ByondResponse(ByondVersion byondVersion)
: base(byondVersion)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ public sealed class CompileJobResponse : Internal.CompileJob
public RevisionInformation? RevisionInformation { get; set; }

/// <summary>
/// The <see cref="ByondResponse.Version"/> the <see cref="CompileJobResponse"/> was made with.
/// The <see cref="Internal.ByondVersion.Version"/> the <see cref="CompileJobResponse"/> was made with.
/// </summary>
public Version? ByondVersion { get; set; }

/// <summary>
/// The <see cref="Internal.ByondVersion.Engine"/> the <see cref="CompileJobResponse"/> was made with.
/// </summary>
public EngineType? Engine { get; set; }

/// <summary>
/// The origin <see cref="Uri"/> of the repository the compile job was built from.
/// </summary>
Expand Down
26 changes: 18 additions & 8 deletions src/Tgstation.Server.Api/Rights/ByondRights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,43 @@ public enum ByondRights : ulong
None = 0,

/// <summary>
/// User may view the active installed BYOND version.
/// User may view the active installed engine versions.
/// </summary>
ReadActive = 1 << 0,

/// <summary>
/// User may list all installed BYOND versions.
/// User may list all installed engine versions.
/// </summary>
ListInstalled = 1 << 1,

/// <summary>
/// User may install official BYOND versions or change the active BYOND version.
/// User may install official <see cref="Models.EngineType.Byond"/> versions or change the active <see cref="Models.EngineType.Byond"/> version.
/// </summary>
InstallOfficialOrChangeActiveVersion = 1 << 2,
InstallOfficialOrChangeActiveByondVersion = 1 << 2,

/// <summary>
/// User may cancel BYOND installation job.
/// User may cancel an engine installation job.
/// </summary>
CancelInstall = 1 << 3,

/// <summary>
/// User may upload and activate custom BYOND builds.
/// User may upload and activate custom <see cref="Models.EngineType.Byond"/> builds.
/// </summary>
InstallCustomVersion = 1 << 4,
InstallCustomByondVersion = 1 << 4,

/// <summary>
/// User may delete non-active BYOND builds.
/// User may delete non-active engine builds.
/// </summary>
DeleteInstall = 1 << 5,

/// <summary>
/// User may install official <see cref="Models.EngineType.OpenDream"/> versions or change the active <see cref="Models.EngineType.OpenDream"/> version.
/// </summary>
InstallOfficialOrChangeActiveOpenDreamVersion = 1 << 6,

/// <summary>
/// User may activate custom <see cref="Models.EngineType.OpenDream"/> builds via zip upload or custom git committish.
/// </summary>
InstallCustomOpenDreamVersion = 1 << 7,
}
}
29 changes: 24 additions & 5 deletions src/Tgstation.Server.Host/Components/Byond/ByondExecutableLock.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using Tgstation.Server.Api.Models.Internal;
using Tgstation.Server.Host.Components.Deployment;
using Tgstation.Server.Host.Utils;

namespace Tgstation.Server.Host.Components.Byond
Expand All @@ -8,21 +12,36 @@ namespace Tgstation.Server.Host.Components.Byond
sealed class ByondExecutableLock : ReferenceCounter<ByondInstallation>, IByondExecutableLock
{
/// <inheritdoc />
public Version Version => Instance.Version;
public ByondVersion Version => Instance.Version;

/// <inheritdoc />
public string DreamDaemonPath => Instance.DreamDaemonPath;
public string ServerExePath => Instance.ServerExePath;

/// <inheritdoc />
public string DreamMakerPath => Instance.DreamMakerPath;
public string CompilerExePath => Instance.CompilerExePath;

/// <inheritdoc />
public bool SupportsCli => Instance.SupportsCli;
public bool HasStandardOutput => Instance.HasStandardOutput;

/// <inheritdoc />
public bool SupportsMapThreads => Instance.SupportsMapThreads;
public bool PromptsForNetworkAccess => Instance.PromptsForNetworkAccess;

/// <inheritdoc />
public Task InstallationTask => Instance.InstallationTask;

/// <inheritdoc />
public void DoNotDeleteThisSession() => DangerousDropReference();

/// <inheritdoc />
public string FormatServerArguments(
IDmbProvider dmbProvider,
IReadOnlyDictionary<string, string> parameters,
DreamDaemonLaunchParameters launchParameters,
string logFilePath)
=> Instance.FormatServerArguments(
dmbProvider,
parameters,
launchParameters,
logFilePath);
}
}
Loading

0 comments on commit ca76ce7

Please sign in to comment.