tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
EngineInstallationBase.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading;
6using System.Threading.Tasks;
7using System.Web;
8
9using DotEnv.Core;
10
11using Microsoft.Extensions.Logging;
12
18
20{
23 {
25 public abstract EngineVersion Version { get; }
26
28 public abstract string ServerExePath { get; }
29
31 public abstract string CompilerExePath { get; }
32
34 public abstract bool HasStandardOutput { get; }
35
37 public abstract bool PreferFileLogging { get; }
38
40 public abstract bool PromptsForNetworkAccess { get; }
41
43 public abstract bool UseDotnetDump { get; }
44
46 public abstract Task InstallationTask { get; }
47
52
59 protected static string EncodeParameters(
60 IReadOnlyDictionary<string, string> parameters,
61 DreamDaemonLaunchParameters launchParameters)
62 {
63 var parametersString = String.Join('&', parameters.Select(kvp => $"{HttpUtility.UrlEncode(kvp.Key)}={HttpUtility.UrlEncode(kvp.Value)}"));
64
65 if (!String.IsNullOrEmpty(launchParameters.AdditionalParameters))
66 parametersString = $"{parametersString}&{launchParameters.AdditionalParameters}";
67
68 return parametersString;
69 }
70
75 public EngineInstallationBase(IIOManager installationIOManager)
76 {
77 InstallationIOManager = installationIOManager ?? throw new ArgumentNullException(nameof(installationIOManager));
78 }
79
81 public abstract string FormatCompilerArguments(string dmePath, string? additionalArguments);
82
84 public abstract string FormatServerArguments(
85 IDmbProvider dmbProvider,
86 IReadOnlyDictionary<string, string> parameters,
87 DreamDaemonLaunchParameters launchParameters,
88 string? logFilePath);
89
91 public virtual async ValueTask StopServerProcess(ILogger logger, IProcess process, string accessIdentifier, ushort port, CancellationToken cancellationToken)
92 {
93 ArgumentNullException.ThrowIfNull(logger);
94 cancellationToken.ThrowIfCancellationRequested();
95 logger.LogTrace("Terminating engine server process...");
96 process.Terminate();
97 await process.Lifetime;
98 }
99
101 public async ValueTask<Dictionary<string, string>?> LoadEnv(ILogger logger, bool forCompiler, CancellationToken cancellationToken)
102 {
103 ArgumentNullException.ThrowIfNull(logger);
104
105 var envFile = forCompiler
106 ? "compiler.env"
107 : "server.env";
108
109 if (!await InstallationIOManager.FileExists(envFile, cancellationToken))
110 {
111 logger.LogTrace("No {envFile} present in engine installation {version}", envFile, Version);
112 return null;
113 }
114
115 logger.LogDebug("Loading {envFile} for engine installation {version}...", envFile, Version);
116
117 var fileBytes = await InstallationIOManager.ReadAllBytes(envFile, cancellationToken);
118 var fileContents = Encoding.UTF8.GetString(fileBytes);
119 var parser = new EnvParser();
120
121 try
122 {
123 var variables = parser.Parse(fileContents);
124
125 return variables.ToDictionary();
126 }
127 catch (Exception ex)
128 {
129 logger.LogWarning(ex, "Unable to parse {envFile}!", envFile);
130 return null;
131 }
132 }
133 }
134}
Information about an engine installation.
static string EncodeParameters(IReadOnlyDictionary< string, string > parameters, DreamDaemonLaunchParameters launchParameters)
Encode given parameters for passing as world.params on the command line.
bool PromptsForNetworkAccess
If ServerExePath may create network prompts.
bool UseDotnetDump
If dotnet-dump should be used to create process dumps for this installation.
EngineVersion Version
The EngineVersion of the IEngineInstallation.
string FormatCompilerArguments(string dmePath, string? additionalArguments)
Return the command line arguments for compiling a given dmePath if compilation is necessary....
EngineInstallationBase(IIOManager installationIOManager)
Initializes a new instance of the EngineInstallationBase class.
bool PreferFileLogging
If HasStandardOutput is set, this indicates that the engine server has good file logging that should ...
virtual async ValueTask StopServerProcess(ILogger logger, IProcess process, string accessIdentifier, ushort port, CancellationToken cancellationToken)
Kills a given engine server process .A ValueTask representing the running operation.
async ValueTask< Dictionary< string, string >?> LoadEnv(ILogger logger, bool forCompiler, CancellationToken cancellationToken)
Loads the environment settings for either the server or compiler.A ValueTask<TResult> resulting in th...
Task InstallationTask
The Task that completes when the BYOND version finished installing.
string ServerExePath
The full path to the game server executable.
string CompilerExePath
The full path to the dm/DreamMaker executable.
bool HasStandardOutput
If ServerExePath supports being run as a command-line application and outputs log information to be c...
IIOManager InstallationIOManager
The IIOManager pointing to the installation directory.
string FormatServerArguments(IDmbProvider dmbProvider, IReadOnlyDictionary< string, string > parameters, DreamDaemonLaunchParameters launchParameters, string? logFilePath)
Return the command line arguments for launching with given launchParameters .The formatted arguments ...
Provides absolute paths to the latest compiled .dmbs.
Interface for using filesystems.
Definition IIOManager.cs:13
ValueTask< byte[]> ReadAllBytes(string path, CancellationToken cancellationToken)
Returns all the contents of a file at path as a byte array.
Task< bool > FileExists(string path, CancellationToken cancellationToken)
Check that the file at path exists.
Task< int?> Lifetime
The Task<TResult> resulting in the exit code of the process or null if the process was detached.
Abstraction over a global::System.Diagnostics.Process.
Definition IProcess.cs:11
void Terminate()
Asycnhronously terminates the process.