tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
InstanceFactory.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
5using Microsoft.Extensions.Logging;
6using Microsoft.Extensions.Options;
7
27
29{
32 {
37
42
47
51 readonly ILoggerFactory loggerFactory;
52
57
62
67
72
77
82
87
92
97
102
107
112
117
122
127
132
137
142
147
152
158 static ResolvingIOManager CreateGameIOManager(IIOManager instanceIOManager) => new(instanceIOManager, "Game");
159
160#pragma warning disable CA1502 // TODO: Decomplexify
188 public InstanceFactory(
192 ILoggerFactory loggerFactory,
211 IOptions<GeneralConfiguration> generalConfigurationOptions,
212 IOptions<SessionConfiguration> sessionConfigurationOptions)
213 {
214 this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
215 this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
216 this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
217 this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
218 this.topicClientFactory = topicClientFactory ?? throw new ArgumentNullException(nameof(topicClientFactory));
219 this.cryptographySuite = cryptographySuite ?? throw new ArgumentNullException(nameof(cryptographySuite));
220 this.synchronousIOManager = synchronousIOManager ?? throw new ArgumentNullException(nameof(synchronousIOManager));
221 this.linkFactory = linkFactory ?? throw new ArgumentNullException(nameof(linkFactory));
222 this.engineInstaller = engineInstaller ?? throw new ArgumentNullException(nameof(engineInstaller));
223 this.chatFactory = chatFactory ?? throw new ArgumentNullException(nameof(chatFactory));
224 this.processExecutor = processExecutor ?? throw new ArgumentNullException(nameof(processExecutor));
225 this.postWriteHandler = postWriteHandler ?? throw new ArgumentNullException(nameof(postWriteHandler));
226 this.watchdogFactory = watchdogFactory ?? throw new ArgumentNullException(nameof(watchdogFactory));
227 this.jobManager = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
228 this.networkPromptReaper = networkPromptReaper ?? throw new ArgumentNullException(nameof(networkPromptReaper));
229 this.platformIdentifier = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier));
230 this.repositoryManagerFactory = repositoryManagerFactory ?? throw new ArgumentNullException(nameof(repositoryManagerFactory));
231 this.serverPortProvider = serverPortProvider ?? throw new ArgumentNullException(nameof(serverPortProvider));
232 this.fileTransferService = fileTransferService ?? throw new ArgumentNullException(nameof(fileTransferService));
233 this.remoteDeploymentManagerFactory = remoteDeploymentManagerFactory ?? throw new ArgumentNullException(nameof(remoteDeploymentManagerFactory));
234 this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
235 this.dotnetDumpService = dotnetDumpService ?? throw new ArgumentNullException(nameof(dotnetDumpService));
236 generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
237 sessionConfiguration = sessionConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(sessionConfigurationOptions));
238 }
239#pragma warning restore CA1502
240
242 public IIOManager CreateGameIOManager(Models.Instance metadata)
243 {
244 ArgumentNullException.ThrowIfNull(metadata);
245
246 var instanceIoManager = CreateInstanceIOManager(metadata);
247 return CreateGameIOManager(instanceIoManager);
248 }
249
251#pragma warning disable CA1506 // TODO: Decomplexify
252 public async ValueTask<IInstance> CreateInstance(IBridgeRegistrar bridgeRegistrar, Models.Instance metadata)
253 {
254 ArgumentNullException.ThrowIfNull(bridgeRegistrar);
255 ArgumentNullException.ThrowIfNull(metadata);
256
257 // Create the ioManager for the instance
258 var instanceIoManager = CreateInstanceIOManager(metadata);
259
260 // various other ioManagers
261 var repoIoManager = new ResolvingIOManager(instanceIoManager, "Repository");
262 var byondIOManager = new ResolvingIOManager(instanceIoManager, "Byond");
263 var gameIoManager = CreateGameIOManager(instanceIoManager);
264 var diagnosticsIOManager = new ResolvingIOManager(instanceIoManager, "Diagnostics");
265 var configurationIoManager = new ResolvingIOManager(instanceIoManager, "Configuration");
266
267 var configuration = new StaticFiles.Configuration(
268 configurationIoManager,
275 loggerFactory.CreateLogger<StaticFiles.Configuration>(),
278 var eventConsumer = new EventConsumer(configuration);
279 var repoManager = repositoryManagerFactory.CreateRepositoryManager(repoIoManager, eventConsumer);
280 try
281 {
282 var engineManager = new EngineManager(
283 byondIOManager,
285 eventConsumer,
286 loggerFactory.CreateLogger<EngineManager>());
287
288 var dmbFactory = new DmbFactory(
290 gameIoManager,
292 eventConsumer,
294 loggerFactory.CreateLogger<DmbFactory>(),
295 metadata);
296 try
297 {
298 var commandFactory = new CommandFactory(assemblyInformationProvider, engineManager, repoManager, databaseContextFactory, dmbFactory, metadata);
299
300 var chatManager = chatFactory.CreateChatManager(commandFactory, metadata.ChatSettings);
301 try
302 {
303 var reattachInfoHandler = new SessionPersistor(
305 dmbFactory,
307 loggerFactory.CreateLogger<SessionPersistor>(),
308 metadata);
309
310 var sessionControllerFactory = new SessionControllerFactory(
312 engineManager,
316 gameIoManager,
317 diagnosticsIOManager,
318 chatManager,
321 bridgeRegistrar,
323 eventConsumer,
329 metadata);
330
331 var watchdog = watchdogFactory.CreateWatchdog(
332 chatManager,
333 dmbFactory,
334 reattachInfoHandler,
335 sessionControllerFactory,
336 gameIoManager,
337 diagnosticsIOManager,
338 configuration, // watchdog doesn't need itself as an event consumer
340 metadata,
341 metadata.DreamDaemonSettings!);
342 try
343 {
344 eventConsumer.SetWatchdog(watchdog);
345 commandFactory.SetWatchdog(watchdog);
346
347 Instance? instance = null;
348 var dreamMaker = new DreamMaker(
349 engineManager,
350 gameIoManager,
351 configuration,
352 sessionControllerFactory,
353 eventConsumer,
354 chatManager,
356 dmbFactory,
357 repoManager,
360 loggerFactory.CreateLogger<DreamMaker>(),
362 metadata);
363
364 instance = new Instance(
365 metadata,
366 repoManager,
367 engineManager,
368 dreamMaker,
369 watchdog,
370 chatManager,
371 configuration,
372 dmbFactory,
374 eventConsumer,
377 loggerFactory.CreateLogger<Instance>());
378
379 return instance;
380 }
381 catch
382 {
383 await watchdog.DisposeAsync();
384 throw;
385 }
386 }
387 catch
388 {
389 await chatManager.DisposeAsync();
390 throw;
391 }
392 }
393 catch
394 {
395 dmbFactory.Dispose();
396 throw;
397 }
398 }
399 catch
400 {
401 repoManager.Dispose();
402 throw;
403 }
404 }
405#pragma warning restore CA1506
406
408 public Task StartAsync(CancellationToken cancellationToken)
409 => Task.WhenAll(
410 repositoryManagerFactory.StartAsync(cancellationToken),
411 engineInstaller.CleanCache(cancellationToken));
412
414 public Task StopAsync(CancellationToken cancellationToken) => repositoryManagerFactory.StopAsync(cancellationToken);
415
421 ResolvingIOManager CreateInstanceIOManager(Models.Instance metadata) => new(ioManager, metadata.Path!);
422 }
423}
readonly IDatabaseContextFactory databaseContextFactory
The IDatabaseContextFactory for the InstanceFactory.
readonly ITopicClientFactory topicClientFactory
The ITopicClientFactory for the InstanceFactory.
readonly ISynchronousIOManager synchronousIOManager
The ISynchronousIOManager for the InstanceFactory.
readonly IPlatformIdentifier platformIdentifier
The IPlatformIdentifier for the InstanceFactory.
readonly SessionConfiguration sessionConfiguration
The SessionConfiguration for the InstanceFactory.
readonly IEngineInstaller engineInstaller
The IEngineInstaller for the InstanceFactory.
readonly IIOManager ioManager
The IIOManager for the InstanceFactory.
readonly IAsyncDelayer asyncDelayer
The IAsyncDelayer for the InstanceFactory.
readonly IProcessExecutor processExecutor
The IProcessExecutor for the InstanceFactory.
readonly IJobManager jobManager
The IJobManager for the InstanceFactory.
readonly IChatManagerFactory chatFactory
The IChatManagerFactory for the InstanceFactory.
readonly IRepositoryManagerFactory repositoryManagerFactory
The IRepositoryManagerFactory for the InstanceFactory.
readonly IServerPortProvider serverPortProvider
The IServerPortProvider for the InstanceFactory.
readonly GeneralConfiguration generalConfiguration
The GeneralConfiguration for the InstanceFactory.
Task StartAsync(CancellationToken cancellationToken)
Task StopAsync(CancellationToken cancellationToken)
readonly IWatchdogFactory watchdogFactory
The IWatchdogFactory for the InstanceFactory.
static ResolvingIOManager CreateGameIOManager(IIOManager instanceIOManager)
Create the IIOManager pointing to the "Game" directory of a given instanceIOManager .
readonly IAssemblyInformationProvider assemblyInformationProvider
The IAssemblyInformationProvider for the InstanceFactory.
ResolvingIOManager CreateInstanceIOManager(Models.Instance metadata)
Create the IIOManager for a given set of instance metadata .
readonly IPostWriteHandler postWriteHandler
The IPostWriteHandler for the InstanceFactory.
IIOManager CreateGameIOManager(Models.Instance metadata)
Create an IIOManager that resolves to the "Game" directory of the Models.Instance defined by metadata...
readonly IDotnetDumpService dotnetDumpService
The IDotnetDumpService for the InstanceFactory.
readonly ICryptographySuite cryptographySuite
The ICryptographySuite for the InstanceFactory.
async ValueTask< IInstance > CreateInstance(IBridgeRegistrar bridgeRegistrar, Models.Instance metadata)
Create an IInstance.A ValueTask<TResult> resulting in a new IInstance.
readonly IFileTransferTicketProvider fileTransferService
The IFileTransferTicketProvider for the InstanceFactory.
readonly INetworkPromptReaper networkPromptReaper
The INetworkPromptReaper for the InstanceFactory.
readonly IFilesystemLinkFactory linkFactory
The IFilesystemLinkFactory for the InstanceFactory.
readonly IRemoteDeploymentManagerFactory remoteDeploymentManagerFactory
The IRemoteDeploymentManagerFactory for the InstanceFactory.
readonly ILoggerFactory loggerFactory
The ILoggerFactory for the InstanceFactory.
Configuration options for the game sessions.
An IIOManager that resolve relative paths from another IIOManager to a subdirectory of that.
IChatManager CreateChatManager(ICommandFactory commandFactory, IEnumerable< Models.ChatBot > initialChatBots)
Create a IChatManager.
For downloading and installing game engines for a given system.
Task CleanCache(CancellationToken cancellationToken)
Attempts to cleans the engine's cache folder for the system.
IRepositoryManager CreateRepositoryManager(IIOManager ioManager, IEventConsumer eventConsumer)
Create a IRepositoryManager.
IWatchdog CreateWatchdog(IChatManager chat, IDmbFactory dmbFactory, ISessionPersistor sessionPersistor, ISessionControllerFactory sessionControllerFactory, IIOManager gameIOManager, IIOManager diagnosticsIOManager, IEventConsumer eventConsumer, IRemoteDeploymentManagerFactory remoteDeploymentManagerFactory, Api.Models.Instance instance, DreamDaemonSettings settings)
Creates a IWatchdog.
Provides access to the server's HttpApiPort.
Factory for scoping usage of IDatabaseContexts. Meant for use by Components.
Interface for using filesystems.
Definition IIOManager.cs:13
Handles changing file modes/permissions after writing.
For accessing the disk in a synchronous manner.
Manages the runtime of Jobs.
Contains various cryptographic functions.
Service for managing the dotnet-dump installation.
On Windows, DreamDaemon will show an unskippable prompt when using /world/proc/OpenPort()....
For identifying the current platform.
Service for temporarily storing files to be downloaded or uploaded.