Skip to content

Commit

Permalink
More DMAPI updates for OpenDream
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Oct 16, 2023
1 parent d76ed91 commit 04bf89f
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 43 deletions.
2 changes: 1 addition & 1 deletion build/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<TgsCommonLibraryVersion>6.0.1</TgsCommonLibraryVersion>
<TgsApiLibraryVersion>12.0.0</TgsApiLibraryVersion>
<TgsClientVersion>13.0.0</TgsClientVersion>
<TgsDmapiVersion>6.6.0</TgsDmapiVersion>
<TgsDmapiVersion>7.0.0</TgsDmapiVersion>
<TgsInteropVersion>5.7.0</TgsInteropVersion>
<TgsHostWatchdogVersion>1.4.0</TgsHostWatchdogVersion>
<TgsContainerScriptVersion>1.2.1</TgsContainerScriptVersion>
Expand Down
21 changes: 13 additions & 8 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.6.0"
#define TGS_DMAPI_VERSION "7.0.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,12 +73,12 @@
#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, 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, engine type of the current BYOND, engine type of the new BYOND.
#define TGS_EVENT_BYOND_ACTIVE_VERSION_CHANGE 7
/// Before a engine install operation begins. Parameters: Version string of the installing engine.
#define TGS_EVENT_ENGINE_INSTALL_START 5
/// When a engine install operation fails. Parameters: Error message
#define TGS_EVENT_ENGINE_INSTALL_FAIL 6
/// When the active engine version changes. Parameters: (Nullable) Version string of the current engine, version string of the new engine.
#define TGS_EVENT_ENGINE_ACTIVE_VERSION_CHANGE 7
/// When the compiler starts running. Parameters: Game directory path, origin commit SHA.
#define TGS_EVENT_COMPILE_START 8
/// When a compile is cancelled. No parameters.
Expand Down Expand Up @@ -108,7 +108,7 @@
// #define TGS_EVENT_DREAM_DAEMON_LAUNCH 22
/// After a single submodule update is performed. Parameters: Updated submodule name.
#define TGS_EVENT_REPO_SUBMODULE_UPDATE 23
/// After CodeModifications are applied, before DreamMaker is run. Parameters: Game directory path, origin commit sha, byond version.
/// After CodeModifications are applied, before DreamMaker is run. Parameters: Game directory path, origin commit sha, version string of the used engine.
#define TGS_EVENT_PRE_DREAM_MAKER 24
/// Whenever a deployment folder is deleted from disk. Parameters: Game directory path.
#define TGS_EVENT_DEPLOYMENT_CLEANUP 25
Expand All @@ -122,6 +122,7 @@
/// The watchdog will restart on reboot.
#define TGS_REBOOT_MODE_RESTART 2

// Note that security levels are currently meaningless in OpenDream
/// DreamDaemon Trusted security level.
#define TGS_SECURITY_TRUSTED 0
/// DreamDaemon Safe security level.
Expand Down Expand Up @@ -447,6 +448,10 @@
/world/proc/TgsVersion()
return

/// Returns the running engine type
/world/proc/TgsEngine()
return

/// Returns the current [/datum/tgs_version] of the DMAPI being used if it was activated, null otherwise. This function may sleep if the call to [/world/proc/TgsNew] is sleeping!
/world/proc/TgsApiVersion()
return
Expand Down
7 changes: 7 additions & 0 deletions src/DMAPI/tgs/core/core.dm
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@
if(api)
return api.ApiVersion()

/world/TgsEngine()
#ifdef OPENDREAM
return TGS_ENGINE_TYPE_OPENDREAM
#else
return TGS_ENGINE_TYPE_BYOND
#endif

/world/TgsInstanceName()
var/datum/tgs_api/api = TGS_READ_GLOBAL(tgs)
if(api)
Expand Down
18 changes: 9 additions & 9 deletions src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ await RunCompileJob(
/// <param name="job">The <see cref="CompileJob"/> to run and populate.</param>
/// <param name="dreamMakerSettings">The <see cref="Api.Models.Internal.DreamMakerSettings"/> to use.</param>
/// <param name="launchParameters">The <see cref="DreamDaemonLaunchParameters"/> to use.</param>
/// <param name="byondLock">The <see cref="IEngineExecutableLock"/> to use.</param>
/// <param name="engineLock">The <see cref="IEngineExecutableLock"/> to use.</param>
/// <param name="repository">The <see cref="IRepository"/> to use.</param>
/// <param name="remoteDeploymentManager">The <see cref="IRemoteDeploymentManager"/> to use.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
Expand All @@ -558,7 +558,7 @@ async ValueTask RunCompileJob(
Models.CompileJob job,
Api.Models.Internal.DreamMakerSettings dreamMakerSettings,
DreamDaemonLaunchParameters launchParameters,
IEngineExecutableLock byondLock,
IEngineExecutableLock engineLock,
IRepository repository,
IRemoteDeploymentManager remoteDeploymentManager,
CancellationToken cancellationToken)
Expand Down Expand Up @@ -586,7 +586,7 @@ await eventConsumer.HandleEvent(
{
resolvedOutputDirectory,
repoOrigin.ToString(),
byondLock.Version.ToString(),
engineLock.Version.ToString(),
},
true,
cancellationToken);
Expand Down Expand Up @@ -625,17 +625,17 @@ await eventConsumer.HandleEvent(
{
resolvedOutputDirectory,
repoOrigin.ToString(),
byondLock.Version.ToString(),
engineLock.Version.ToString(),
},
true,
cancellationToken);

// run compiler
progressReporter.StageName = "Running DreamMaker";
var compileSuceeded = await RunDreamMaker(byondLock, job, cancellationToken);
var compileSuceeded = await RunDreamMaker(engineLock, job, cancellationToken);

// Session takes ownership of the lock and Disposes it so save this for later
var byondVersion = byondLock.Version;
var engineVersion = engineLock.Version;

// verify api
try
Expand All @@ -650,7 +650,7 @@ await VerifyApi(
launchParameters.StartupTimeout.Value,
dreamMakerSettings.ApiValidationSecurityLevel.Value,
job,
byondLock,
engineLock,
dreamMakerSettings.ApiValidationPort.Value,
dreamMakerSettings.RequireDMApiValidation.Value,
launchParameters.LogOutput.Value,
Expand All @@ -666,7 +666,7 @@ await eventConsumer.HandleEvent(
{
resolvedOutputDirectory,
compileSuceeded ? "1" : "0",
byondVersion.ToString(),
engineVersion.ToString(),
},
true,
cancellationToken);
Expand All @@ -679,7 +679,7 @@ await eventConsumer.HandleEvent(
new List<string>
{
resolvedOutputDirectory,
byondVersion.ToString(),
engineVersion.ToString(),
},
true,
cancellationToken);
Expand Down
6 changes: 3 additions & 3 deletions src/Tgstation.Server.Host/Components/Engine/EngineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public async ValueTask ChangeVersion(
var stringVersion = version.ToString();
await ioManager.WriteAllBytes(ActiveVersionFileName, Encoding.UTF8.GetBytes(stringVersion), cancellationToken);
await eventConsumer.HandleEvent(
EventType.ByondActiveVersionChange,
EventType.EngineActiveVersionChange,
new List<string>
{
ActiveVersion?.ToString(),
Expand Down Expand Up @@ -463,7 +463,7 @@ async ValueTask<EngineExecutableLock> AssertAndLockVersion(
progressReporter.StageName = "Running event";

var versionString = version.ToString();
await eventConsumer.HandleEvent(EventType.ByondInstallStart, new List<string> { versionString }, false, cancellationToken);
await eventConsumer.HandleEvent(EventType.EngineInstallStart, new List<string> { versionString }, false, cancellationToken);

await InstallVersionFiles(progressReporter, version, customVersionStream, cancellationToken);

Expand All @@ -472,7 +472,7 @@ async ValueTask<EngineExecutableLock> AssertAndLockVersion(
catch (Exception ex)
{
if (ex is not OperationCanceledException)
await eventConsumer.HandleEvent(EventType.ByondInstallFail, new List<string> { ex.Message }, false, cancellationToken);
await eventConsumer.HandleEvent(EventType.EngineInstallFail, new List<string> { ex.Message }, false, cancellationToken);

lock (installedVersions)
installedVersions.Remove(version);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;

namespace Tgstation.Server.Host.Components.Events
{
Expand All @@ -9,17 +10,17 @@ namespace Tgstation.Server.Host.Components.Events
sealed class EventScriptAttribute : Attribute
{
/// <summary>
/// The name of the script the event script the <see cref="EventType"/> runs.
/// The name and order of the scripts the event script the <see cref="EventType"/> runs.
/// </summary>
public string ScriptName { get; }
public IReadOnlyList<string> ScriptNames { get; }

/// <summary>
/// Initializes a new instance of the <see cref="EventScriptAttribute"/> class.
/// </summary>
/// <param name="scriptName">The value of <see cref="ScriptName"/>.</param>
public EventScriptAttribute(string scriptName)
/// <param name="scriptNames">The value of <see cref="ScriptNames"/>.</param>
public EventScriptAttribute(params string[] scriptNames)
{
ScriptName = scriptName ?? throw new ArgumentNullException(nameof(scriptName));
ScriptNames = ScriptNames ?? throw new ArgumentNullException(nameof(scriptNames));
}
}
}
22 changes: 11 additions & 11 deletions src/Tgstation.Server.Host/Components/Events/EventType.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Tgstation.Server.Host.Components.Events
{
/// <summary>
/// Types of events. Mirror in tgs.dm.
/// Types of events. Mirror in tgs.dm. Prefer last listed name for script.
/// </summary>
public enum EventType
{
Expand Down Expand Up @@ -39,23 +39,23 @@ public enum EventType
/// <summary>
/// Parameters: Version being installed
/// </summary>
[EventScript("ByondInstallStart")]
ByondInstallStart,
[EventScript("ByondInstallStart", "EngineInstallStart")]
EngineInstallStart,

/// <summary>
/// Parameters: Error string
/// </summary>
[EventScript("ByondInstallFail")]
ByondInstallFail,
[EventScript("ByondInstallFail", "EngineInstallFail")]
EngineInstallFail,

/// <summary>
/// Parameters: Old active version, new active version
/// </summary>
[EventScript("ByondActiveVersionChange")]
ByondActiveVersionChange,
[EventScript("ByondActiveVersionChange", "EngineActiveVersionChange")]
EngineActiveVersionChange,

/// <summary>
/// After the repo is copied, before CodeModifications are applied. Parameters: Game directory path, origin commit sha, byond version
/// After the repo is copied, before CodeModifications are applied. Parameters: Game directory path, origin commit sha, engine version string
/// </summary>
[EventScript("PreCompile")]
CompileStart,
Expand All @@ -67,13 +67,13 @@ public enum EventType
CompileCancelled,

/// <summary>
/// Parameters: Game directory path, "1" if compile succeeded and api validation failed, "0" otherwise, BYOND version used
/// Parameters: Game directory path, "1" if compile succeeded and api validation failed, "0" otherwise, engine version string
/// </summary>
[EventScript("CompileFailure")]
CompileFailure,

/// <summary>
/// Parameters: Game directory path, BYOND version used
/// Parameters: Game directory path, engine version string
/// </summary>
[EventScript("PostCompile")]
CompileComplete,
Expand Down Expand Up @@ -151,7 +151,7 @@ public enum EventType
RepoSubmoduleUpdate,

/// <summary>
/// After CodeModifications are applied, before DreamMaker is run. Parameters: Game directory path, origin commit sha, byond version
/// After CodeModifications are applied, before DreamMaker is run. Parameters: Game directory path, origin commit sha, engine version string
/// </summary>
[EventScript("PreDreamMaker")]
PreDreamMaker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ sealed class Configuration : IConfiguration
/// <summary>
/// Map of <see cref="EventType"/>s to the filename of the event scripts they trigger.
/// </summary>
static readonly IReadOnlyDictionary<EventType, string> EventTypeScriptFileNameMap = new Dictionary<EventType, string>(
static readonly IReadOnlyDictionary<EventType, IReadOnlyList<string>> EventTypeScriptFileNameMap = new Dictionary<EventType, IReadOnlyList<string>>(
Enum.GetValues(typeof(EventType))
.OfType<EventType>()
.Select(
eventType => new KeyValuePair<EventType, string>(
eventType => new KeyValuePair<EventType, IReadOnlyList<string>>(
eventType,
typeof(EventType)
.GetField(eventType.ToString())
.GetCustomAttributes(false)
.OfType<EventScriptAttribute>()
.First()
.ScriptName)));
.ScriptNames)));

/// <summary>
/// The <see cref="IIOManager"/> for <see cref="Configuration"/>.
Expand Down Expand Up @@ -606,7 +606,7 @@ public async ValueTask HandleEvent(EventType eventType, IEnumerable<string> para

await EnsureDirectories(cancellationToken);

if (!EventTypeScriptFileNameMap.TryGetValue(eventType, out var scriptName))
if (!EventTypeScriptFileNameMap.TryGetValue(eventType, out var scriptNames))
return;

// always execute in serial
Expand All @@ -617,12 +617,13 @@ public async ValueTask HandleEvent(EventType eventType, IEnumerable<string> para

var scriptFiles = files
.Select(x => ioManager.GetFileName(x))
.Where(x => x.StartsWith(scriptName, StringComparison.Ordinal))
.Where(x => scriptNames.Any(
scriptName => x.StartsWith(scriptName, StringComparison.Ordinal)))
.ToList();

if (!scriptFiles.Any())
{
logger.LogTrace("No event scripts starting with \"{scriptName}\" detected", scriptName);
logger.LogTrace("No event scripts starting with \"{scriptName}\" detected", String.Join("\" or \"", scriptNames));
return;
}

Expand Down

0 comments on commit 04bf89f

Please sign in to comment.